Skip to content

Commit 7dd8dc6

Browse files
committed
Fixes for ignored tests after last week's nullability commit
Issue: SPR-15540
1 parent 58242f2 commit 7dd8dc6

File tree

9 files changed

+30
-53
lines changed

9 files changed

+30
-53
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ public void handleReturnValue(@Nullable Object returnValue, MethodParameter retu
179179
}
180180
}
181181
}
182-
else if (annotation instanceof SendTo) {
183-
SendTo sendTo = (SendTo) annotation;
182+
else {
183+
SendTo sendTo = (SendTo) annotation; // possibly null
184184
String[] destinations = getTargetDestinations(sendTo, message, this.defaultDestinationPrefix);
185185
for (String destination : destinations) {
186186
destination = this.placeholderHelper.replacePlaceholders(destination, varResolver);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import com.fasterxml.jackson.annotation.JsonView;
2929
import org.junit.Before;
30-
import org.junit.Ignore;
3130
import org.junit.Test;
3231
import org.mockito.ArgumentCaptor;
3332
import org.mockito.Captor;
@@ -176,7 +175,6 @@ public void supportsReturnType() throws Exception {
176175
}
177176

178177
@Test
179-
@Ignore // TODO: NULLABLE
180178
public void sendToNoAnnotations() throws Exception {
181179
given(this.messageChannel.send(any(Message.class))).willReturn(true);
182180

@@ -346,7 +344,6 @@ public void sendToDefaultDestinationWhenUsingDotPathSeparator() throws Exception
346344
}
347345

348346
@Test
349-
@Ignore // TODO: NULLABLE
350347
public void testHeadersToSend() throws Exception {
351348
Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);
352349

@@ -530,7 +527,6 @@ public void sendToUserSessionWithoutUserName() throws Exception {
530527
}
531528

532529
@Test
533-
@Ignore // TODO: NULLABLE
534530
public void jsonView() throws Exception {
535531
given(this.messageChannel.send(any(Message.class))).willReturn(true);
536532

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.concurrent.ConcurrentHashMap;
2727

2828
import org.junit.Before;
29-
import org.junit.Ignore;
3029
import org.junit.Test;
3130
import org.mockito.ArgumentCaptor;
3231
import org.mockito.Captor;
@@ -238,7 +237,6 @@ public void dotPathSeparator() {
238237
}
239238

240239
@Test
241-
@Ignore // TODO: NULLABLE
242240
@SuppressWarnings("unchecked")
243241
public void listenableFutureSuccess() {
244242
Message emptyMessage = (Message) MessageBuilder.withPayload(new byte[0]).build();
@@ -277,7 +275,6 @@ public void listenableFutureFailure() {
277275
}
278276

279277
@Test
280-
@Ignore // TODO: NULLABLE
281278
@SuppressWarnings("unchecked")
282279
public void completableFutureSuccess() {
283280
Message emptyMessage = (Message) MessageBuilder.withPayload(new byte[0]).build();

spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.nio.charset.StandardCharsets;
2020

2121
import org.junit.Before;
22-
import org.junit.Ignore;
2322
import org.junit.Test;
2423
import org.mockito.ArgumentCaptor;
2524
import org.mockito.Mockito;
@@ -123,7 +122,6 @@ public void handleMessageWithoutActiveSession() {
123122
}
124123

125124
@Test
126-
@Ignore // TODO: NULLABLE
127125
public void handleMessageFromBrokerWithActiveSession() {
128126
TestSimpUser simpUser = new TestSimpUser("joe");
129127
simpUser.addSessions(new TestSimpSession("123"));

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ protected <T> Object readWithMessageConverters(HttpInputMessage inputMessage, Me
200200
logger.debug("Read [" + targetType + "] as \"" + contentType + "\" with [" + converter + "]");
201201
}
202202
if (message.hasBody()) {
203-
HttpInputMessage inputMessageToUse =
203+
HttpInputMessage msgToUse =
204204
getAdvice().beforeBodyRead(message, parameter, targetType, converterType);
205-
body = (genericConverter != null ? genericConverter.read(targetType, contextClass, message) :
206-
((HttpMessageConverter<T>) converter).read(targetClass, message));
207-
body = getAdvice().afterBodyRead(body, inputMessageToUse, parameter, targetType, converterType);
205+
body = (genericConverter != null ? genericConverter.read(targetType, contextClass, msgToUse) :
206+
((HttpMessageConverter<T>) converter).read(targetClass, msgToUse));
207+
body = getAdvice().afterBodyRead(body, msgToUse, parameter, targetType, converterType);
208208
}
209209
else {
210210
body = getAdvice().handleEmptyBody(null, message, parameter, targetType, converterType);

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ protected AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>>
117117
@Nullable ContentNegotiationManager manager, @Nullable List<Object> requestResponseBodyAdvice) {
118118

119119
super(converters, requestResponseBodyAdvice);
120+
120121
this.contentNegotiationManager = (manager != null ? manager : new ContentNegotiationManager());
121122
this.pathStrategy = initPathStrategy(this.contentNegotiationManager);
122123
this.safeExtensions.addAll(this.contentNegotiationManager.getAllFileExtensions());
@@ -163,7 +164,7 @@ protected <T> void writeWithMessageConverters(T value, MethodParameter returnTyp
163164
* @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated
164165
* by the {@code Accept} header on the request cannot be met by the message converters
165166
*/
166-
@SuppressWarnings("unchecked")
167+
@SuppressWarnings({"rawtypes", "unchecked"})
167168
protected <T> void writeWithMessageConverters(@Nullable T value, MethodParameter returnType,
168169
ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage)
169170
throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException {
@@ -223,35 +224,26 @@ else if (mediaType.equals(MediaType.ALL) || mediaType.equals(MEDIA_TYPE_APPLICAT
223224

224225
if (selectedMediaType != null) {
225226
selectedMediaType = selectedMediaType.removeQualityValue();
226-
for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
227-
if (messageConverter instanceof GenericHttpMessageConverter) {
228-
if (((GenericHttpMessageConverter) messageConverter).canWrite(
229-
declaredType, valueType, selectedMediaType)) {
230-
outputValue = (T) getAdvice().beforeBodyWrite(outputValue, returnType, selectedMediaType,
231-
(Class<? extends HttpMessageConverter<?>>) messageConverter.getClass(),
232-
inputMessage, outputMessage);
233-
if (outputValue != null) {
234-
addContentDispositionHeader(inputMessage, outputMessage);
235-
((GenericHttpMessageConverter) messageConverter).write(
236-
outputValue, declaredType, selectedMediaType, outputMessage);
237-
if (logger.isDebugEnabled()) {
238-
logger.debug("Written [" + outputValue + "] as \"" + selectedMediaType +
239-
"\" using [" + messageConverter + "]");
240-
}
241-
}
242-
return;
243-
}
244-
}
245-
else if (messageConverter.canWrite(valueType, selectedMediaType)) {
227+
for (HttpMessageConverter<?> converter : this.messageConverters) {
228+
GenericHttpMessageConverter genericConverter =
229+
(converter instanceof GenericHttpMessageConverter ? (GenericHttpMessageConverter<?>) converter : null);
230+
if (genericConverter != null ?
231+
((GenericHttpMessageConverter) converter).canWrite(declaredType, valueType, selectedMediaType) :
232+
converter.canWrite(valueType, selectedMediaType)) {
246233
outputValue = (T) getAdvice().beforeBodyWrite(outputValue, returnType, selectedMediaType,
247-
(Class<? extends HttpMessageConverter<?>>) messageConverter.getClass(),
234+
(Class<? extends HttpMessageConverter<?>>) converter.getClass(),
248235
inputMessage, outputMessage);
249236
if (outputValue != null) {
250237
addContentDispositionHeader(inputMessage, outputMessage);
251-
((HttpMessageConverter) messageConverter).write(outputValue, selectedMediaType, outputMessage);
238+
if (genericConverter != null) {
239+
genericConverter.write(outputValue, declaredType, selectedMediaType, outputMessage);
240+
}
241+
else {
242+
((HttpMessageConverter) converter).write(outputValue, selectedMediaType, outputMessage);
243+
}
252244
if (logger.isDebugEnabled()) {
253245
logger.debug("Written [" + outputValue + "] as \"" + selectedMediaType +
254-
"\" using [" + messageConverter + "]");
246+
"\" using [" + converter + "]");
255247
}
256248
}
257249
return;
@@ -305,7 +297,9 @@ protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Cl
305297
* @since 4.2
306298
*/
307299
@SuppressWarnings("unchecked")
308-
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass, @Nullable Type declaredType) {
300+
protected List<MediaType> getProducibleMediaTypes(HttpServletRequest request, Class<?> valueClass,
301+
@Nullable Type declaredType) {
302+
309303
Set<MediaType> mediaTypes = (Set<MediaType>) request.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
310304
if (!CollectionUtils.isEmpty(mediaTypes)) {
311305
return new ArrayList<>(mediaTypes);

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converte
8989
* @since 4.2
9090
*/
9191
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters,
92-
List<Object> requestResponseBodyAdvice) {
92+
@Nullable List<Object> requestResponseBodyAdvice) {
9393

9494
super(converters, null, requestResponseBodyAdvice);
9595
}
@@ -99,7 +99,7 @@ public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converte
9999
* {@code @ResponseBody}.
100100
*/
101101
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> converters,
102-
ContentNegotiationManager manager, List<Object> requestResponseBodyAdvice) {
102+
@Nullable ContentNegotiationManager manager, @Nullable List<Object> requestResponseBodyAdvice) {
103103

104104
super(converters, manager, requestResponseBodyAdvice);
105105
}

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ public void jacksonJsonViewWithResponseEntityAndXmlMessageConverter() throws Exc
507507
}
508508

509509
@Test // SPR-12501
510-
@Ignore // TODO: NULLABLE
511510
public void resolveArgumentWithJacksonJsonView() throws Exception {
512511
String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}";
513512
this.servletRequest.setContent(content.getBytes("UTF-8"));
@@ -534,7 +533,6 @@ public void resolveArgumentWithJacksonJsonView() throws Exception {
534533
}
535534

536535
@Test // SPR-12501
537-
@Ignore // TODO: NULLABLE
538536
public void resolveHttpEntityArgumentWithJacksonJsonView() throws Exception {
539537
String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}";
540538
this.servletRequest.setContent(content.getBytes("UTF-8"));
@@ -562,7 +560,6 @@ public void resolveHttpEntityArgumentWithJacksonJsonView() throws Exception {
562560
}
563561

564562
@Test // SPR-12501
565-
@Ignore // TODO: NULLABLE
566563
public void resolveArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Exception {
567564
String content = "<root><withView1>with</withView1><withView2>with</withView2><withoutView>without</withoutView></root>";
568565
this.servletRequest.setContent(content.getBytes("UTF-8"));
@@ -589,7 +586,6 @@ public void resolveArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Ex
589586
}
590587

591588
@Test // SPR-12501
592-
@Ignore // TODO: NULLABLE
593589
public void resolveHttpEntityArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Exception {
594590
String content = "<root><withView1>with</withView1><withView2>with</withView2><withoutView>without</withoutView></root>";
595591
this.servletRequest.setContent(content.getBytes("UTF-8"));

spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import java.util.concurrent.CountDownLatch;
2424
import java.util.concurrent.TimeUnit;
2525

26-
import org.junit.Ignore;
2726
import org.junit.Test;
2827
import org.junit.runner.RunWith;
2928
import org.junit.runners.Parameterized;
@@ -67,7 +66,6 @@
6766
* @author Rossen Stoyanchev
6867
*/
6968
@RunWith(Parameterized.class)
70-
@Ignore // TODO: NULLABLE
7169
public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
7270

7371
private static final long TIMEOUT = 10;
@@ -120,8 +118,7 @@ public void sendMessageToControllerAndReceiveReplyViaTopic() throws Exception {
120118
}
121119
}
122120

123-
// SPR-10930
124-
@Test
121+
@Test // SPR-10930
125122
public void sendMessageToBrokerAndReceiveReplyViaTopic() throws Exception {
126123
TextMessage m1 = create(StompCommand.SUBSCRIBE).headers("id:subs1", "destination:/topic/foo").build();
127124
TextMessage m2 = create(StompCommand.SEND).headers("destination:/topic/foo").body("5").build();
@@ -140,8 +137,7 @@ public void sendMessageToBrokerAndReceiveReplyViaTopic() throws Exception {
140137
}
141138
}
142139

143-
// SPR-11648
144-
@Test
140+
@Test // SPR-11648
145141
public void sendSubscribeToControllerAndReceiveReply() throws Exception {
146142
String destHeader = "destination:/app/number";
147143
TextMessage message = create(StompCommand.SUBSCRIBE).headers("id:subs1", destHeader).build();

0 commit comments

Comments
 (0)