killbill-aplcache

entitlement: add test for TimedMigration Signed-off-by:

6/27/2012 4:39:53 PM

Details

diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/alignment/TimedMigration.java b/entitlement/src/main/java/com/ning/billing/entitlement/alignment/TimedMigration.java
index 118c2eb..0c32b57 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/alignment/TimedMigration.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/alignment/TimedMigration.java
@@ -64,4 +64,62 @@ public class TimedMigration {
     public String getPriceList() {
         return priceList;
     }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder();
+        sb.append("TimedMigration");
+        sb.append("{apiEventType=").append(apiEventType);
+        sb.append(", eventTime=").append(eventTime);
+        sb.append(", eventType=").append(eventType);
+        sb.append(", plan=").append(plan);
+        sb.append(", phase=").append(phase);
+        sb.append(", priceList='").append(priceList).append('\'');
+        sb.append('}');
+        return sb.toString();
+    }
+
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        final TimedMigration that = (TimedMigration) o;
+
+        if (apiEventType != that.apiEventType) {
+            return false;
+        }
+        if (eventTime != null ? !eventTime.equals(that.eventTime) : that.eventTime != null) {
+            return false;
+        }
+        if (eventType != that.eventType) {
+            return false;
+        }
+        if (phase != null ? !phase.equals(that.phase) : that.phase != null) {
+            return false;
+        }
+        if (plan != null ? !plan.equals(that.plan) : that.plan != null) {
+            return false;
+        }
+        if (priceList != null ? !priceList.equals(that.priceList) : that.priceList != null) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = eventTime != null ? eventTime.hashCode() : 0;
+        result = 31 * result + (eventType != null ? eventType.hashCode() : 0);
+        result = 31 * result + (apiEventType != null ? apiEventType.hashCode() : 0);
+        result = 31 * result + (plan != null ? plan.hashCode() : 0);
+        result = 31 * result + (phase != null ? phase.hashCode() : 0);
+        result = 31 * result + (priceList != null ? priceList.hashCode() : 0);
+        return result;
+    }
 }
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java
new file mode 100644
index 0000000..09740d2
--- /dev/null
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/alignment/TestTimedMigration.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2010-2012 Ning, Inc.
+ *
+ * Ning 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:
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.entitlement.alignment;
+
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.ning.billing.catalog.api.Plan;
+import com.ning.billing.catalog.api.PlanPhase;
+import com.ning.billing.entitlement.events.EntitlementEvent;
+import com.ning.billing.entitlement.events.user.ApiEventType;
+
+public class TestTimedMigration {
+    @Test(groups = "fast")
+    public void testConstructor() throws Exception {
+        final DateTime eventTime = new DateTime(DateTimeZone.UTC);
+        final EntitlementEvent.EventType eventType = EntitlementEvent.EventType.API_USER;
+        final ApiEventType apiEventType = ApiEventType.CREATE;
+        final Plan plan = Mockito.mock(Plan.class);
+        final PlanPhase phase = Mockito.mock(PlanPhase.class);
+        final String priceList = UUID.randomUUID().toString();
+        final TimedMigration timedMigration = new TimedMigration(eventTime, eventType, apiEventType, plan, phase, priceList);
+        final TimedMigration otherTimedMigration = new TimedMigration(eventTime, eventType, apiEventType, plan, phase, priceList);
+
+        Assert.assertEquals(otherTimedMigration, timedMigration);
+        Assert.assertEquals(timedMigration.getEventTime(), eventTime);
+        Assert.assertEquals(timedMigration.getEventType(), eventType);
+        Assert.assertEquals(timedMigration.getApiEventType(), apiEventType);
+        Assert.assertEquals(timedMigration.getPlan(), plan);
+        Assert.assertEquals(timedMigration.getPhase(), phase);
+        Assert.assertEquals(timedMigration.getPriceList(), priceList);
+    }
+}