11package org .openmrs .module .lamp ;
22
3- import static org .junit .Assert .assertEquals ;
4- import static org .junit .Assert .assertFalse ;
5- import static org .junit .Assert .assertNull ;
6- import static org .junit .Assert .assertTrue ;
7- import static org .mockito .Mockito .*;
8-
93import java .util .Date ;
104
11- import org .junit .Before ;
12- import org .junit .Test ;
13- import org .junit .runner .RunWith ;
5+ import static org .junit .jupiter .api .Assertions .assertEquals ;
6+ import static org .junit .jupiter .api .Assertions .assertFalse ;
7+ import static org .junit .jupiter .api .Assertions .assertNull ;
8+ import static org .junit .jupiter .api .Assertions .assertTrue ;
9+ import org .junit .jupiter .api .BeforeEach ;
10+ import org .junit .jupiter .api .Test ;
11+ import org .junit .jupiter .api .extension .ExtendWith ;
12+ import static org .mockito .ArgumentMatchers .any ;
13+ import static org .mockito .ArgumentMatchers .anyString ;
14+ import static org .mockito .ArgumentMatchers .eq ;
1415import org .mockito .Mock ;
16+ import static org .mockito .Mockito .mockStatic ;
17+ import static org .mockito .Mockito .never ;
18+ import static org .mockito .Mockito .times ;
19+ import static org .mockito .Mockito .verify ;
20+ import static org .mockito .Mockito .when ;
1521import org .openmrs .Concept ;
1622import org .openmrs .Encounter ;
1723import org .openmrs .EncounterType ;
2531import org .openmrs .api .ConceptService ;
2632import org .openmrs .api .ProgramWorkflowService ;
2733import org .openmrs .api .context .Context ;
28- import org .powermock .api .mockito .PowerMockito ;
29- import org .powermock .core .classloader .annotations .PowerMockIgnore ;
30- import org .powermock .core .classloader .annotations .PrepareForTest ;
31- import org .powermock .modules .junit4 .PowerMockRunner ;
34+ import org .openmrs .test .jupiter .BaseModuleContextSensitiveTest ;
3235
33- @ RunWith (PowerMockRunner .class )
34- @ PrepareForTest ({ Context .class , Utils .class })
35- @ PowerMockIgnore ({ "javax.management.*" , "javax.script.*" })
36- public class ChildNutritionProgramStrategyTest {
36+ public class ChildNutritionProgramStrategyTest extends BaseModuleContextSensitiveTest {
3737
3838 @ Mock
3939 private ProgramWorkflowService mockProgramWorkflowService ;
@@ -59,10 +59,10 @@ private Encounter buildEncounter(boolean childNutritionType) {
5959 return encounter ;
6060 }
6161
62- @ Before
62+ @ BeforeEach
6363 public void setup () {
64- PowerMockito . mockStatic (Context .class );
65- PowerMockito . mockStatic (Utils .class );
64+ mockStatic (Context .class );
65+ mockStatic (Utils .class );
6666
6767 when (Context .getProgramWorkflowService ()).thenReturn (mockProgramWorkflowService );
6868 when (Context .getConceptService ()).thenReturn (mockConceptService );
@@ -130,12 +130,12 @@ public void shouldExitWhenBothValuesAreNull() {
130130 reasonC );
131131
132132 PatientProgram patientProgram = new PatientProgram ();
133- PowerMockito . when (
133+ when (
134134 Utils .getOrCreateActiveProgramEnrollment (eq (mockProgramWorkflowService ), eq (encounter .getPatient ()),
135135 eq (program ), any (Date .class ))).thenReturn (patientProgram );
136136
137- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (null );
138- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (null );
137+ when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (null );
138+ when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (null );
139139
140140 childNutritionProgramStrategy .execute (encounter , new User (), new Date (), "reason" );
141141
@@ -156,14 +156,14 @@ public void shouldExitWhenWorkflowIsNull() {
156156 reasonC );
157157
158158 PatientProgram patientProgram = new PatientProgram ();
159- PowerMockito . when (
159+ when (
160160 Utils .getOrCreateActiveProgramEnrollment (eq (mockProgramWorkflowService ), eq (encounter .getPatient ()),
161161 eq (program ), any (Date .class ))).thenReturn (patientProgram );
162162
163- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (new Concept (201 ));
164- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (null );
163+ when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (new Concept (201 ));
164+ when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (null );
165165
166- PowerMockito . when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (null );
166+ when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (null );
167167
168168 childNutritionProgramStrategy .execute (encounter , new User (), new Date (), "reason" );
169169
@@ -184,18 +184,18 @@ public void shouldExitWhenTargetStateFromMalnutritionStatusIsNull() {
184184 reasonC );
185185
186186 PatientProgram pp = new PatientProgram ();
187- PowerMockito . when (
187+ when (
188188 Utils .getOrCreateActiveProgramEnrollment (eq (mockProgramWorkflowService ), eq (encounter .getPatient ()),
189189 eq (program ), any (Date .class ))).thenReturn (pp );
190190
191191 Concept malValue = new Concept (201 );
192- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (malValue );
193- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (null );
192+ when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (malValue );
193+ when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (null );
194194
195195 ProgramWorkflow wf = new ProgramWorkflow ();
196- PowerMockito . when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (wf );
196+ when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (wf );
197197
198- PowerMockito . when (Utils .getStateByConcept (wf , malValue )).thenReturn (null );
198+ when (Utils .getStateByConcept (wf , malValue )).thenReturn (null );
199199
200200 childNutritionProgramStrategy .execute (encounter , new User (), new Date (), "reason" );
201201
@@ -216,19 +216,19 @@ public void shouldExitWhenTargetStateFromReasonForDischargeValueIsNull() {
216216 reasonC );
217217
218218 PatientProgram pp = new PatientProgram ();
219- PowerMockito . when (
219+ when (
220220 Utils .getOrCreateActiveProgramEnrollment (eq (mockProgramWorkflowService ), eq (encounter .getPatient ()),
221221 eq (program ), any (Date .class ))).thenReturn (pp );
222222
223223 // malnutrition value null, reason value present
224- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (null );
224+ when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (null );
225225 Concept reasonValue = new Concept (301 );
226- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (reasonValue );
226+ when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (reasonValue );
227227
228228 ProgramWorkflow wf = new ProgramWorkflow ();
229- PowerMockito . when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (wf );
229+ when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (wf );
230230
231- PowerMockito . when (Utils .getStateByConcept (wf , reasonValue )).thenReturn (null );
231+ when (Utils .getStateByConcept (wf , reasonValue )).thenReturn (null );
232232
233233 childNutritionProgramStrategy .execute (encounter , new User (), new Date (), "reason" );
234234
@@ -250,21 +250,21 @@ public void shouldNotSetDateCompletedWhenReachedTargetFromMalnutritionStatus() {
250250 reasonC );
251251
252252 PatientProgram pp = new PatientProgram ();
253- PowerMockito . when (
253+ when (
254254 Utils .getOrCreateActiveProgramEnrollment (eq (mockProgramWorkflowService ), eq (encounter .getPatient ()),
255255 eq (program ), any (Date .class ))).thenReturn (pp );
256256
257257 Concept malValue = new Concept (201 );
258258 malValue .setUuid (LampConfig .CONCEPT_REACHED_TARGET_GOAL_WEIGHT_UUID );
259- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (malValue );
260- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (null );
259+ when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (malValue );
260+ when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (null );
261261
262262 ProgramWorkflow wf = new ProgramWorkflow ();
263- PowerMockito . when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (wf );
263+ when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (wf );
264264
265265 ProgramWorkflowState state = new ProgramWorkflowState ();
266266 state .setConcept (malValue );
267- PowerMockito . when (Utils .getStateByConcept (wf , malValue )).thenReturn (state );
267+ when (Utils .getStateByConcept (wf , malValue )).thenReturn (state );
268268
269269 childNutritionProgramStrategy .execute (encounter , new User (), now , "reason" );
270270
@@ -292,24 +292,24 @@ public void shouldSetDateCompletedWhenReachedTargetFromReasonForDischarge() {
292292 reasonC );
293293
294294 PatientProgram pp = new PatientProgram ();
295- PowerMockito . when (
295+ when (
296296 Utils .getOrCreateActiveProgramEnrollment (eq (mockProgramWorkflowService ), eq (encounter .getPatient ()),
297297 eq (program ), any (Date .class ))).thenReturn (pp );
298298
299299 // malnutrition null; reason == REACHED_TARGET_GOAL_WEIGHT
300- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (null );
300+ when (Utils .findLatestCodedObsValue (encounter , malC )).thenReturn (null );
301301
302302 Concept reasonValue = new Concept (301 );
303303 reasonValue .setUuid (LampConfig .CONCEPT_REACHED_TARGET_GOAL_WEIGHT_UUID );
304- PowerMockito . when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (reasonValue );
304+ when (Utils .findLatestCodedObsValue (encounter , reasonC )).thenReturn (reasonValue );
305305
306306 ProgramWorkflow wf = new ProgramWorkflow ();
307- PowerMockito . when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (wf );
307+ when (Utils .getWorkflowByUuid (program , LampConfig .WORKFLOW_CHILD_NUTRITION_UUID )).thenReturn (wf );
308308
309309 ProgramWorkflowState state = new ProgramWorkflowState ();
310310 state .setConcept (reasonValue );
311311 state .setTerminal (true );
312- PowerMockito . when (Utils .getStateByConcept (wf , reasonValue )).thenReturn (state );
312+ when (Utils .getStateByConcept (wf , reasonValue )).thenReturn (state );
313313
314314 childNutritionProgramStrategy .execute (encounter , new User (), now , "reason" );
315315
0 commit comments