mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-25 23:26:01 +00:00
How to boolean logic?
This commit is contained in:
parent
82e51292f5
commit
7dc8bf9b9f
2 changed files with 49 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue