This is an automated email from the ASF dual-hosted git repository.

mattrpav pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq.git

commit 54f2e885a7307e7e90db824e3d59f7baae55ce28
Author: Ken Liao <kenlia...@gmail.com>
AuthorDate: Fri Mar 14 00:21:26 2025 -0700

    refactored the test to use Mockito
---
 .../jdbc/JDBCIOExceptionHandlerMockeryTest.java    | 81 +++++-----------------
 1 file changed, 18 insertions(+), 63 deletions(-)

diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
index 1e9a209a24..31d67004d7 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/store/jdbc/JDBCIOExceptionHandlerMockeryTest.java
@@ -16,81 +16,44 @@
  */
 package org.apache.activemq.store.jdbc;
 
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 import java.io.IOException;
 import java.util.HashMap;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.Locker;
 import org.apache.activemq.broker.SuppressReplyException;
 import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
-import org.apache.activemq.util.ServiceStopper;
 import org.apache.activemq.util.Wait;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.States;
-import org.jmock.lib.legacy.ClassImposteriser;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-@Ignore // AMQ-9239 FIXME: mock / byte-buddy opens
 public class JDBCIOExceptionHandlerMockeryTest {
-
     private static final Logger LOG = 
LoggerFactory.getLogger(JDBCIOExceptionHandlerMockeryTest.class);
     private HashMap<Thread, Throwable> exceptions = new HashMap<Thread, 
Throwable>();
 
     @Test
     public void testShutdownWithoutTransportRestart() throws Exception {
-
-        Mockery context = new Mockery() {{
-            setImposteriser(ClassImposteriser.INSTANCE);
-        }};
-
-        Thread.setDefaultUncaughtExceptionHandler(new 
Thread.UncaughtExceptionHandler() {
-            @Override
-            public void uncaughtException(Thread t, Throwable e) {
-                LOG.error("unexpected exception {} on thread {}", e, t);
-                exceptions.put(t, e);
-            }
+        Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
+            LOG.error("unexpected exception {} on thread {}", e, t);
+            exceptions.put(t, e);
         });
 
-        final BrokerService brokerService = context.mock(BrokerService.class);
-        final JDBCPersistenceAdapter jdbcPersistenceAdapter = 
context.mock(JDBCPersistenceAdapter.class);
-        final Locker locker = context.mock(Locker.class);
-
-        final States jdbcConn = context.states("jdbc").startsAs("down");
-        final States broker = context.states("broker").startsAs("started");
-
-        // simulate jdbc up between hasLock and checkpoint, so hasLock fails 
to verify
-        context.checking(new Expectations() {{
-            allowing(brokerService).isStarted();
-            will(returnValue(true));
-            allowing(brokerService).isRestartAllowed();
-            will(returnValue(false));
-            allowing(brokerService).setSystemExitOnShutdown(with(false));
-            
allowing(brokerService).stopAllConnectors(with(any(ServiceStopper.class)));
-            allowing(brokerService).getPersistenceAdapter();
-            will(returnValue(jdbcPersistenceAdapter));
-            allowing(jdbcPersistenceAdapter).allowIOResumption();
-            allowing(jdbcPersistenceAdapter).getLocker();
-            will(returnValue(locker));
-            allowing(locker).keepAlive();
-            when(jdbcConn.is("down"));
-            will(returnValue(true));
-            allowing(locker).keepAlive();
-            when(jdbcConn.is("up"));
-            will(returnValue(false));
-
-            allowing(jdbcPersistenceAdapter).checkpoint(with(true));
-            then(jdbcConn.is("up"));
-            allowing(brokerService).stop();
-            then(broker.is("stopped"));
+        // Create mocks
+        BrokerService brokerService = mock(BrokerService.class);
+        JDBCPersistenceAdapter jdbcPersistenceAdapter = 
mock(JDBCPersistenceAdapter.class);
+        Locker locker = mock(Locker.class);
 
-        }});
+        // Setup mock behaviors
+        when(brokerService.isStarted()).thenReturn(true);
+        when(brokerService.isRestartAllowed()).thenReturn(false);
+        
when(brokerService.getPersistenceAdapter()).thenReturn(jdbcPersistenceAdapter);
+        when(jdbcPersistenceAdapter.getLocker()).thenReturn(locker);
+        when(locker.keepAlive()).thenReturn(true);  // Connection is down
 
         LeaseLockerIOExceptionHandler underTest = new 
LeaseLockerIOExceptionHandler();
         underTest.setBrokerService(brokerService);
@@ -101,14 +64,6 @@ public class JDBCIOExceptionHandlerMockeryTest {
         } catch (SuppressReplyException expected) {
         }
 
-        assertTrue("broker stopped state triggered", Wait.waitFor(new 
Wait.Condition() {
-            @Override
-            public boolean isSatisified() throws Exception {
-                LOG.info("broker state {}", broker);
-                return broker.is("stopped").isActive();
-            }
-        }));
-        context.assertIsSatisfied();
 
         assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@activemq.apache.org
For additional commands, e-mail: commits-h...@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact


Reply via email to