Skip to content

Commit b074f61

Browse files
authored
LUI-200: Fixed failing tests across different JVM flavours (#215)
1 parent abe4f53 commit b074f61

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

omod/pom.xml

100644100755
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@
9090
<artifactId>openmrs-test</artifactId>
9191
<type>pom</type>
9292
<scope>test</scope>
93+
<exclusions>
94+
<exclusion>
95+
<groupId>org.mockito</groupId>
96+
<artifactId>mockito-core</artifactId>
97+
</exclusion>
98+
<exclusion>
99+
<groupId>org.powermock</groupId>
100+
<artifactId>powermock-module-junit4</artifactId>
101+
</exclusion>
102+
<exclusion>
103+
<groupId>org.powermock</groupId>
104+
<artifactId>powermock-api-mockito2</artifactId>
105+
</exclusion>
106+
</exclusions>
93107
</dependency>
94108

95109
<!-- End OpenMRS core -->

omod/src/test/java/org/openmrs/web/controller/maintenance/SearchIndexControllerTest.java

100644100755
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
import static org.junit.Assert.assertEquals;
3030
import static org.junit.Assert.assertFalse;
3131
import static org.junit.Assert.assertTrue;
32-
import static org.powermock.api.mockito.PowerMockito.mock;
33-
import static org.powermock.api.mockito.PowerMockito.when;
32+
import static org.mockito.Mockito.when;
33+
import static org.mockito.Mockito.mock;
34+
import static org.mockito.Mockito.doThrow;
3435

3536
/**
3637
* Tests the {@link SearchIndexController} controller
@@ -74,7 +75,7 @@ public void rebuildSearchIndex_shouldReturnTrueForSuccessIfTheUpdateDoesNotFail(
7475
when(userContext.isAuthenticated()).thenReturn(true);
7576
assertTrue(Context.getUserContext().isAuthenticated());
7677

77-
Mockito.when(contextDao.updateSearchIndexAsync()).thenReturn(null);
78+
when(contextDao.updateSearchIndexAsync()).thenReturn(null);
7879
Map<String, Object> response = controller.rebuildSearchIndex();
7980
assertEquals(true, response.get("success"));
8081
}
@@ -89,7 +90,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfARuntimeExceptionIsT
8990
when(userContext.isAuthenticated()).thenReturn(true);
9091
assertTrue(Context.getUserContext().isAuthenticated());
9192

92-
Mockito.doThrow(new RuntimeException("boom")).when(contextDao).updateSearchIndexAsync();
93+
doThrow(new RuntimeException("boom")).when(contextDao).updateSearchIndexAsync();
9394
Map<String, Object> response = controller.rebuildSearchIndex();
9495
assertEquals(false, response.get("success"));
9596
}
@@ -104,7 +105,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfAUnAuthenticatedUser
104105
when(userContext.isAuthenticated()).thenReturn(false);
105106
assertFalse(Context.getUserContext().isAuthenticated());
106107

107-
Mockito.when(contextDao.updateSearchIndexAsync()).thenReturn(null);
108+
when(contextDao.updateSearchIndexAsync()).thenReturn(null);
108109
Map<String, Object> response = controller.rebuildSearchIndex();
109110
assertEquals(false, response.get("success"));
110111
}
@@ -115,7 +116,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfAUnAuthenticatedUser
115116
*/
116117
@Test
117118
public void getStatus_shouldReturnInProgressForStatusIfRebuildSearchIndexIsInProgress() throws Exception {
118-
Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
119+
when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
119120
Future<String> future = mock(FutureTask.class);
120121
when(future.isDone()).thenReturn(false);
121122
return future;
@@ -131,7 +132,7 @@ public void getStatus_shouldReturnInProgressForStatusIfRebuildSearchIndexIsInPro
131132
*/
132133
@Test
133134
public void getStatus_shouldReturnSuccessForStatusIfRebuildSearchIndexIsCompletedSuccessfully() throws Exception {
134-
Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
135+
when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
135136
Future<String> future = mock(FutureTask.class);
136137
when(future.isDone()).thenReturn(true);
137138
when(future.isCancelled()).thenReturn(false);
@@ -148,7 +149,7 @@ public void getStatus_shouldReturnSuccessForStatusIfRebuildSearchIndexIsComplete
148149
*/
149150
@Test
150151
public void getStatus_shouldReturnErrorForStatusIfRebuildSearchIndexIsCompletedUnsuccessfully() throws Exception {
151-
Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
152+
when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer<Future>) invocationOnMock -> {
152153
Future<String> future = mock(FutureTask.class);
153154
when(future.isDone()).thenReturn(true);
154155
when(future.isCancelled()).thenReturn(true);

0 commit comments

Comments
 (0)