diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java index cfbc15f9ac..8d5a992899 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2021 the original author or authors. + * Copyright 2015-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +17,7 @@ package org.springframework.integration.http.inbound; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -30,8 +29,6 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.junit.jupiter.api.Test; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.springframework.beans.factory.BeanFactory; import org.springframework.http.converter.ByteArrayHttpMessageConverter; @@ -63,20 +60,7 @@ public class MultipartAsRawByteArrayTests { HttpServletRequest request = mock(HttpServletRequest.class); ServletInputStream sis = mock(ServletInputStream.class); - doAnswer(new Answer() { - - int done; - - @Override - public Integer answer(InvocationOnMock invocation) { - byte[] buff = invocation.getArgument(0); - buff[0] = 'f'; - buff[1] = 'o'; - buff[2] = 'o'; - return done++ > 0 ? -1 : 3; - } - - }).when(sis).read(any(byte[].class)); + doReturn("test data".getBytes()).when(sis).readAllBytes(); when(request.getInputStream()).thenReturn(sis); when(request.getMethod()).thenReturn("POST"); when(request.getHeaderNames()).thenReturn(mock(Enumeration.class)); @@ -87,7 +71,7 @@ public class MultipartAsRawByteArrayTests { Message received = requestChannel.receive(10000); assertThat(received).isNotNull(); assertThat(received.getPayload()).isInstanceOf(byte[].class); - assertThat(new String((byte[]) received.getPayload())).isEqualTo("foo"); + assertThat(new String((byte[]) received.getPayload())).isEqualTo("test data"); } } diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java index 7e42d25ec0..42d8835bbc 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java @@ -111,7 +111,7 @@ public class HttpRequestExecutingMessageHandlerTests { MessageBuilder.withPayload(form) .setHeader(MessageHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=UTF-8") - .build(); + .build(); QueueChannel replyChannel = new QueueChannel(); handler.setOutputChannel(replyChannel); @@ -204,9 +204,9 @@ public class HttpRequestExecutingMessageHandlerTests { setBeanFactory(handler); handler.afterPropertiesSet(); Map form = new LinkedHashMap<>(); - form.put("a", new String[] { "1", "2", "3" }); + form.put("a", new String[]{ "1", "2", "3" }); form.put("b", "4"); - form.put("c", new String[] { "5" }); + form.put("c", new String[]{ "5" }); form.put("d", "6"); Message message = MessageBuilder.withPayload(form).build(); @@ -249,9 +249,9 @@ public class HttpRequestExecutingMessageHandlerTests { setBeanFactory(handler); handler.afterPropertiesSet(); Map form = new LinkedHashMap<>(); - form.put("a", new int[] { 1, 2, 3 }); + form.put("a", new int[]{ 1, 2, 3 }); form.put("b", "4"); - form.put("c", new String[] { "5" }); + form.put("c", new String[]{ "5" }); form.put("d", "6"); Message message = MessageBuilder.withPayload(form).build(); @@ -297,7 +297,7 @@ public class HttpRequestExecutingMessageHandlerTests { setBeanFactory(handler); handler.afterPropertiesSet(); Map form = new LinkedHashMap<>(); - form.put("a", new Object[] { null, 4, null }); + form.put("a", new Object[]{ null, 4, null }); form.put("b", "4"); Message message = MessageBuilder.withPayload(form).build(); @@ -833,9 +833,11 @@ public class HttpRequestExecutingMessageHandlerTests { public void testNoContentTypeAndSmartConverter() { Sinks.One httpHeadersSink = Sinks.one(); RestTemplate testRestTemplate = new RestTemplate() { + @Nullable - protected T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, - @Nullable ResponseExtractor responseExtractor) throws RestClientException { + protected T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method, + @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor) + throws RestClientException { try { ClientHttpRequest request = createRequest(url, method); @@ -847,11 +849,12 @@ public class HttpRequestExecutingMessageHandlerTests { } throw new RuntimeException("intentional"); } + }; HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("https://www.springsource.org/spring-integration", - testRestTemplate); + testRestTemplate); setBeanFactory(handler); handler.afterPropertiesSet(); @@ -911,8 +914,10 @@ public class HttpRequestExecutingMessageHandlerTests { private final AtomicReference actualUrl = new AtomicReference<>(); @Nullable - protected T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, - @Nullable ResponseExtractor responseExtractor) throws RestClientException { + protected T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method, + @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor) + throws RestClientException { + this.actualUrl.set(url.toString()); this.lastRequestEntity.set(TestUtils.getPropertyValue(requestCallback, "requestEntity", HttpEntity.class)); throw new RuntimeException("intentional"); @@ -932,8 +937,10 @@ public class HttpRequestExecutingMessageHandlerTests { } @Nullable - protected T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, - @Nullable ResponseExtractor responseExtractor) throws RestClientException { + protected T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method, + @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor) + throws RestClientException { + this.actualUrl.set(url.toString()); try { return responseExtractor.extractData(new MockClientHttpResponse(new byte[0], HttpStatus.OK));