|
1 | 1 | /* |
2 | | - * Copyright 2006-2023 the original author or authors. |
| 2 | + * Copyright 2006-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
49 | 49 | import static org.assertj.core.api.Assertions.assertThat; |
50 | 50 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
51 | 51 | import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
| 52 | +import static org.mockito.Mockito.mock; |
| 53 | +import static org.mockito.Mockito.when; |
52 | 54 |
|
53 | 55 | /** |
54 | 56 | * @author Dave Syer |
@@ -287,39 +289,17 @@ public void testProxyAttributeRemainWithWrongKey() { |
287 | 289 | } |
288 | 290 |
|
289 | 291 | @Test |
290 | | - public void testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown() { |
| 292 | + public void testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown() throws NoSuchMethodException { |
291 | 293 | RetryContext context = new RetryContextSupport(null); |
292 | 294 | Object mockProxy = new Object(); |
293 | 295 | RetrySynchronizationManager.register(context); |
294 | 296 | context.setAttribute("___proxy___", mockProxy); |
295 | 297 | assertThat(context.getAttribute("___proxy___")).isNotNull(); |
296 | | - assertThatIllegalStateException().isThrownBy(() -> this.interceptor.invoke(new MethodInvocation() { |
297 | | - @Override |
298 | | - public Method getMethod() { |
299 | | - return ClassUtils.getMethod(RetryOperationsInterceptorTests.class, |
300 | | - "testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown"); |
301 | | - } |
302 | | - |
303 | | - @Override |
304 | | - public Object[] getArguments() { |
305 | | - return new Object[0]; |
306 | | - } |
307 | | - |
308 | | - @Override |
309 | | - public Object proceed() { |
310 | | - return null; |
311 | | - } |
312 | | - |
313 | | - @Override |
314 | | - public Object getThis() { |
315 | | - return new Object(); |
316 | | - } |
317 | | - |
318 | | - @Override |
319 | | - public AccessibleObject getStaticPart() { |
320 | | - return null; |
321 | | - } |
322 | | - })).withMessageContaining("MethodInvocation"); |
| 298 | + MethodInvocation mockInvocation = mock(MethodInvocation.class); |
| 299 | + Method testMethod = this.getClass().getMethod("testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown"); |
| 300 | + when(mockInvocation.getMethod()).thenReturn(testMethod); |
| 301 | + assertThatIllegalStateException().isThrownBy(() -> this.interceptor.invoke(mockInvocation)) |
| 302 | + .withMessageContaining("MethodInvocation"); |
323 | 303 | assertThat(context.getAttribute("___proxy___")).isNull(); |
324 | 304 | RetrySynchronizationManager.clear(); |
325 | 305 | } |
|
0 commit comments