Repository: killbill/killbill
Issue: Pending subscription shows a `PENDING` state after being canceled

Scenario:
1. Create a subscription with an future start (billing) date -> `PENDING` state
2. Cancel the subscription immediately -> This will default to the future start date
3. Fetch the subscription and check the state -> `CANCELLED` state

It seems that in step 3. `state` is incorrectly showing `PENDING`

Changed files:
subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java
subscription/src/test/java/org/killbill/billing/subscription/api/user/TestUserApiCancel.java

diff --git a/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java b/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java
index 1a9e0cfa83..157269856b 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBase.java
@@ -184,6 +184,7 @@ public class DefaultSubscriptionBase extends EntityBase implements SubscriptionB
         throw new IllegalStateException("Should return a valid EntitlementState");
     }
 
+
     @Override
     public EntitlementSourceType getSourceType() {
         if (transitions == null) {
diff --git a/subscription/src/test/java/org/killbill/billing/subscription/api/user/TestUserApiCancel.java b/subscription/src/test/java/org/killbill/billing/subscription/api/user/TestUserApiCancel.java
index aa74d92dc7..3d7680b140 100644
--- a/subscription/src/test/java/org/killbill/billing/subscription/api/user/TestUserApiCancel.java
+++ b/subscription/src/test/java/org/killbill/billing/subscription/api/user/TestUserApiCancel.java
@@ -509,17 +509,22 @@ public class TestUserApiCancel extends SubscriptionTestSuiteWithEmbeddedDB {
         assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
 
         subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext);
+        
+        final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
+        assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0);
+        assertEquals(subscription2.getState(), Entitlement.EntitlementState.PENDING);
 
         testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL);
         clock.addDays(5);
         assertListenerStatus();
 
-        final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
-        assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0);
-        assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED);
-        assertNull(subscription2.getCurrentPlan());
+        final DefaultSubscriptionBase subscription3 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
+        assertEquals(subscription3.getStartDate().compareTo(subscription.getStartDate()), 0);
+        assertEquals(subscription3.getState(), Entitlement.EntitlementState.CANCELLED);
+        assertNull(subscription3.getCurrentPlan());
     }
-
+    
+  
 
     @Test(groups = "slow", description="See https://github.com/killbill/killbill/issues/1207")
     public void testDoubleFutureLaterCancellation() throws SubscriptionBaseApiException {