Skip to content

Commit 5237e47

Browse files
committed
Polish
1 parent 226c9f9 commit 5237e47

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.net.HttpURLConnection;
21-
import java.net.Proxy;
2221
import java.net.URI;
23-
import java.net.URL;
2422
import java.util.Optional;
2523

2624
import org.junit.Test;
@@ -41,8 +39,9 @@
4139
import org.springframework.web.bind.annotation.GetMapping;
4240
import org.springframework.web.bind.annotation.RequestParam;
4341
import org.springframework.web.client.RestTemplate;
42+
import org.springframework.web.reactive.config.EnableWebFlux;
4443
import org.springframework.web.reactive.config.ViewResolverRegistry;
45-
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
44+
import org.springframework.web.reactive.config.WebFluxConfigurer;
4645
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
4746
import org.springframework.web.server.ServerWebExchange;
4847

@@ -102,12 +101,13 @@ protected void prepareConnection(HttpURLConnection conn, String method) throws I
102101

103102

104103
@Configuration
104+
@EnableWebFlux
105105
@ComponentScan(resourcePattern = "**/RequestMappingViewResolutionIntegrationTests$*.class")
106106
@SuppressWarnings({"unused", "WeakerAccess"})
107-
static class WebConfig extends WebFluxConfigurationSupport {
107+
static class WebConfig implements WebFluxConfigurer {
108108

109109
@Override
110-
protected void configureViewResolvers(ViewResolverRegistry registry) {
110+
public void configureViewResolvers(ViewResolverRegistry registry) {
111111
registry.freeMarker();
112112
}
113113

@@ -122,7 +122,7 @@ public FreeMarkerConfigurer freeMarkerConfig() {
122122

123123

124124
@Controller
125-
@SuppressWarnings("unused")
125+
@SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"})
126126
private static class TestController {
127127

128128
@GetMapping("/html")

spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.web.reactive.result.view;
1818

19+
import java.time.Duration;
1920
import java.util.Locale;
2021
import java.util.Map;
2122

@@ -41,54 +42,57 @@ public class UrlBasedViewResolverTests {
4142

4243
private UrlBasedViewResolver resolver;
4344

45+
4446
@Before
4547
public void setup() {
4648
StaticApplicationContext context = new StaticApplicationContext();
4749
context.refresh();
48-
resolver = new UrlBasedViewResolver();
49-
resolver.setApplicationContext(context);
50+
this.resolver = new UrlBasedViewResolver();
51+
this.resolver.setApplicationContext(context);
5052
}
5153

5254

5355
@Test
5456
public void viewNames() throws Exception {
55-
resolver.setViewClass(TestView.class);
56-
resolver.setViewNames("my*");
57+
this.resolver.setViewClass(TestView.class);
58+
this.resolver.setViewNames("my*");
5759

58-
Mono<View> mono = resolver.resolveViewName("my-view", Locale.US);
60+
Mono<View> mono = this.resolver.resolveViewName("my-view", Locale.US);
5961
assertNotNull(mono.block());
6062

61-
mono = resolver.resolveViewName("not-my-view", Locale.US);
63+
mono = this.resolver.resolveViewName("not-my-view", Locale.US);
6264
assertNull(mono.block());
6365
}
6466

6567
@Test
6668
public void redirectView() throws Exception {
67-
Mono<View> mono = resolver.resolveViewName("redirect:foo", Locale.US);
68-
assertNotNull(mono.block());
69+
Mono<View> mono = this.resolver.resolveViewName("redirect:foo", Locale.US);
70+
6971
StepVerifier.create(mono)
7072
.consumeNextWith(view -> {
7173
assertEquals(RedirectView.class, view.getClass());
7274
RedirectView redirectView = (RedirectView) view;
7375
assertEquals(redirectView.getUrl(), "foo");
7476
assertEquals(redirectView.getStatusCode(), HttpStatus.SEE_OTHER);
7577
})
76-
.expectComplete();
78+
.expectComplete()
79+
.verify(Duration.ZERO);
7780
}
7881

7982
@Test
8083
public void customizedRedirectView() throws Exception {
81-
resolver.setRedirectViewProvider(url -> new RedirectView(url, HttpStatus.FOUND));
82-
Mono<View> mono = resolver.resolveViewName("redirect:foo", Locale.US);
83-
assertNotNull(mono.block());
84+
this.resolver.setRedirectViewProvider(url -> new RedirectView(url, HttpStatus.FOUND));
85+
Mono<View> mono = this.resolver.resolveViewName("redirect:foo", Locale.US);
86+
8487
StepVerifier.create(mono)
8588
.consumeNextWith(view -> {
8689
assertEquals(RedirectView.class, view.getClass());
8790
RedirectView redirectView = (RedirectView) view;
8891
assertEquals(redirectView.getUrl(), "foo");
8992
assertEquals(redirectView.getStatusCode(), HttpStatus.FOUND);
9093
})
91-
.expectComplete();
94+
.expectComplete()
95+
.verify(Duration.ZERO);
9296
}
9397

9498

@@ -102,6 +106,7 @@ public boolean checkResourceExists(Locale locale) throws Exception {
102106
@Override
103107
protected Mono<Void> renderInternal(Map<String, Object> attributes, MediaType contentType,
104108
ServerWebExchange exchange) {
109+
105110
return Mono.empty();
106111
}
107112
}

spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
import static org.springframework.http.MediaType.*;
6666

6767
/**
68-
* Unit tests for {@link ViewResolutionResultHandler}.
68+
* ViewResolutionResultHandler relying on a canned {@link TestViewResolver}
69+
* or a (Mockito) "mock".
70+
*
6971
* @author Rossen Stoyanchev
7072
*/
7173
public class ViewResolutionResultHandlerTests {

0 commit comments

Comments
 (0)