Skip to content

Commit abe9f5d

Browse files
[WIP] Use JUnit5
1 parent 0dcf8e4 commit abe9f5d

File tree

5 files changed

+99
-143
lines changed

5 files changed

+99
-143
lines changed

api/pom.xml

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,52 +17,10 @@
1717
<groupId>org.openmrs.api</groupId>
1818
<artifactId>openmrs-api</artifactId>
1919
</dependency>
20-
<dependency>
21-
<groupId>org.powermock</groupId>
22-
<artifactId>powermock-api-mockito2</artifactId>
23-
<version>2.0.7</version>
24-
<scope>test</scope>
25-
</dependency>
26-
<dependency>
27-
<groupId>org.powermock</groupId>
28-
<artifactId>powermock-api-support</artifactId>
29-
<version>2.0.7</version>
30-
<scope>test</scope>
31-
</dependency>
32-
<dependency>
33-
<groupId>org.powermock</groupId>
34-
<artifactId>powermock-core</artifactId>
35-
<version>2.0.7</version>
36-
<scope>test</scope>
37-
</dependency>
38-
<dependency>
39-
<groupId>org.powermock</groupId>
40-
<artifactId>powermock-module-junit4</artifactId>
41-
<version>2.0.7</version>
42-
<scope>test</scope>
43-
</dependency>
44-
<dependency>
45-
<groupId>org.powermock</groupId>
46-
<artifactId>powermock-module-junit4-common</artifactId>
47-
<version>2.0.7</version>
48-
<scope>test</scope>
49-
</dependency>
50-
<dependency>
51-
<groupId>org.powermock</groupId>
52-
<artifactId>powermock-reflect</artifactId>
53-
<version>2.0.7</version>
54-
<scope>test</scope>
55-
</dependency>
5620
<dependency>
5721
<groupId>org.mockito</groupId>
5822
<artifactId>mockito-core</artifactId>
59-
<version>3.5.11</version>
60-
<scope>test</scope>
61-
</dependency>
62-
<dependency>
63-
<groupId>junit</groupId>
64-
<artifactId>junit</artifactId>
65-
<version>4.13</version>
23+
<version>5.20.0</version>
6624
<scope>test</scope>
6725
</dependency>
6826
</dependencies>

api/src/test/java/org/openmrs/module/lamp/ChildNutritionProgramStrategyTest.java

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package 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-
93
import 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;
1415
import 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;
1521
import org.openmrs.Concept;
1622
import org.openmrs.Encounter;
1723
import org.openmrs.EncounterType;
@@ -25,15 +31,9 @@
2531
import org.openmrs.api.ConceptService;
2632
import org.openmrs.api.ProgramWorkflowService;
2733
import 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

api/src/test/java/org/openmrs/module/lamp/PrenatalProgramStrategyTest.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package org.openmrs.module.lamp;
22

33
import java.util.Date;
4-
import static org.junit.Assert.assertEquals;
5-
import org.junit.Before;
6-
import org.junit.Test;
7-
import org.junit.runner.RunWith;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
import static org.mockito.ArgumentMatchers.any;
8+
import static org.mockito.ArgumentMatchers.anyString;
9+
import static org.mockito.ArgumentMatchers.eq;
810
import org.mockito.Mock;
911
import org.mockito.Mockito;
12+
import static org.mockito.Mockito.mockStatic;
13+
import static org.mockito.Mockito.never;
14+
import static org.mockito.Mockito.times;
15+
import static org.mockito.Mockito.verify;
16+
import static org.mockito.Mockito.when;
1017
import org.openmrs.Concept;
1118
import org.openmrs.Encounter;
1219
import org.openmrs.EncounterType;
@@ -20,17 +27,9 @@
2027
import org.openmrs.api.ConceptService;
2128
import org.openmrs.api.ProgramWorkflowService;
2229
import org.openmrs.api.context.Context;
23-
import org.powermock.api.mockito.PowerMockito;
24-
import org.powermock.core.classloader.annotations.PowerMockIgnore;
25-
import org.powermock.core.classloader.annotations.PrepareForTest;
26-
import org.powermock.modules.junit4.PowerMockRunner;
30+
import org.openmrs.test.jupiter.BaseModuleContextSensitiveTest;
2731

28-
import static org.mockito.Mockito.*;
29-
30-
@RunWith(PowerMockRunner.class)
31-
@PrepareForTest({ Context.class, Utils.class })
32-
@PowerMockIgnore({ "javax.management.*", "javax.script.*" })
33-
public class PrenatalProgramStrategyTest {
32+
public class PrenatalProgramStrategyTest extends BaseModuleContextSensitiveTest {
3433

3534
@Mock
3635
private ProgramWorkflowService mockProgramWorkflowService;
@@ -40,10 +39,10 @@ public class PrenatalProgramStrategyTest {
4039

4140
private PrenatalProgramStrategy prenatalProgramStrategy;
4241

43-
@Before
42+
@BeforeEach
4443
public void setup() {
45-
PowerMockito.mockStatic(Context.class);
46-
PowerMockito.mockStatic(Utils.class);
44+
mockStatic(Context.class);
45+
mockStatic(Utils.class);
4746
Mockito.when(Context.getProgramWorkflowService()).thenReturn(mockProgramWorkflowService);
4847
Mockito.when(Context.getConceptService()).thenReturn(mockConceptService);
4948
prenatalProgramStrategy = new PrenatalProgramStrategy();
@@ -123,14 +122,14 @@ public void shouldExitWhenWorkflowIsNull() {
123122
pregnancyStatusConcept);
124123

125124
PatientProgram pp = new PatientProgram();
126-
PowerMockito.when(
125+
when(
127126
Utils.getOrCreateActiveProgramEnrollment(eq(mockProgramWorkflowService), eq(encounter.getPatient()),
128127
eq(program), any(Date.class))).thenReturn(pp);
129128

130129
Concept prenatalStatusValue = new Concept(2000);
131-
PowerMockito.when(Utils.findLatestCodedObsValue(encounter, pregnancyStatusConcept)).thenReturn(prenatalStatusValue);
130+
when(Utils.findLatestCodedObsValue(encounter, pregnancyStatusConcept)).thenReturn(prenatalStatusValue);
132131

133-
PowerMockito.when(Utils.getWorkflowByUuid(program, LampConfig.WORKFLOW_PRENATAL_UUID)).thenReturn(null);
132+
when(Utils.getWorkflowByUuid(program, LampConfig.WORKFLOW_PRENATAL_UUID)).thenReturn(null);
134133

135134
User user = new User();
136135

@@ -153,17 +152,17 @@ public void shouldExitWhenTargetStateIsNull() {
153152
pregnancyStatusConcept);
154153

155154
PatientProgram pp = new PatientProgram();
156-
PowerMockito.when(
155+
when(
157156
Utils.getOrCreateActiveProgramEnrollment(eq(mockProgramWorkflowService), eq(encounter.getPatient()),
158157
eq(program), any(Date.class))).thenReturn(pp);
159158

160159
Concept prenatalStatusValue = new Concept(2000);
161-
PowerMockito.when(Utils.findLatestCodedObsValue(encounter, pregnancyStatusConcept)).thenReturn(prenatalStatusValue);
160+
when(Utils.findLatestCodedObsValue(encounter, pregnancyStatusConcept)).thenReturn(prenatalStatusValue);
162161

163162
ProgramWorkflow wf = new ProgramWorkflow();
164-
PowerMockito.when(Utils.getWorkflowByUuid(program, LampConfig.WORKFLOW_PRENATAL_UUID)).thenReturn(wf);
163+
when(Utils.getWorkflowByUuid(program, LampConfig.WORKFLOW_PRENATAL_UUID)).thenReturn(wf);
165164

166-
PowerMockito.when(Utils.getStateByConcept(wf, prenatalStatusValue)).thenReturn(null);
165+
when(Utils.getStateByConcept(wf, prenatalStatusValue)).thenReturn(null);
167166

168167
User user = new User();
169168

@@ -189,18 +188,18 @@ public void shouldSaveProgram() {
189188
pregnancyStatusConcept);
190189

191190
PatientProgram pp = new PatientProgram();
192-
PowerMockito.when(
191+
when(
193192
Utils.getOrCreateActiveProgramEnrollment(eq(mockProgramWorkflowService), eq(encounter.getPatient()),
194193
eq(program), any(Date.class))).thenReturn(pp);
195194

196195
Concept prenatalStatusValue = new Concept(2000);
197-
PowerMockito.when(Utils.findLatestCodedObsValue(encounter, pregnancyStatusConcept)).thenReturn(prenatalStatusValue);
196+
when(Utils.findLatestCodedObsValue(encounter, pregnancyStatusConcept)).thenReturn(prenatalStatusValue);
198197

199198
ProgramWorkflow wf = new ProgramWorkflow();
200-
PowerMockito.when(Utils.getWorkflowByUuid(program, LampConfig.WORKFLOW_PRENATAL_UUID)).thenReturn(wf);
199+
when(Utils.getWorkflowByUuid(program, LampConfig.WORKFLOW_PRENATAL_UUID)).thenReturn(wf);
201200

202201
ProgramWorkflowState targetState = new ProgramWorkflowState();
203-
PowerMockito.when(Utils.getStateByConcept(wf, prenatalStatusValue)).thenReturn(targetState);
202+
when(Utils.getStateByConcept(wf, prenatalStatusValue)).thenReturn(targetState);
204203

205204
// when
206205
prenatalProgramStrategy.execute(encounter, user, now, "reason");

0 commit comments

Comments
 (0)