test:update RejectedProxyInvocationHandlerTest

pull/1199/head
z-y-hang 2 years ago
commit 4cd446f21b

@ -26,13 +26,14 @@ public class RejectedProxyInvocationHandlerTest {
@Mock @Mock
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Mock
private Object target;
@Mock @Mock
private Method mockMethod; private Method mockMethod;
private RejectedProxyInvocationHandler handler; private RejectedProxyInvocationHandler handler;
@Before @Before
public void setUp() { public void setUp() {
Object target = new Object();
String threadPoolId = "test-pool"; String threadPoolId = "test-pool";
AtomicLong rejectCount = new AtomicLong(0); AtomicLong rejectCount = new AtomicLong(0);
handler = new RejectedProxyInvocationHandler(target, threadPoolId, rejectCount); handler = new RejectedProxyInvocationHandler(target, threadPoolId, rejectCount);
@ -40,7 +41,6 @@ public class RejectedProxyInvocationHandlerTest {
@Test @Test
public void testInvoke() throws Throwable { public void testInvoke() throws Throwable {
Object[] mockArgs = new Object[] {"arg1", "arg2"}; Object[] mockArgs = new Object[] {"arg1", "arg2"};
MockedStatic<ApplicationContextHolder> mockedStatic = Mockito.mockStatic(ApplicationContextHolder.class); MockedStatic<ApplicationContextHolder> mockedStatic = Mockito.mockStatic(ApplicationContextHolder.class);
mockedStatic.when(ApplicationContextHolder::getInstance).thenReturn(applicationContext); mockedStatic.when(ApplicationContextHolder::getInstance).thenReturn(applicationContext);
@ -48,11 +48,7 @@ public class RejectedProxyInvocationHandlerTest {
Mockito.doNothing().when(mockAlarmHandler).asyncSendRejectedAlarm("test-pool"); Mockito.doNothing().when(mockAlarmHandler).asyncSendRejectedAlarm("test-pool");
handler.invoke(null, mockMethod, mockArgs); handler.invoke(null, mockMethod, mockArgs);
Mockito.when(mockMethod.invoke(new Object(), mockArgs)).thenThrow(new IllegalAccessException()); Mockito.doThrow(new InvocationTargetException(new Throwable())).when(mockMethod).invoke(target, mockArgs);
try { Assertions.assertThrows(Throwable.class, () -> handler.invoke(null, mockMethod, mockArgs));
handler.invoke(null, mockMethod, mockArgs);
} catch (Exception ex){
Assertions.assertTrue(ex instanceof InvocationTargetException);
}
} }
} }

Loading…
Cancel
Save