Skip to content

Commit

Permalink
Merge branch 'master' into Testing_Tuesday
Browse files Browse the repository at this point in the history
  • Loading branch information
Mstjamush authored Dec 4, 2020
2 parents 78d96fd + ec7fafb commit 6513b3d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.smartregister.chw.core.implementation;

import android.content.Context;

import org.smartregister.chw.core.rule.MonthlyAlertRule;

public class MonthlyAlertRuleImpl extends MonthlyAlertRule {

public MonthlyAlertRuleImpl(Context context, long lastVisitDateLong, long dateCreatedLong) {
super(context, lastVisitDateLong, dateCreatedLong);
}

@Override
public String getRuleKey() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,26 @@ public void buttonStatusNotDueIfDateBeforeDueAndExpiry() {
}


}
@Test
public void canGetDueDate() {
dueDate = LocalDate.now().plusDays(10).toDateTime(LocalTime.MIDNIGHT);
ReflectionHelpers.setField(fpAlertRule, "dueDate", dueDate);
Assert.assertEquals(dueDate.toDate(), fpAlertRule.getDueDate());
}

@Test
public void canGetOverdueDate() {
overDueDate = LocalDate.now().minusDays(1).toDateTime(LocalTime.MIDNIGHT);
ReflectionHelpers.setField(fpAlertRule, "overDueDate", overDueDate);
Assert.assertEquals(overDueDate.toDate(), fpAlertRule.getOverDueDate());
}

@Test
public void canGetExpiryDate() {
expiryDate = LocalDate.now().plusDays(10).toDateTime(LocalTime.MIDNIGHT);
ReflectionHelpers.setField(fpAlertRule, "expiryDate", expiryDate);
Assert.assertEquals(expiryDate.toDate(), fpAlertRule.getExpiryDate());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,45 @@
import android.content.Context;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.powermock.reflect.Whitebox;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.chw.core.BaseRobolectricTest;
import org.smartregister.chw.core.implementation.MonthlyAlertRuleImpl;

import java.util.Date;


/**
* Created by Qazi Abubakar
*/
public class MonthlyAlertRuleTest {
private final Context context = RuntimeEnvironment.application;
private final long lastVisitDate = new DateTime().minusDays(7).toDate().getTime();
private final long dateCreated = new DateTime().minusDays(30).toDate().getTime();
private final MonthlyAlertRule monthlyAlertRule = new MonthlyAlertRule(context, lastVisitDate, dateCreated) {
@Override
public String getRuleKey() {
return "familyKitAlertRule";
}
};

public class MonthlyAlertRuleTest extends BaseRobolectricTest {

private MonthlyAlertRule monthlyAlertRule;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Context context = RuntimeEnvironment.application;
monthlyAlertRule = new MonthlyAlertRuleImpl(context, new Date().getTime(), new Date().getTime());
}

@Test
public void lastDueDateIs1stIfLastVisitEarlierThanCreated() throws Exception {
Date firstDayOfThisMonth = LocalDate.now().withDayOfMonth(1).toDate();
LocalDate dateCreated = LocalDate.fromDateFields(firstDayOfThisMonth).plusWeeks(2);
LocalDate lastVisitDate = LocalDate.fromDateFields(firstDayOfThisMonth).plusWeeks(1);

ReflectionHelpers.setField(monthlyAlertRule, "dateCreated", dateCreated);
ReflectionHelpers.setField(monthlyAlertRule, "lastVisitDate", lastVisitDate);

Assert.assertEquals(firstDayOfThisMonth, Whitebox.invokeMethod(monthlyAlertRule, "getLastDueDate"));
}

@Test
public void testGetLastDayOfMonth(){
DateTime first = new DateTime(new Date()).withDayOfMonth(1);
Expand Down

0 comments on commit 6513b3d

Please sign in to comment.