diff --git a/activemq-unit-tests/pom.xml b/activemq-unit-tests/pom.xml index 8e690a92ed..28ec67c253 100644 --- a/activemq-unit-tests/pom.xml +++ b/activemq-unit-tests/pom.xml @@ -302,27 +302,7 @@ org.mockito - mockito-core - test - - - org.powermock - powermock-core - test - - - org.powermock - powermock-module-junit4 - test - - - org.powermock - powermock-api-mockito - test - - - org.powermock - powermock-api-mockito-common + mockito-inline test diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java index 810a6ea9b3..bbf1c9f84a 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java @@ -22,22 +22,19 @@ import org.apache.activemq.network.NetworkConnector; import org.apache.activemq.store.PersistenceAdapter; import org.apache.activemq.util.LargeFile; import org.apache.activemq.util.StoreUtil; -import org.junit.runner.RunWith; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.verifyStatic; -import static org.powermock.api.mockito.PowerMockito.when; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - +import org.junit.Test; +import org.mockito.MockedStatic; import junit.framework.TestCase; +import org.mockito.Mockito; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; /** * Tests for the BrokerService class * * @author chirino */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(StoreUtil.class) public class BrokerServiceTest extends TestCase { public void testAddRemoveTransportsWithJMX() throws Exception { BrokerService service = new BrokerService(); @@ -94,6 +91,7 @@ public class BrokerServiceTest extends TestCase { assertEquals( 1024L * 1024 * 1024 * 100, service.getSystemUsage().getStoreUsage().getLimit() ); } + @Test public void testLargeFileSystem() throws Exception { BrokerService service = new BrokerService(); @@ -105,29 +103,30 @@ public class BrokerServiceTest extends TestCase { service.setPersistenceAdapter(persistenceAdapter); service.setUseJmx(false); - mockStatic(StoreUtil.class); + try(MockedStatic mocked = Mockito.mockStatic(StoreUtil.class)) { + // Return a simulated handle to a very large file system that will return a negative totalSpace. + mocked.when(() -> StoreUtil.findParentDirectory(dataDirectory)).thenReturn(new LargeFile(dataDirectory.getParentFile(), "KahaDB")); + mocked.when(() -> StoreUtil.findParentDirectory(tmpDataDirectory)).thenReturn(tmpDataDirectory.getParentFile()); - // Return a simulated handle to a very large file system that will return a negative totalSpace. - when(StoreUtil.findParentDirectory(dataDirectory)).thenReturn(new LargeFile(dataDirectory.getParentFile(), "KahaDB")); - when(StoreUtil.findParentDirectory(tmpDataDirectory)).thenReturn(tmpDataDirectory.getParentFile()); + try { + service.start(); + fail("Expect error on negative totalspace"); + } catch (Exception expected) { + // verify message + assertTrue(expected.getLocalizedMessage().contains("negative")); + } + finally { + service.stop(); + } - try { - service.start(); - fail("Expect error on negative totalspace"); - } catch (Exception expected) { - // verify message - assertTrue(expected.getLocalizedMessage().contains("negative")); - } - finally { + // configure a 2x value for the fs limit so it can start + service.getSystemUsage().getStoreUsage().setTotal( service.getSystemUsage().getStoreUsage().getLimit() * 2); + + service.start(true); service.stop(); + + mocked.verify(() -> StoreUtil.findParentDirectory(any()), times(3)); } - // configure a 2x value for the fs limit so it can start - service.getSystemUsage().getStoreUsage().setTotal( service.getSystemUsage().getStoreUsage().getLimit() * 2); - - service.start(true); - service.stop(); - - verifyStatic(); } } diff --git a/pom.xml b/pom.xml index b8a3736e2d..268aebdf60 100644 --- a/pom.xml +++ b/pom.xml @@ -85,7 +85,6 @@ 1.2.17 3.8.0 5.2.4 - 1.7.4 1.16 10.14.2.0 6.0.0 @@ -943,27 +942,9 @@ test - org.powermock - powermock-core - ${powermock-version} - test - - - org.powermock - powermock-module-junit4 - ${powermock-version} - test - - - org.powermock - powermock-api-mockito - ${powermock-version} - test - - - org.powermock - powermock-api-mockito-common - ${powermock-version} + org.mockito + mockito-inline + ${mockito-version} test