Skip to content

Commit

Permalink
Fix failing test : PlanResourceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Dec 11, 2021
1 parent 7f5005f commit a22a1d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/java/org/opensrp/web/rest/PlanResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,10 @@ public void generateCaseTriggeredPlans() {
}
}

public Date getCurrentDate(){
return new Date();
}

public PlanDefinition createPlanFromTemplate(String templateString, Event caseDetailsEvent) {
// Build map
Map<String, String> valuesMap = new HashMap<>();
Expand All @@ -588,7 +592,7 @@ public PlanDefinition createPlanFromTemplate(String templateString, Event caseDe
caseDetailsEvent.getDetails().get(Constants.Plan.PLAN_IDENTIFIER) : UUID.randomUUID().toString();
valuesMap.put(Constants.Plan.PLAN_IDENTIFIER, planIdentifier);
SimpleDateFormat sdf = new SimpleDateFormat(Constants.Plan.DATE_FORMAT);
Date currentDate = new Date();
Date currentDate = getCurrentDate();
Date endDate;
Calendar c = Calendar.getInstance();
c.setTime(currentDate);
Expand Down
9 changes: 8 additions & 1 deletion src/test/java/org/opensrp/web/rest/PlanResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
Expand All @@ -32,8 +33,10 @@
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;

import org.apache.commons.lang3.tuple.Pair;
import org.joda.time.DateTime;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -1736,7 +1739,11 @@ public void testGenerateCaseTriggeredPlans() {
Template template = gson.fromJson(templateString, Template.class);
when(templateService.getTemplateByTemplateId(1)).thenReturn(template);

planResource.generateCaseTriggeredPlans();
PlanResource planResourceSpy = spy(planResource);
Date todayDate = new DateTime(2021, 12, 10, 0, 0, 0, 0).toDate();
when(planResourceSpy.getCurrentDate()).thenReturn(todayDate);

planResourceSpy.generateCaseTriggeredPlans();

verify(planService).addPlan(argumentCaptor.capture(), stringArgumentCaptor.capture());
assertEquals(Constants.Plan.PLAN_USER, stringArgumentCaptor.getValue());
Expand Down

0 comments on commit a22a1d0

Please sign in to comment.