Add tests to DelegatingWebReactiveConfigurationTests
This commit is contained in:
@@ -139,7 +139,7 @@ public class WebReactiveConfigurerComposite implements WebReactiveConfigurer {
|
||||
return Optional.empty();
|
||||
}
|
||||
else if (result.size() == 1) {
|
||||
return result.get(1);
|
||||
return result.get(0);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("More than one WebReactiveConfigurer implements " +
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.springframework.web.reactive.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -36,6 +39,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter;
|
||||
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
@@ -43,7 +47,9 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link DelegatingWebReactiveConfiguration} tests.
|
||||
@@ -66,6 +72,9 @@ public class DelegatingWebReactiveConfigurationTests {
|
||||
@Captor
|
||||
private ArgumentCaptor<FormatterRegistry> formatterRegistry;
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -78,6 +87,52 @@ public class DelegatingWebReactiveConfigurationTests {
|
||||
given(webReactiveConfigurer.getMessageCodesResolver()).willReturn(Optional.empty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerMapping() throws Exception {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webReactiveConfigurer));
|
||||
delegatingConfig.requestMappingHandlerMapping();
|
||||
|
||||
verify(webReactiveConfigurer).createRequestMappingHandlerMapping();
|
||||
verify(webReactiveConfigurer).configureRequestedContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
|
||||
verify(webReactiveConfigurer).addCorsMappings(any(CorsRegistry.class));
|
||||
verify(webReactiveConfigurer).configurePathMatching(any(PathMatchConfigurer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerMappingFactoryMethod() throws Exception {
|
||||
RequestMappingHandlerMapping mapping = new RequestMappingHandlerMapping();
|
||||
|
||||
WebReactiveConfigurer configurer1 = mock(WebReactiveConfigurer.class);
|
||||
WebReactiveConfigurer configurer2 = mock(WebReactiveConfigurer.class);
|
||||
|
||||
when(configurer1.createRequestMappingHandlerMapping()).thenReturn(Optional.of(mapping));
|
||||
when(configurer2.createRequestMappingHandlerMapping()).thenReturn(Optional.empty());
|
||||
|
||||
delegatingConfig.setConfigurers(Arrays.asList(configurer1, configurer2));
|
||||
Object actual = delegatingConfig.createRequestMappingHandlerMapping();
|
||||
|
||||
assertSame(mapping, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleRequestMappingHandlerMappingFactoryMethods() throws Exception {
|
||||
RequestMappingHandlerMapping mapping1 = new RequestMappingHandlerMapping();
|
||||
RequestMappingHandlerMapping mapping2 = new RequestMappingHandlerMapping();
|
||||
|
||||
WebReactiveConfigurer configurer1 = mock(WebReactiveConfigurer.class);
|
||||
WebReactiveConfigurer configurer2 = mock(WebReactiveConfigurer.class);
|
||||
|
||||
when(configurer1.createRequestMappingHandlerMapping()).thenReturn(Optional.of(mapping1));
|
||||
when(configurer2.createRequestMappingHandlerMapping()).thenReturn(Optional.of(mapping2));
|
||||
|
||||
this.thrown.expectMessage("More than one WebReactiveConfigurer implements " +
|
||||
"RequestMappingHandlerMapping factory method.");
|
||||
|
||||
delegatingConfig.setConfigurers(Arrays.asList(configurer1, configurer2));
|
||||
delegatingConfig.createRequestMappingHandlerMapping();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerAdapter() throws Exception {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webReactiveConfigurer));
|
||||
@@ -99,17 +154,6 @@ public class DelegatingWebReactiveConfigurationTests {
|
||||
assertEquals(5, readers.getValue().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerMapping() throws Exception {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webReactiveConfigurer));
|
||||
delegatingConfig.requestMappingHandlerMapping();
|
||||
|
||||
verify(webReactiveConfigurer).createRequestMappingHandlerMapping();
|
||||
verify(webReactiveConfigurer).configureRequestedContentTypeResolver(any(RequestedContentTypeResolverBuilder.class));
|
||||
verify(webReactiveConfigurer).addCorsMappings(any(CorsRegistry.class));
|
||||
verify(webReactiveConfigurer).configurePathMatching(any(PathMatchConfigurer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceHandlerMapping() throws Exception {
|
||||
delegatingConfig.setConfigurers(Collections.singletonList(webReactiveConfigurer));
|
||||
@@ -141,4 +185,5 @@ public class DelegatingWebReactiveConfigurationTests {
|
||||
|
||||
verify(webReactiveConfigurer).configureViewResolvers(any(ViewResolverRegistry.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user