diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java index e6fecf622e6..6a8b9616c9d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java @@ -145,7 +145,8 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC protected boolean isInternalLanguageInterface(Class ifc) { return (ifc.getName().equals("groovy.lang.GroovyObject") || ifc.getName().endsWith(".cglib.proxy.Factory") || - ifc.getName().endsWith(".bytebuddy.MockAccess")); + ifc.getName().endsWith(".bytebuddy.MockAccess") || // Mockito < 5.16.1 + ifc.getName().endsWith(".bytebuddy.access.MockAccess")); // Mockito >= 5.16.1 } } diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/ProxyProcessorSupportTests.java b/spring-aop/src/test/java/org/springframework/aop/framework/ProxyProcessorSupportTests.java new file mode 100644 index 00000000000..be05158cb8f --- /dev/null +++ b/spring-aop/src/test/java/org/springframework/aop/framework/ProxyProcessorSupportTests.java @@ -0,0 +1,69 @@ +/* + * Copyright 2002-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.aop.framework; + +import java.util.Arrays; + +import org.junit.jupiter.api.Test; + +import org.springframework.cglib.proxy.Factory; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +/** + * Tests for {@link ProxyProcessorSupport}. + * + * @author Sam Brannen + * @since 7.0.10 + */ +class ProxyProcessorSupportTests { + + private final ProxyProcessorSupport proxyProcessorSupport = new ProxyProcessorSupport(); + + + @Test + void isInternalLanguageInterfaceForCglibProxyFactory() { + assertThat(proxyProcessorSupport.isInternalLanguageInterface(Factory.class)).isTrue(); + } + + @Test + void isInternalLanguageInterfaceForCurrentMockitoMockAccess() { + Class mockAccessInterface = Arrays.stream(mock(Runnable.class).getClass().getInterfaces()) + .filter(ifc -> ifc.getSimpleName().equals("MockAccess")) + .findFirst() + .orElseThrow(() -> new AssertionError("Mockito mock does not implement a MockAccess interface")); + + assertThat(mockAccessInterface.getName()).endsWith(".bytebuddy.access.MockAccess"); + assertThat(proxyProcessorSupport.isInternalLanguageInterface(mockAccessInterface)).isTrue(); + } + + @Test + void isInternalLanguageInterfaceForLegacyMockitoMockAccess() { + // Mockito relocated MockAccess in 5.16.1 from a "bytebuddy" package to a + // "bytebuddy.access" subpackage. This interface mimics the pre-5.16.1 + // location so that we can verify that both locations are supported. + assertThat(proxyProcessorSupport.isInternalLanguageInterface( + org.springframework.aop.framework.bytebuddy.MockAccess.class)).isTrue(); + } + + @Test + void isNotInternalLanguageInterface() { + assertThat(proxyProcessorSupport.isInternalLanguageInterface(Runnable.class)).isFalse(); + } + +} diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/bytebuddy/MockAccess.java b/spring-aop/src/test/java/org/springframework/aop/framework/bytebuddy/MockAccess.java new file mode 100644 index 00000000000..1ad364cce3e --- /dev/null +++ b/spring-aop/src/test/java/org/springframework/aop/framework/bytebuddy/MockAccess.java @@ -0,0 +1,26 @@ +/* + * Copyright 2002-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.aop.framework.bytebuddy; + +/** + * Stand-in for the {@code MockAccess} interface that Mockito generated + * mocks implemented prior to Mockito 5.16.1. + * + * @see org.springframework.aop.framework.ProxyProcessorSupportTests + */ +public interface MockAccess { +}