|
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.assertj.core.api.Assertions.assertThatNullPointerException; |
| 53 | +import static org.mockito.Mockito.mock; |
| 54 | +import static org.mockito.Mockito.when; |
52 | 55 |
|
53 | 56 | /**
|
54 | 57 | * @author Dave Syer
|
@@ -287,39 +290,17 @@ public void testProxyAttributeRemainWithWrongKey() {
|
287 | 290 | }
|
288 | 291 |
|
289 | 292 | @Test
|
290 |
| - public void testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown() { |
| 293 | + public void testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown() throws NoSuchMethodException { |
291 | 294 | RetryContext context = new RetryContextSupport(null);
|
292 | 295 | Object mockProxy = new Object();
|
293 | 296 | RetrySynchronizationManager.register(context);
|
294 | 297 | context.setAttribute("___proxy___", mockProxy);
|
295 | 298 | 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"); |
| 299 | + MethodInvocation mockInvocation = mock(MethodInvocation.class); |
| 300 | + Method testMethod = this.getClass().getMethod("testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown"); |
| 301 | + when(mockInvocation.getMethod()).thenReturn(testMethod); |
| 302 | + assertThatIllegalStateException().isThrownBy(() -> this.interceptor.invoke(mockInvocation)) |
| 303 | + .withMessageContaining("MethodInvocation"); |
323 | 304 | assertThat(context.getAttribute("___proxy___")).isNull();
|
324 | 305 | RetrySynchronizationManager.clear();
|
325 | 306 | }
|
|
0 commit comments