killbill-memoizeit

Details

diff --git a/catalog/src/main/java/com/ning/billing/catalog/PriceList.java b/catalog/src/main/java/com/ning/billing/catalog/PriceList.java
index 18e21cf..c4842f9 100644
--- a/catalog/src/main/java/com/ning/billing/catalog/PriceList.java
+++ b/catalog/src/main/java/com/ning/billing/catalog/PriceList.java
@@ -58,7 +58,8 @@ public class PriceList extends ValidatingConfig<Catalog>  {
 
 	public Plan findPlan(IProduct product, BillingPeriod period) {
         for (Plan cur : getPlans()) {
-            if (cur.getProduct().equals(product) && cur.getBillingPeriod().equals(period)) {
+            if (cur.getProduct().equals(product) && 
+            		(cur.getBillingPeriod() == null || cur.getBillingPeriod().equals(period))) {
                 return cur;
             }
         }
diff --git a/catalog/src/test/java/com/ning/billing/catalog/TestPriceListSet.java b/catalog/src/test/java/com/ning/billing/catalog/TestPriceListSet.java
index fad50a8..0825eb9 100644
--- a/catalog/src/test/java/com/ning/billing/catalog/TestPriceListSet.java
+++ b/catalog/src/test/java/com/ning/billing/catalog/TestPriceListSet.java
@@ -50,4 +50,30 @@ public class TestPriceListSet {
 		Assert.assertEquals(set.getPlanListFrom("child", foo, BillingPeriod.ANNUAL).getFinalPhase().getPhaseType(), PhaseType.DISCOUNT);
 		Assert.assertEquals(set.getPlanListFrom("child", foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
 	}
+	
+	public void testForNullBillingPeriod() {
+		Product foo = new Product("Foo", ProductCategory.BASE);
+		Product bar = new Product("Bar", ProductCategory.BASE);
+		Plan[] defaultPlans = new Plan[]{ 
+				new Plan("plan-foo-monthly", foo, new PlanPhase(BillingPeriod.MONTHLY, PhaseType.EVERGREEN)),
+				new Plan("plan-bar-monthly", bar, new PlanPhase(BillingPeriod.MONTHLY, PhaseType.EVERGREEN)),
+				new Plan("plan-foo-annual", foo, new PlanPhase(null, PhaseType.EVERGREEN)),
+				new Plan("plan-bar-annual", bar, new PlanPhase(null, PhaseType.EVERGREEN))
+				};
+		Plan[] childPlans = new Plan[]{ 
+				new Plan("plan-foo", foo, new PlanPhase(BillingPeriod.ANNUAL, PhaseType.DISCOUNT)),
+				new Plan("plan-bar", bar, new PlanPhase(BillingPeriod.ANNUAL, PhaseType.DISCOUNT))
+				};
+		PriceListDefault defaultPriceList = new PriceListDefault(defaultPlans);
+		PriceList[] childPriceLists = new PriceList[] {
+				new PriceList(childPlans, "child")
+		};
+		PriceListSet set = new PriceListSet(defaultPriceList, childPriceLists);
+		
+		Assert.assertEquals(set.getPlanListFrom("child", foo, BillingPeriod.ANNUAL).getFinalPhase().getPhaseType(), PhaseType.DISCOUNT);
+		Assert.assertEquals(set.getPlanListFrom("child", foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
+		Assert.assertEquals(set.getPlanListFrom(IPriceListSet.DEFAULT_PRICELIST_NAME, foo, BillingPeriod.ANNUAL).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
+		Assert.assertEquals(set.getPlanListFrom(IPriceListSet.DEFAULT_PRICELIST_NAME, foo, BillingPeriod.MONTHLY).getFinalPhase().getPhaseType(), PhaseType.EVERGREEN);
+	}
+
 }