Skip to content

Commit 430180a

Browse files
committed
Polishing
1 parent e828be9 commit 430180a

File tree

5 files changed

+75
-66
lines changed

5 files changed

+75
-66
lines changed

spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
import org.springframework.messaging.MessageHeaders;
4343
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
4444
import org.springframework.messaging.converter.StringMessageConverter;
45+
import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
4546
import org.springframework.messaging.handler.annotation.SendTo;
47+
import org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver;
4648
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
4749
import org.springframework.messaging.simp.SimpMessageSendingOperations;
4850
import org.springframework.messaging.simp.SimpMessagingTemplate;
@@ -54,9 +56,6 @@
5456

5557
import static org.junit.Assert.*;
5658
import static org.mockito.BDDMockito.*;
57-
import static org.springframework.messaging.handler.DestinationPatternsMessageCondition.*;
58-
import static org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver.*;
59-
import static org.springframework.messaging.support.MessageHeaderAccessor.*;
6059

6160
/**
6261
* Test fixture for {@link SendToMethodReturnValueHandlerTests}.
@@ -357,7 +356,8 @@ public void testHeadersToSend() throws Exception {
357356
verify(messagingTemplate).convertAndSend(eq("/topic/dest"), eq(PAYLOAD), captor.capture());
358357

359358
MessageHeaders headers = captor.getValue();
360-
SimpMessageHeaderAccessor accessor = getAccessor(headers, SimpMessageHeaderAccessor.class);
359+
SimpMessageHeaderAccessor accessor =
360+
MessageHeaderAccessor.getAccessor(headers, SimpMessageHeaderAccessor.class);
361361
assertNotNull(accessor);
362362
assertTrue(accessor.isMutable());
363363
assertEquals("sess1", accessor.getSessionId());
@@ -399,7 +399,7 @@ public void sendToWithDestinationPlaceholders() throws Exception {
399399
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
400400
accessor.setSessionId(sessionId);
401401
accessor.setSubscriptionId("sub1");
402-
accessor.setHeader(DESTINATION_TEMPLATE_VARIABLES_HEADER, vars);
402+
accessor.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars);
403403
Message<?> message = MessageBuilder.createMessage(PAYLOAD, accessor.getMessageHeaders());
404404
this.handler.handleReturnValue(PAYLOAD, this.sendToWithPlaceholdersReturnType, message);
405405

@@ -549,7 +549,7 @@ private Message<?> createMessage(String sessId, String subsId, String destPrefix
549549
headerAccessor.setSubscriptionId(subsId);
550550
if (dest != null && destPrefix != null) {
551551
headerAccessor.setDestination(destPrefix + dest);
552-
headerAccessor.setHeader(LOOKUP_DESTINATION_HEADER, dest);
552+
headerAccessor.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, dest);
553553
}
554554
if (user != null) {
555555
headerAccessor.setUser(user);
@@ -563,83 +563,55 @@ private SimpMessageHeaderAccessor getCapturedAccessor(int index) {
563563
}
564564

565565

566-
private static class TestUser implements Principal {
567-
568-
public String getName() {
569-
return "joe";
570-
}
571-
572-
public boolean implies(Subject subject) {
573-
return false;
574-
}
575-
}
576-
577-
private static class UniqueUser extends TestUser implements DestinationUserNameProvider {
578-
579-
@Override
580-
public String getDestinationUserName() {
581-
return "Me myself and I";
582-
}
583-
}
584-
585-
@SendTo
586-
@Retention(RetentionPolicy.RUNTIME)
587-
@interface MySendTo {
588-
589-
@AliasFor(annotation = SendTo.class, attribute = "value")
590-
String[] dest();
591-
}
592-
593-
@SendToUser
594-
@Retention(RetentionPolicy.RUNTIME)
595-
@interface MySendToUser {
596-
597-
@AliasFor(annotation = SendToUser.class, attribute = "destinations")
598-
String[] dest();
599-
}
600-
601-
602566
@SuppressWarnings("unused")
603567
String handleNoAnnotations() {
604568
return PAYLOAD;
605569
}
606570

607-
@SendTo @SuppressWarnings("unused")
571+
@SendTo
572+
@SuppressWarnings("unused")
608573
String handleAndSendToDefaultDestination() {
609574
return PAYLOAD;
610575
}
611576

612-
@SendTo({"/dest1", "/dest2"}) @SuppressWarnings("unused")
577+
@SendTo({"/dest1", "/dest2"})
578+
@SuppressWarnings("unused")
613579
String handleAndSendTo() {
614580
return PAYLOAD;
615581
}
616582

617-
@SendTo("/topic/chat.message.filtered.{roomName}") @SuppressWarnings("unused")
583+
@SendTo("/topic/chat.message.filtered.{roomName}")
584+
@SuppressWarnings("unused")
618585
String handleAndSendToWithPlaceholders() {
619586
return PAYLOAD;
620587
}
621588

622-
@SendToUser @SuppressWarnings("unused")
589+
@SendToUser
590+
@SuppressWarnings("unused")
623591
String handleAndSendToUserDefaultDestination() {
624592
return PAYLOAD;
625593
}
626594

627-
@SendToUser(broadcast = false) @SuppressWarnings("unused")
595+
@SendToUser(broadcast = false)
596+
@SuppressWarnings("unused")
628597
String handleAndSendToUserDefaultDestinationSingleSession() {
629598
return PAYLOAD;
630599
}
631600

632-
@SendToUser({"/dest1", "/dest2"}) @SuppressWarnings("unused")
601+
@SendToUser({"/dest1", "/dest2"})
602+
@SuppressWarnings("unused")
633603
String handleAndSendToUser() {
634604
return PAYLOAD;
635605
}
636606

637-
@SendToUser(destinations = { "/dest1", "/dest2" }, broadcast = false) @SuppressWarnings("unused")
607+
@SendToUser(destinations = { "/dest1", "/dest2" }, broadcast = false)
608+
@SuppressWarnings("unused")
638609
String handleAndSendToUserSingleSession() {
639610
return PAYLOAD;
640611
}
641612

642-
@JsonView(MyJacksonView1.class) @SuppressWarnings("unused")
613+
@JsonView(MyJacksonView1.class)
614+
@SuppressWarnings("unused")
643615
JacksonViewBean handleAndSendToJsonView() {
644616
JacksonViewBean payload = new JacksonViewBean();
645617
payload.setWithView1("with");
@@ -649,6 +621,45 @@ JacksonViewBean handleAndSendToJsonView() {
649621
}
650622

651623

624+
private static class TestUser implements Principal {
625+
626+
public String getName() {
627+
return "joe";
628+
}
629+
630+
public boolean implies(Subject subject) {
631+
return false;
632+
}
633+
}
634+
635+
636+
private static class UniqueUser extends TestUser implements DestinationUserNameProvider {
637+
638+
@Override
639+
public String getDestinationUserName() {
640+
return "Me myself and I";
641+
}
642+
}
643+
644+
645+
@SendTo
646+
@Retention(RetentionPolicy.RUNTIME)
647+
@interface MySendTo {
648+
649+
@AliasFor(annotation = SendTo.class, attribute = "value")
650+
String[] dest();
651+
}
652+
653+
654+
@SendToUser
655+
@Retention(RetentionPolicy.RUNTIME)
656+
@interface MySendToUser {
657+
658+
@AliasFor(annotation = SendToUser.class, attribute = "destinations")
659+
String[] dest();
660+
}
661+
662+
652663
@MySendTo(dest = "/dest-default") @SuppressWarnings("unused")
653664
private static class SendToTestBean {
654665

@@ -667,6 +678,7 @@ String handleAndSendToOverride() {
667678
}
668679
}
669680

681+
670682
@MySendToUser(dest = "/dest-default") @SuppressWarnings("unused")
671683
private static class SendToUserTestBean {
672684

@@ -685,6 +697,7 @@ String handleAndSendToOverride() {
685697
}
686698
}
687699

700+
688701
@MySendToUser(dest = "/dest-default") @SuppressWarnings("unused")
689702
private static class SendToUserWithSendToOverrideTestBean {
690703

@@ -701,8 +714,10 @@ String handleAndSendToOverride() {
701714

702715

703716
private interface MyJacksonView1 {}
717+
704718
private interface MyJacksonView2 {}
705719

720+
706721
@SuppressWarnings("unused")
707722
private static class JacksonViewBean {
708723

spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/AsyncTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void callable() throws Exception {
7070

7171
this.mockMvc.perform(asyncDispatch(mvcResult))
7272
.andExpect(status().isOk())
73-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
73+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
7474
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
7575
}
7676

@@ -98,7 +98,7 @@ public void streamingJson() throws Exception {
9898
.andExpect(request().asyncStarted())
9999
.andDo(MvcResult::getAsyncResult)
100100
.andExpect(status().isOk())
101-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
101+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
102102
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.5}"));
103103
}
104104

@@ -112,7 +112,7 @@ public void deferredResult() throws Exception {
112112

113113
this.mockMvc.perform(asyncDispatch(mvcResult))
114114
.andExpect(status().isOk())
115-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
115+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
116116
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
117117
}
118118

@@ -125,7 +125,7 @@ public void deferredResultWithImmediateValue() throws Exception {
125125

126126
this.mockMvc.perform(asyncDispatch(mvcResult))
127127
.andExpect(status().isOk())
128-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
128+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
129129
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
130130
}
131131

@@ -150,7 +150,7 @@ public void listenableFuture() throws Exception {
150150

151151
this.mockMvc.perform(asyncDispatch(mvcResult))
152152
.andExpect(status().isOk())
153-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
153+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
154154
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
155155
}
156156

@@ -162,7 +162,7 @@ public void completableFutureWithImmediateValue() throws Exception {
162162

163163
this.mockMvc.perform(asyncDispatch(mvcResult))
164164
.andExpect(status().isOk())
165-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
165+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
166166
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
167167
}
168168

@@ -183,7 +183,7 @@ public void printAsyncResult() throws Exception {
183183
this.mockMvc.perform(asyncDispatch(mvcResult))
184184
.andDo(print(writer))
185185
.andExpect(status().isOk())
186-
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
186+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
187187
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
188188

189189
assertTrue(writer.toString().contains("Async started = false"));

spring-web/src/test/java/org/springframework/web/client/AsyncRestTemplateIntegrationTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ public ListenableFuture<ClientHttpResponse> intercept(HttpRequest request, byte[
630630
AsyncClientHttpRequestExecution execution) throws IOException {
631631

632632
request = new HttpRequestWrapper(request) {
633-
634633
@Override
635634
public URI getURI() {
636635
try {

spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ public void jsonPostForObjectWithJacksonView() throws URISyntaxException {
240240
assertFalse(s.contains("\"without\":\"without\""));
241241
}
242242

243-
// SPR-12123
244-
245-
@Test
243+
@Test // SPR-12123
246244
public void serverPort() {
247245
String s = template.getForObject("http://localhost:{port}/get", String.class, port);
248246
assertEquals("Invalid content", helloWorld, s);

spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/ScriptTemplateViewTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ public void setup() {
6767
this.view = new ScriptTemplateView();
6868
}
6969

70+
7071
@Test
7172
public void missingScriptTemplateConfig() throws Exception {
7273
try {
7374
this.view.setApplicationContext(new StaticApplicationContext());
75+
fail("Should have thrown ApplicationContextException");
7476
}
7577
catch (ApplicationContextException ex) {
7678
assertTrue(ex.getMessage().contains("ScriptTemplateConfig"));
77-
return;
7879
}
79-
fail();
8080
}
8181

8282
@Test
@@ -158,7 +158,6 @@ public void nonInvocableScriptEngine() throws Exception {
158158
}
159159
catch (IllegalArgumentException ex) {
160160
assertThat(ex.getMessage(), containsString("instance"));
161-
return;
162161
}
163162
}
164163

@@ -199,9 +198,7 @@ public void engineSetterAndNonSharedEngine() {
199198
}
200199
catch (IllegalArgumentException ex) {
201200
assertThat(ex.getMessage(), containsString("sharedEngine"));
202-
return;
203201
}
204-
fail();
205202
}
206203

207204
@Test // SPR-14210

0 commit comments

Comments
 (0)