killbill-aplcache

invoice: remove unused code in InvoiceDateUtils Signed-off-by:

4/14/2016 8:02:20 AM

Details

diff --git a/invoice/src/main/java/org/killbill/billing/invoice/generator/InvoiceDateUtils.java b/invoice/src/main/java/org/killbill/billing/invoice/generator/InvoiceDateUtils.java
index 879ef43..11c8d5d 100644
--- a/invoice/src/main/java/org/killbill/billing/invoice/generator/InvoiceDateUtils.java
+++ b/invoice/src/main/java/org/killbill/billing/invoice/generator/InvoiceDateUtils.java
@@ -1,7 +1,9 @@
 /*
- * Copyright 2010-2013 Ning, Inc.
+ * Copyright 2010-2014 Ning, Inc.
+ * Copyright 2014-2016 Groupon, Inc
+ * Copyright 2014-2016 The Billing Project, LLC
  *
- * Ning licenses this file to you under the Apache License, version 2.0
+ * The Billing Project licenses this file to you under the Apache License, version 2.0
  * (the "License"); you may not use this file except in compliance with the
  * License.  You may obtain a copy of the License at:
  *
@@ -25,6 +27,8 @@ import org.joda.time.Months;
 import org.killbill.billing.catalog.api.BillingPeriod;
 import org.killbill.billing.util.currency.KillBillMoney;
 
+import com.google.common.annotations.VisibleForTesting;
+
 public class InvoiceDateUtils {
 
     /**
@@ -65,35 +69,6 @@ public class InvoiceDateUtils {
         return numberOfMonths / numberOfMonthsInPeriod;
     }
 
-    public static LocalDate calculateLastBillingCycleDateBefore(final LocalDate date, final LocalDate previousBillCycleDate,
-                                                                final int billingCycleDay, final BillingPeriod billingPeriod) {
-        LocalDate proposedDate = previousBillCycleDate;
-
-        int numberOfPeriods = 0;
-        while (!proposedDate.isAfter(date)) {
-            proposedDate = previousBillCycleDate.plusMonths(numberOfPeriods * billingPeriod.getNumberOfMonths());
-            numberOfPeriods += 1;
-        }
-
-        proposedDate = proposedDate.plusMonths(-billingPeriod.getNumberOfMonths());
-
-        if (proposedDate.dayOfMonth().get() < billingCycleDay) {
-            final int lastDayOfTheMonth = proposedDate.dayOfMonth().getMaximumValue();
-            if (lastDayOfTheMonth < billingCycleDay) {
-                proposedDate = new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), lastDayOfTheMonth);
-            } else {
-                proposedDate = new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), billingCycleDay);
-            }
-        }
-
-        if (proposedDate.isBefore(previousBillCycleDate)) {
-            // Make sure not to go too far in the past
-            return previousBillCycleDate;
-        } else {
-            return proposedDate;
-        }
-    }
-
     public static LocalDate calculateEffectiveEndDate(final LocalDate billCycleDate, final LocalDate targetDate,
                                                       final BillingPeriod billingPeriod) {
         if (targetDate.isBefore(billCycleDate)) {
@@ -112,34 +87,6 @@ public class InvoiceDateUtils {
         return proposedDate;
     }
 
-    public static LocalDate calculateEffectiveEndDate(final LocalDate billCycleDate, final LocalDate targetDate,
-                                                      final LocalDate endDate, final BillingPeriod billingPeriod) {
-        if (targetDate.isBefore(endDate)) {
-            if (targetDate.isBefore(billCycleDate)) {
-                return billCycleDate;
-            }
-
-            final int numberOfMonthsInPeriod = billingPeriod.getNumberOfMonths();
-            int numberOfPeriods = 0;
-            LocalDate proposedDate = billCycleDate;
-
-            while (!proposedDate.isAfter(targetDate)) {
-                proposedDate = billCycleDate.plusMonths(numberOfPeriods * numberOfMonthsInPeriod);
-                numberOfPeriods += 1;
-            }
-
-            // the current period includes the target date
-            // check to see whether the end date truncates the period
-            if (endDate.isBefore(proposedDate)) {
-                return endDate;
-            } else {
-                return proposedDate;
-            }
-        } else {
-            return endDate;
-        }
-    }
-
     public static BigDecimal calculateProRationAfterLastBillingCycleDate(final LocalDate endDate, final LocalDate previousBillThroughDate,
                                                                          final BillingPeriod billingPeriod) {
         // Note: assumption is that previousBillThroughDate is correctly aligned with the billing cycle day
@@ -147,7 +94,8 @@ public class InvoiceDateUtils {
         return calculateProrationBetweenDates(previousBillThroughDate, endDate, previousBillThroughDate, nextBillThroughDate);
     }
 
-    public static LocalDate calculateBillingCycleDateOnOrAfter(final LocalDate date, final int billingCycleDayLocal) {
+    @VisibleForTesting
+    static LocalDate calculateBillingCycleDateOnOrAfter(final LocalDate date, final int billingCycleDayLocal) {
         final int lastDayOfMonth = date.dayOfMonth().getMaximumValue();
 
         final LocalDate fixedDate;
diff --git a/invoice/src/test/java/org/killbill/billing/invoice/generator/TestInvoiceDateUtils.java b/invoice/src/test/java/org/killbill/billing/invoice/generator/TestInvoiceDateUtils.java
index 485329b..01ed54d 100644
--- a/invoice/src/test/java/org/killbill/billing/invoice/generator/TestInvoiceDateUtils.java
+++ b/invoice/src/test/java/org/killbill/billing/invoice/generator/TestInvoiceDateUtils.java
@@ -1,7 +1,9 @@
 /*
- * Copyright 2010-2013 Ning, Inc.
+ * Copyright 2010-2014 Ning, Inc.
+ * Copyright 2014-2016 Groupon, Inc
+ * Copyright 2014-2016 The Billing Project, LLC
  *
- * Ning licenses this file to you under the Apache License, version 2.0
+ * The Billing Project licenses this file to you under the Apache License, version 2.0
  * (the "License"); you may not use this file except in compliance with the
  * License.  You may obtain a copy of the License at:
  *
@@ -29,15 +31,6 @@ import org.killbill.billing.invoice.InvoiceTestSuiteNoDB;
 public class TestInvoiceDateUtils extends InvoiceTestSuiteNoDB {
 
     @Test(groups = "fast")
-    public void testLastBCDShouldNotBeBeforePreviousBCD() throws Exception {
-        final LocalDate from = new LocalDate("2012-07-16");
-        final LocalDate previousBCD = new LocalDate("2012-08-15");
-        final int bcdLocal = 15;
-        final LocalDate lastBCD = InvoiceDateUtils.calculateLastBillingCycleDateBefore(from, previousBCD, bcdLocal, BillingPeriod.MONTHLY);
-        Assert.assertEquals(lastBCD, new LocalDate("2012-08-15"));
-    }
-
-    @Test(groups = "fast")
     public void testNextBCDShouldNotBeInThePast() throws Exception {
         final LocalDate from = new LocalDate("2012-07-16");
         final LocalDate to = InvoiceDateUtils.calculateBillingCycleDateOnOrAfter(from, 15);
@@ -105,15 +98,6 @@ public class TestInvoiceDateUtils extends InvoiceTestSuiteNoDB {
     }
 
     @Test(groups = "fast")
-    public void testLastBCD() throws Exception {
-        final LocalDate firstBCD = new LocalDate(2012, 7, 16);
-        final LocalDate effectiveEndDate = new LocalDate(2012, 9, 15);
-        final BillingPeriod billingPeriod = BillingPeriod.MONTHLY;
-        final LocalDate lastBCD = InvoiceDateUtils.calculateLastBillingCycleDateBefore(effectiveEndDate, firstBCD, 16, billingPeriod);
-        Assert.assertEquals(lastBCD, new LocalDate(2012, 8, 16));
-    }
-
-    @Test(groups = "fast")
     public void testCalculateNbOfBillingPeriods() throws Exception {
         final LocalDate firstBCD = new LocalDate(2012, 7, 16);
         final LocalDate lastBCD = new LocalDate(2012, 9, 16);