Skip to content

Commit 650826e

Browse files
committed
O3-5011: Queue Module: Update to Platform 2.7.x and Support Java 21
1 parent e46114e commit 650826e

File tree

7 files changed

+131
-122
lines changed

7 files changed

+131
-122
lines changed

api/src/main/java/org/openmrs/module/queue/tasks/AutoCloseVisitQueueEntryTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected List<QueueEntry> getActiveVisitQueueEntries() {
7878

7979
/**
8080
* @param queueEntry the QueueEntry to save
81-
*/
81+
*/
8282
protected void saveQueueEntry(QueueEntry queueEntry) {
8383
Context.getService(QueueEntryService.class).saveQueueEntry(queueEntry);
8484
}

omod/src/test/java/org/openmrs/module/queue/web/QueueEntryMetricRestControllerTest.java

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
import static org.hamcrest.Matchers.equalTo;
1515
import static org.hamcrest.Matchers.hasSize;
1616
import static org.mockito.ArgumentMatchers.any;
17+
import static org.mockito.Mockito.lenient;
18+
import static org.mockito.Mockito.mock;
19+
import static org.mockito.Mockito.mockStatic;
1720
import static org.mockito.Mockito.verify;
21+
import static org.mockito.Mockito.when;
1822
import static org.openmrs.module.queue.web.QueueEntryMetricRestController.COUNT;
1923
import static org.openmrs.module.queue.web.resources.parser.QueueEntrySearchCriteriaParser.SEARCH_PARAM_STATUS;
20-
import static org.powermock.api.mockito.PowerMockito.mock;
21-
import static org.powermock.api.mockito.PowerMockito.mockStatic;
22-
import static org.powermock.api.mockito.PowerMockito.when;
2324

2425
import javax.servlet.http.HttpServletRequest;
2526

@@ -29,11 +30,14 @@
2930
import java.util.List;
3031
import java.util.Map;
3132

32-
import org.junit.Before;
33-
import org.junit.Test;
34-
import org.junit.runner.RunWith;
33+
import org.junit.jupiter.api.AfterEach;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.extension.ExtendWith;
3537
import org.mockito.ArgumentCaptor;
3638
import org.mockito.Mock;
39+
import org.mockito.MockedStatic;
40+
import org.mockito.junit.jupiter.MockitoExtension;
3741
import org.openmrs.Concept;
3842
import org.openmrs.api.ConceptService;
3943
import org.openmrs.api.LocationService;
@@ -48,11 +52,8 @@
4852
import org.openmrs.module.queue.web.resources.parser.QueueEntrySearchCriteriaParser;
4953
import org.openmrs.module.webservices.rest.SimpleObject;
5054
import org.openmrs.module.webservices.rest.web.RestUtil;
51-
import org.powermock.core.classloader.annotations.PrepareForTest;
52-
import org.powermock.modules.junit4.PowerMockRunner;
5355

54-
@RunWith(PowerMockRunner.class)
55-
@PrepareForTest({ Context.class, RestUtil.class })
56+
@ExtendWith(MockitoExtension.class)
5657
public class QueueEntryMetricRestControllerTest {
5758

5859
private QueueEntryMetricRestController controller;
@@ -81,32 +82,36 @@ public class QueueEntryMetricRestControllerTest {
8182
@Mock
8283
private QueueServicesWrapper queueServicesWrapper;
8384

85+
private MockedStatic<RestUtil> restUtil;
86+
87+
private MockedStatic<Context> context;
88+
8489
HttpServletRequest request;
8590

8691
Map<String, String[]> parameterMap;
8792

8893
ArgumentCaptor<QueueEntrySearchCriteria> queueEntryArgumentCaptor;
8994

90-
@Before
95+
@BeforeEach
9196
public void prepareMocks() {
92-
mockStatic(RestUtil.class);
93-
mockStatic(Context.class);
94-
when(queueServicesWrapper.getQueueService()).thenReturn(queueService);
95-
when(queueServicesWrapper.getQueueEntryService()).thenReturn(queueEntryService);
96-
when(queueServicesWrapper.getQueueRoomService()).thenReturn(queueRoomService);
97-
when(queueServicesWrapper.getRoomProviderMapService()).thenReturn(roomProviderMapService);
98-
when(queueServicesWrapper.getConceptService()).thenReturn(conceptService);
99-
when(queueServicesWrapper.getLocationService()).thenReturn(locationService);
100-
when(queueServicesWrapper.getPatientService()).thenReturn(patientService);
97+
restUtil = mockStatic(RestUtil.class);
98+
context = mockStatic(Context.class);
99+
lenient().when(queueServicesWrapper.getQueueService()).thenReturn(queueService);
100+
lenient().when(queueServicesWrapper.getQueueEntryService()).thenReturn(queueEntryService);
101+
lenient().when(queueServicesWrapper.getQueueRoomService()).thenReturn(queueRoomService);
102+
lenient().when(queueServicesWrapper.getRoomProviderMapService()).thenReturn(roomProviderMapService);
103+
lenient().when(queueServicesWrapper.getConceptService()).thenReturn(conceptService);
104+
lenient().when(queueServicesWrapper.getLocationService()).thenReturn(locationService);
105+
lenient().when(queueServicesWrapper.getPatientService()).thenReturn(patientService);
101106

102107
//By pass authentication
103-
when(Context.isAuthenticated()).thenReturn(true);
108+
context.when(Context::isAuthenticated).thenReturn(true);
104109

105110
QueueEntrySearchCriteriaParser searchCriteriaParser = new QueueEntrySearchCriteriaParser(queueServicesWrapper);
106-
when(Context.getRegisteredComponents(QueueEntrySearchCriteriaParser.class))
111+
context.when(() -> Context.getRegisteredComponents(QueueEntrySearchCriteriaParser.class))
107112
.thenReturn(Collections.singletonList(searchCriteriaParser));
108113

109-
when(Context.getRegisteredComponents(QueueServicesWrapper.class))
114+
context.when(() -> Context.getRegisteredComponents(QueueServicesWrapper.class))
110115
.thenReturn(Collections.singletonList(queueServicesWrapper));
111116

112117
controller = new QueueEntryMetricRestController(searchCriteriaParser, queueServicesWrapper);
@@ -118,6 +123,12 @@ public void prepareMocks() {
118123
when(queueEntryService.getCountOfQueueEntries(any())).thenReturn(50L);
119124
}
120125

126+
@AfterEach
127+
public void cleanup() {
128+
restUtil.close();
129+
context.close();
130+
}
131+
121132
@Test
122133
public void shouldRetrieveCountOfQueueEntriesByStatus() {
123134
List<Concept> vals = Arrays.asList(new Concept(), new Concept());

omod/src/test/java/org/openmrs/module/queue/web/resources/BaseQueueResourceTest.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@
1313
import static org.hamcrest.Matchers.contains;
1414
import static org.hamcrest.Matchers.hasKey;
1515
import static org.hamcrest.Matchers.notNullValue;
16-
import static org.mockito.Mockito.when;
16+
import static org.mockito.Mockito.mockStatic;
1717

1818
import lombok.AccessLevel;
1919
import lombok.Getter;
2020
import lombok.Setter;
21-
import org.junit.Before;
21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.mockito.MockedStatic;
2224
import org.openmrs.OpenmrsObject;
2325
import org.openmrs.api.context.Context;
2426
import org.openmrs.module.webservices.rest.web.RestUtil;
2527
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
2628
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
2729
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
2830
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler;
29-
import org.powermock.api.mockito.PowerMockito;
30-
import org.powermock.core.classloader.annotations.PrepareForTest;
3131

3232
@Getter(AccessLevel.PACKAGE)
3333
@Setter(AccessLevel.PACKAGE)
34-
@PrepareForTest({ Context.class, RestUtil.class })
3534
public class BaseQueueResourceTest<Q extends OpenmrsObject, O extends DelegatingResourceHandler<Q>> {
3635

3736
private O resource;
@@ -40,13 +39,26 @@ public class BaseQueueResourceTest<Q extends OpenmrsObject, O extends Delegating
4039
@Setter(AccessLevel.PACKAGE)
4140
private Q object;
4241

43-
@Before
42+
@Getter(AccessLevel.PACKAGE)
43+
@Setter(AccessLevel.PACKAGE)
44+
private MockedStatic<RestUtil> restUtil;
45+
46+
@Getter(AccessLevel.PACKAGE)
47+
@Setter(AccessLevel.PACKAGE)
48+
private MockedStatic<Context> context;
49+
50+
@BeforeEach
4451
public void prepareMocks() {
45-
PowerMockito.mockStatic(RestUtil.class);
46-
47-
PowerMockito.mockStatic(Context.class);
52+
restUtil = mockStatic(RestUtil.class);
53+
context = mockStatic(Context.class);
4854
//By pass authentication
49-
when(Context.isAuthenticated()).thenReturn(true);
55+
context.when(Context::isAuthenticated).thenReturn(true);
56+
}
57+
58+
@AfterEach
59+
public void cleanup() {
60+
restUtil.close();
61+
context.close();
5062
}
5163

5264
public void verifyDefaultRepresentation(String... properties) {

omod/src/test/java/org/openmrs/module/queue/web/resources/QueueEntryResourceTest.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
import static org.hamcrest.Matchers.is;
1717
import static org.hamcrest.Matchers.notNullValue;
1818
import static org.hamcrest.Matchers.nullValue;
19+
import static org.mockito.Mockito.lenient;
20+
import static org.mockito.Mockito.mock;
21+
import static org.mockito.Mockito.mockStatic;
1922
import static org.mockito.Mockito.verify;
23+
import static org.mockito.Mockito.when;
2024
import static org.openmrs.module.queue.web.resources.parser.QueueEntrySearchCriteriaParser.SEARCH_PARAM_ENDED_ON_OR_AFTER;
2125
import static org.openmrs.module.queue.web.resources.parser.QueueEntrySearchCriteriaParser.SEARCH_PARAM_ENDED_ON_OR_BEFORE;
2226
import static org.openmrs.module.queue.web.resources.parser.QueueEntrySearchCriteriaParser.SEARCH_PARAM_HAS_VISIT;
@@ -34,9 +38,6 @@
3438
import static org.openmrs.module.queue.web.resources.parser.QueueEntrySearchCriteriaParser.SEARCH_PARAM_STARTED_ON_OR_BEFORE;
3539
import static org.openmrs.module.queue.web.resources.parser.QueueEntrySearchCriteriaParser.SEARCH_PARAM_STATUS;
3640
import static org.openmrs.module.queue.web.resources.parser.QueueEntrySearchCriteriaParser.SEARCH_PARAM_VISIT;
37-
import static org.powermock.api.mockito.PowerMockito.mock;
38-
import static org.powermock.api.mockito.PowerMockito.mockStatic;
39-
import static org.powermock.api.mockito.PowerMockito.when;
4041

4142
import javax.servlet.http.HttpServletRequest;
4243

@@ -47,11 +48,12 @@
4748
import java.util.Map;
4849
import java.util.Optional;
4950

50-
import org.junit.Before;
51-
import org.junit.Test;
52-
import org.junit.runner.RunWith;
51+
import org.junit.jupiter.api.BeforeEach;
52+
import org.junit.jupiter.api.Test;
53+
import org.junit.jupiter.api.extension.ExtendWith;
5354
import org.mockito.ArgumentCaptor;
5455
import org.mockito.Mock;
56+
import org.mockito.junit.jupiter.MockitoExtension;
5557
import org.openmrs.Concept;
5658
import org.openmrs.Location;
5759
import org.openmrs.Patient;
@@ -77,11 +79,8 @@
7779
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
7880
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
7981
import org.openmrs.module.webservices.rest.web.representation.RefRepresentation;
80-
import org.powermock.core.classloader.annotations.PrepareForTest;
81-
import org.powermock.modules.junit4.PowerMockRunner;
8282

83-
@RunWith(PowerMockRunner.class)
84-
@PrepareForTest({ Context.class, RestUtil.class })
83+
@ExtendWith(MockitoExtension.class)
8584
public class QueueEntryResourceTest extends BaseQueueResourceTest<QueueEntry, QueueEntryResource> {
8685

8786
private static final String QUEUE_ENTRY_UUID = "6hje567a-fca0-11e5-9e59-08002719a7";
@@ -122,26 +121,26 @@ public class QueueEntryResourceTest extends BaseQueueResourceTest<QueueEntry, Qu
122121

123122
ArgumentCaptor<QueueEntrySearchCriteria> queueEntryArgumentCaptor;
124123

125-
@Before
124+
@BeforeEach
126125
public void prepareMocks() {
127-
mockStatic(RestUtil.class);
128-
mockStatic(Context.class);
129-
when(queueServicesWrapper.getQueueService()).thenReturn(queueService);
130-
when(queueServicesWrapper.getQueueEntryService()).thenReturn(queueEntryService);
131-
when(queueServicesWrapper.getQueueRoomService()).thenReturn(queueRoomService);
132-
when(queueServicesWrapper.getRoomProviderMapService()).thenReturn(roomProviderMapService);
133-
when(queueServicesWrapper.getConceptService()).thenReturn(conceptService);
134-
when(queueServicesWrapper.getLocationService()).thenReturn(locationService);
135-
when(queueServicesWrapper.getPatientService()).thenReturn(patientService);
126+
setRestUtil(mockStatic(RestUtil.class));
127+
setContext(mockStatic(Context.class));
128+
lenient().when(queueServicesWrapper.getQueueService()).thenReturn(queueService);
129+
lenient().when(queueServicesWrapper.getQueueEntryService()).thenReturn(queueEntryService);
130+
lenient().when(queueServicesWrapper.getQueueRoomService()).thenReturn(queueRoomService);
131+
lenient().when(queueServicesWrapper.getRoomProviderMapService()).thenReturn(roomProviderMapService);
132+
lenient().when(queueServicesWrapper.getConceptService()).thenReturn(conceptService);
133+
lenient().when(queueServicesWrapper.getLocationService()).thenReturn(locationService);
134+
lenient().when(queueServicesWrapper.getPatientService()).thenReturn(patientService);
136135

137136
//By pass authentication
138-
when(Context.isAuthenticated()).thenReturn(true);
137+
getContext().when(Context::isAuthenticated).thenReturn(true);
139138

140-
when(Context.getRegisteredComponents(QueueServicesWrapper.class))
139+
getContext().when(() -> Context.getRegisteredComponents(QueueServicesWrapper.class))
141140
.thenReturn(Collections.singletonList(queueServicesWrapper));
142141

143142
QueueEntrySearchCriteriaParser searchCriteriaParser = new QueueEntrySearchCriteriaParser(queueServicesWrapper);
144-
when(Context.getRegisteredComponents(QueueEntrySearchCriteriaParser.class))
143+
getContext().when(() -> Context.getRegisteredComponents(QueueEntrySearchCriteriaParser.class))
145144
.thenReturn(Collections.singletonList(searchCriteriaParser));
146145

147146
resource = new QueueEntryResource();
@@ -152,9 +151,9 @@ public void prepareMocks() {
152151

153152
requestContext = mock(RequestContext.class);
154153
request = mock(HttpServletRequest.class);
155-
when(requestContext.getRequest()).thenReturn(request);
154+
lenient().when(requestContext.getRequest()).thenReturn(request);
156155
parameterMap = new HashMap<>();
157-
when(request.getParameterMap()).thenReturn(parameterMap);
156+
lenient().when(request.getParameterMap()).thenReturn(parameterMap);
158157
queueEntryArgumentCaptor = ArgumentCaptor.forClass(QueueEntrySearchCriteria.class);
159158
}
160159

omod/src/test/java/org/openmrs/module/queue/web/resources/QueueEntrySubResourceTest.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
import static org.hamcrest.Matchers.is;
1414
import static org.hamcrest.Matchers.notNullValue;
1515
import static org.hamcrest.Matchers.nullValue;
16-
import static org.powermock.api.mockito.PowerMockito.mock;
17-
import static org.powermock.api.mockito.PowerMockito.when;
16+
import static org.mockito.Mockito.lenient;
17+
import static org.mockito.Mockito.mock;
18+
import static org.mockito.Mockito.when;
1819

1920
import java.util.Collections;
2021
import java.util.Optional;
2122

22-
import org.junit.Before;
23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
2526
import org.mockito.Mock;
27+
import org.mockito.junit.jupiter.MockitoExtension;
2628
import org.openmrs.api.ConceptService;
2729
import org.openmrs.api.LocationService;
2830
import org.openmrs.api.PatientService;
@@ -37,9 +39,8 @@
3739
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
3840
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
3941
import org.openmrs.module.webservices.rest.web.representation.RefRepresentation;
40-
import org.powermock.modules.junit4.PowerMockRunner;
4142

42-
@RunWith(PowerMockRunner.class)
43+
@ExtendWith(MockitoExtension.class)
4344
public class QueueEntrySubResourceTest extends BaseQueueResourceTest<QueueEntry, QueueEntrySubResource> {
4445

4546
private static final String QUEUE_ENTRY_UUID = "6hje567a-fca0-11e5-9e59-08002719a7";
@@ -70,20 +71,21 @@ public class QueueEntrySubResourceTest extends BaseQueueResourceTest<QueueEntry,
7071

7172
private QueueEntry queueEntry;
7273

73-
@Before
74+
@BeforeEach
7475
public void setup() {
76+
this.cleanup();
7577
this.prepareMocks();
7678
queueEntry = mock(QueueEntry.class);
77-
when(queueServicesWrapper.getQueueService()).thenReturn(queueService);
78-
when(queueServicesWrapper.getQueueEntryService()).thenReturn(queueEntryService);
79-
when(queueServicesWrapper.getQueueRoomService()).thenReturn(queueRoomService);
80-
when(queueServicesWrapper.getRoomProviderMapService()).thenReturn(roomProviderMapService);
81-
when(queueServicesWrapper.getConceptService()).thenReturn(conceptService);
82-
when(queueServicesWrapper.getLocationService()).thenReturn(locationService);
83-
when(queueServicesWrapper.getPatientService()).thenReturn(patientService);
79+
lenient().when(queueServicesWrapper.getQueueService()).thenReturn(queueService);
80+
lenient().when(queueServicesWrapper.getQueueEntryService()).thenReturn(queueEntryService);
81+
lenient().when(queueServicesWrapper.getQueueRoomService()).thenReturn(queueRoomService);
82+
lenient().when(queueServicesWrapper.getRoomProviderMapService()).thenReturn(roomProviderMapService);
83+
lenient().when(queueServicesWrapper.getConceptService()).thenReturn(conceptService);
84+
lenient().when(queueServicesWrapper.getLocationService()).thenReturn(locationService);
85+
lenient().when(queueServicesWrapper.getPatientService()).thenReturn(patientService);
8486

85-
when(queueEntry.getUuid()).thenReturn(QUEUE_ENTRY_UUID);
86-
when(Context.getRegisteredComponents(QueueServicesWrapper.class))
87+
lenient().when(queueEntry.getUuid()).thenReturn(QUEUE_ENTRY_UUID);
88+
getContext().when(() -> Context.getRegisteredComponents(QueueServicesWrapper.class))
8789
.thenReturn(Collections.singletonList(queueServicesWrapper));
8890

8991
this.setResource(new QueueEntrySubResource());

0 commit comments

Comments
 (0)