Skip to content

Commit

Permalink
Add VaccineTrigger Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Jun 29, 2021
1 parent a09d80e commit effc622
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.robolectric.util.ReflectionHelpers;
import org.smartregister.Context;
import org.smartregister.immunization.BaseUnitTest;
import org.smartregister.immunization.ImmunizationLibrary;
Expand Down Expand Up @@ -104,4 +105,41 @@ public void assertGetWindowTestReturnsCurrentWindow() {

}

@Test
public void testInitCreatesValidVaccineTriggerForExpiryConstructorParamWithLMP() {

Due expiry = new Due();
expiry.reference = "LMP";
expiry.offset = "+1y, +3m, -1d";

VaccineTrigger vaccineTrigger = VaccineTrigger.init(expiry);
Assert.assertNotNull(vaccineTrigger);

Assert.assertEquals("LMP", ReflectionHelpers.getField(vaccineTrigger, "reference").toString());
Assert.assertEquals("+1y, +3m, -1d", ReflectionHelpers.getField(vaccineTrigger, "offset"));

}

@Test
public void testInitCreatesValidVaccineTriggerForExpiryConstructorParamWithDOB() {

Due expiry = new Due();
expiry.reference = "DOB";
expiry.offset = "+2m,+2d";

VaccineTrigger vaccineTrigger = VaccineTrigger.init(expiry);
Assert.assertNotNull(vaccineTrigger);

Assert.assertEquals("DOB", ReflectionHelpers.getField(vaccineTrigger, "reference").toString());
Assert.assertEquals("+2m,+2d", ReflectionHelpers.getField(vaccineTrigger, "offset"));

}

@Test
public void testInitReturnsNullForNullExpiryConstructorParam() {
Due nullDueParam = null;
VaccineTrigger vaccineTrigger = VaccineTrigger.init(nullDueParam);
Assert.assertNull(vaccineTrigger);

}
}

0 comments on commit effc622

Please sign in to comment.