How to boolean logic?

This commit is contained in:
Phillip Thelen 2017-03-06 20:43:35 +01:00
parent 82e51292f5
commit 7dc8bf9b9f
2 changed files with 49 additions and 4 deletions

View file

@ -55,10 +55,7 @@ public class SubscriptionPlan extends BaseModel {
public boolean isActive() {
Date today = new Date();
if (planId != null && this.dateTerminated == null) {
return true;
}
return planId != null || this.dateTerminated.after(today);
return planId != null && (this.dateTerminated == null || this.dateTerminated.after(today));
}
@Override

View file

@ -0,0 +1,48 @@
package com.magicmicky.habitrpgwrapper.lib.models;
import org.junit.Before;
import org.junit.Test;
import java.util.Calendar;
import java.util.Date;
import static org.junit.Assert.*;
public class SubscriptionPlanTest {
private SubscriptionPlan plan;
@Before
public void setUp() throws Exception {
this.plan = new SubscriptionPlan();
this.plan.planId = "test";
}
@Test
public void isInactiveForNoPlanId() throws Exception {
this.plan.planId = null;
assertFalse(this.plan.isActive());
}
@Test
public void isActiveForNoTerminationDate() throws Exception {
assertTrue(this.plan.isActive());
}
@Test
public void isActiveForLaterTerminationDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.DATE, 1);
this.plan.dateTerminated = calendar.getTime();
assertTrue(this.plan.isActive());
}
@Test
public void isInactiveForEarlierTerminationDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.DATE, -1);
this.plan.dateTerminated = calendar.getTime();
assertFalse(this.plan.isActive());
}
}