Skip to content

Commit c93e9e6

Browse files
committed
Fix RetryOperationsInterceptorTests extract MethodInvocation and simplify mocking
Signed-off-by: Kim Jun Hyeong <ggprgrkjh@naver.com>
1 parent 85ba0dd commit c93e9e6

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

src/test/java/org/springframework/retry/interceptor/RetryOperationsInterceptorTests.java

+10-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,6 +49,9 @@
4949
import static org.assertj.core.api.Assertions.assertThat;
5050
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
5151
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;
5255

5356
/**
5457
* @author Dave Syer
@@ -287,39 +290,17 @@ public void testProxyAttributeRemainWithWrongKey() {
287290
}
288291

289292
@Test
290-
public void testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown() {
293+
public void testProxyAttributeCleanupEvenWhenIllegalStateExceptionThrown() throws NoSuchMethodException {
291294
RetryContext context = new RetryContextSupport(null);
292295
Object mockProxy = new Object();
293296
RetrySynchronizationManager.register(context);
294297
context.setAttribute("___proxy___", mockProxy);
295298
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");
323304
assertThat(context.getAttribute("___proxy___")).isNull();
324305
RetrySynchronizationManager.clear();
325306
}

0 commit comments

Comments
 (0)