-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add support for relaxing vaccination schedules
- Loading branch information
1 parent
8a8bb5b
commit 3fa8351
Showing
9 changed files
with
171 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
opensrp-immunization/src/test/java/org/smartregister/immunization/utils/UtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.smartregister.immunization.utils; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.powermock.api.mockito.PowerMockito; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.rule.PowerMockRule; | ||
import org.smartregister.immunization.ImmunizationLibrary; | ||
import org.smartregister.immunization.util.IMConstants; | ||
import org.smartregister.immunization.util.Utils; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* Created by ndegwamartin on 2019-07-23. | ||
*/ | ||
@PrepareForTest({ImmunizationLibrary.class}) | ||
public class UtilsTest { | ||
@Rule | ||
public PowerMockRule rule = new PowerMockRule(); | ||
@Mock | ||
private ImmunizationLibrary immunizationLibrary; | ||
@Mock | ||
private Properties properties; | ||
|
||
private static String OFFSET_days = "+2d"; | ||
private static String OFFSET_days_negative = "-2d"; | ||
private static String OFFSET_month_days = "+4m,3d"; | ||
private static String OFFSET_months = "+6m"; | ||
private static String OFFSET_years = "-5y"; | ||
private static String RELAXATION_DAYS = "2"; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void testUpdateRelaxationDaysGivesCorrectOffsetForDaysDefault() { | ||
String result = Utils.updateRelaxationDays(OFFSET_days); | ||
Assert.assertEquals(OFFSET_days, result); | ||
} | ||
|
||
@Test | ||
public void testUpdateRelaxationDaysGivesCorrectOffsetForDays() { | ||
|
||
PowerMockito.mockStatic(ImmunizationLibrary.class); | ||
PowerMockito.when(ImmunizationLibrary.getInstance()).thenReturn(immunizationLibrary); | ||
PowerMockito.when(immunizationLibrary.getProperties()).thenReturn(properties); | ||
PowerMockito.when(properties.getProperty(IMConstants.APP_PROPERTIES.VACCINE_RELAXATION_DAYS)).thenReturn(RELAXATION_DAYS); | ||
|
||
String result = Utils.updateRelaxationDays(OFFSET_days); | ||
Assert.assertEquals("+0d", result); | ||
} | ||
|
||
@Test | ||
public void testUpdateRelaxationDaysGivesCorrectOffsetForDaysNegative() { | ||
|
||
PowerMockito.mockStatic(ImmunizationLibrary.class); | ||
PowerMockito.when(ImmunizationLibrary.getInstance()).thenReturn(immunizationLibrary); | ||
PowerMockito.when(immunizationLibrary.getProperties()).thenReturn(properties); | ||
PowerMockito.when(properties.getProperty(IMConstants.APP_PROPERTIES.VACCINE_RELAXATION_DAYS)).thenReturn(RELAXATION_DAYS); | ||
|
||
String result = Utils.updateRelaxationDays(OFFSET_days_negative); | ||
Assert.assertEquals("-4d", result); | ||
} | ||
|
||
@Test | ||
public void testUpdateRelaxationDaysGivesCorrectOffsetForMonths() { | ||
|
||
PowerMockito.mockStatic(ImmunizationLibrary.class); | ||
PowerMockito.when(ImmunizationLibrary.getInstance()).thenReturn(immunizationLibrary); | ||
PowerMockito.when(immunizationLibrary.getProperties()).thenReturn(properties); | ||
PowerMockito.when(properties.getProperty(IMConstants.APP_PROPERTIES.VACCINE_RELAXATION_DAYS)).thenReturn(RELAXATION_DAYS); | ||
|
||
String result = Utils.updateRelaxationDays(OFFSET_months); | ||
Assert.assertEquals("+6m,-2d", result); | ||
} | ||
|
||
@Test | ||
public void testUpdateRelaxationDaysGivesCorrectOffsetForYears() { | ||
|
||
PowerMockito.mockStatic(ImmunizationLibrary.class); | ||
PowerMockito.when(ImmunizationLibrary.getInstance()).thenReturn(immunizationLibrary); | ||
PowerMockito.when(immunizationLibrary.getProperties()).thenReturn(properties); | ||
PowerMockito.when(properties.getProperty(IMConstants.APP_PROPERTIES.VACCINE_RELAXATION_DAYS)).thenReturn(RELAXATION_DAYS); | ||
|
||
String result = Utils.updateRelaxationDays(OFFSET_years); | ||
Assert.assertEquals("-5y,-2d", result); | ||
} | ||
|
||
@Test | ||
public void testUpdateRelaxationDaysGivesCorrectOffsetForMonthsDays() { | ||
|
||
PowerMockito.mockStatic(ImmunizationLibrary.class); | ||
PowerMockito.when(ImmunizationLibrary.getInstance()).thenReturn(immunizationLibrary); | ||
PowerMockito.when(immunizationLibrary.getProperties()).thenReturn(properties); | ||
PowerMockito.when(properties.getProperty(IMConstants.APP_PROPERTIES.VACCINE_RELAXATION_DAYS)).thenReturn(RELAXATION_DAYS); | ||
|
||
String result = Utils.updateRelaxationDays(OFFSET_month_days); | ||
Assert.assertEquals("+4m,1d", result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters