From b074f61e77aa2f9662b974138f7235e1eeaa66c3 Mon Sep 17 00:00:00 2001 From: Ruhanga <41738040+Ruhanga@users.noreply.github.com> Date: Thu, 29 May 2025 17:09:05 +0300 Subject: [PATCH] LUI-200: Fixed failing tests across different JVM flavours (#215) --- omod/pom.xml | 14 ++++++++++++++ .../maintenance/SearchIndexControllerTest.java | 17 +++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) mode change 100644 => 100755 omod/pom.xml mode change 100644 => 100755 omod/src/test/java/org/openmrs/web/controller/maintenance/SearchIndexControllerTest.java diff --git a/omod/pom.xml b/omod/pom.xml old mode 100644 new mode 100755 index 57a5b88c..3cb70eba --- a/omod/pom.xml +++ b/omod/pom.xml @@ -90,6 +90,20 @@ openmrs-test pom test + + + org.mockito + mockito-core + + + org.powermock + powermock-module-junit4 + + + org.powermock + powermock-api-mockito2 + + diff --git a/omod/src/test/java/org/openmrs/web/controller/maintenance/SearchIndexControllerTest.java b/omod/src/test/java/org/openmrs/web/controller/maintenance/SearchIndexControllerTest.java old mode 100644 new mode 100755 index 0898d3af..86af392b --- a/omod/src/test/java/org/openmrs/web/controller/maintenance/SearchIndexControllerTest.java +++ b/omod/src/test/java/org/openmrs/web/controller/maintenance/SearchIndexControllerTest.java @@ -29,8 +29,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.doThrow; /** * Tests the {@link SearchIndexController} controller @@ -74,7 +75,7 @@ public void rebuildSearchIndex_shouldReturnTrueForSuccessIfTheUpdateDoesNotFail( when(userContext.isAuthenticated()).thenReturn(true); assertTrue(Context.getUserContext().isAuthenticated()); - Mockito.when(contextDao.updateSearchIndexAsync()).thenReturn(null); + when(contextDao.updateSearchIndexAsync()).thenReturn(null); Map response = controller.rebuildSearchIndex(); assertEquals(true, response.get("success")); } @@ -89,7 +90,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfARuntimeExceptionIsT when(userContext.isAuthenticated()).thenReturn(true); assertTrue(Context.getUserContext().isAuthenticated()); - Mockito.doThrow(new RuntimeException("boom")).when(contextDao).updateSearchIndexAsync(); + doThrow(new RuntimeException("boom")).when(contextDao).updateSearchIndexAsync(); Map response = controller.rebuildSearchIndex(); assertEquals(false, response.get("success")); } @@ -104,7 +105,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfAUnAuthenticatedUser when(userContext.isAuthenticated()).thenReturn(false); assertFalse(Context.getUserContext().isAuthenticated()); - Mockito.when(contextDao.updateSearchIndexAsync()).thenReturn(null); + when(contextDao.updateSearchIndexAsync()).thenReturn(null); Map response = controller.rebuildSearchIndex(); assertEquals(false, response.get("success")); } @@ -115,7 +116,7 @@ public void rebuildSearchIndex_shouldReturnFalseForSuccessIfAUnAuthenticatedUser */ @Test public void getStatus_shouldReturnInProgressForStatusIfRebuildSearchIndexIsInProgress() throws Exception { - Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer) invocationOnMock -> { + when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer) invocationOnMock -> { Future future = mock(FutureTask.class); when(future.isDone()).thenReturn(false); return future; @@ -131,7 +132,7 @@ public void getStatus_shouldReturnInProgressForStatusIfRebuildSearchIndexIsInPro */ @Test public void getStatus_shouldReturnSuccessForStatusIfRebuildSearchIndexIsCompletedSuccessfully() throws Exception { - Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer) invocationOnMock -> { + when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer) invocationOnMock -> { Future future = mock(FutureTask.class); when(future.isDone()).thenReturn(true); when(future.isCancelled()).thenReturn(false); @@ -148,7 +149,7 @@ public void getStatus_shouldReturnSuccessForStatusIfRebuildSearchIndexIsComplete */ @Test public void getStatus_shouldReturnErrorForStatusIfRebuildSearchIndexIsCompletedUnsuccessfully() throws Exception { - Mockito.when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer) invocationOnMock -> { + when(contextDao.updateSearchIndexAsync()).thenAnswer((Answer) invocationOnMock -> { Future future = mock(FutureTask.class); when(future.isDone()).thenReturn(true); when(future.isCancelled()).thenReturn(true);