Skip to content

Commit 630d610

Browse files
committed
Fix BasePathAwareHandlerMappingUnitTests.
Fixes GH-2338.
1 parent ec0e25e commit 630d610

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BasePathAwareHandlerMappingUnitTests.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.jupiter.api.Test;
2525
import org.springframework.aop.framework.ProxyFactory;
2626
import org.springframework.aop.support.AopUtils;
27+
import org.springframework.context.support.StaticApplicationContext;
2728
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
2829
import org.springframework.stereotype.Controller;
2930
import org.springframework.util.ReflectionUtils;
@@ -45,7 +46,7 @@ void setUp() {
4546

4647
doReturn(URI.create("")).when(configuration).getBasePath();
4748

48-
mapping = new HandlerMappingStub(configuration);
49+
mapping = getHandlerMappingStub(configuration);
4950
}
5051

5152
@Test // DATAREST-1132
@@ -85,7 +86,7 @@ void doesNotRejectAtRequestMappingOnStandardMvcController() {
8586
void combinesBasePathAndControllerPrefixesCorrectly() throws Exception {
8687

8788
doReturn(URI.create("/base")).when(configuration).getBasePath();
88-
mapping = new HandlerMappingStub(configuration);
89+
mapping = getHandlerMappingStub(configuration);
8990

9091
var method = ReflectionUtils.findMethod(PrefixedController.class, "someMethod");
9192
var info = mapping.getMappingForMethod(method, PrefixedController.class);
@@ -105,6 +106,15 @@ private static Class<?> createProxy(Object source) {
105106
return proxy.getClass();
106107
}
107108

109+
private static HandlerMappingStub getHandlerMappingStub(RepositoryRestConfiguration configuration) {
110+
111+
HandlerMappingStub mapping = new HandlerMappingStub(configuration);
112+
mapping.setApplicationContext(new StaticApplicationContext());
113+
mapping.afterPropertiesSet();
114+
115+
return mapping;
116+
}
117+
108118
@BasePathAwareController
109119
static class SomeController {}
110120

0 commit comments

Comments
 (0)