Skip to content

Commit 9ecf7f4

Browse files
committed
Fix MultipartAsRawByteArrayTests for new SF
The `ByteArrayHttpMessageConverter` now uses a `readNBytes()` if `Content-Length` is `0`
1 parent 1059add commit 9ecf7f4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

spring-integration-http/src/test/java/org/springframework/integration/http/inbound/MultipartAsRawByteArrayTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 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.
@@ -32,6 +32,7 @@
3232
import org.springframework.web.context.request.RequestContextHolder;
3333

3434
import static org.assertj.core.api.Assertions.assertThat;
35+
import static org.mockito.ArgumentMatchers.anyInt;
3536
import static org.mockito.Mockito.doReturn;
3637
import static org.mockito.Mockito.mock;
3738
import static org.mockito.Mockito.when;
@@ -57,9 +58,11 @@ public void testMultiPass() throws Exception {
5758
gw.afterPropertiesSet();
5859
gw.start();
5960

61+
String testData = "test data";
62+
6063
HttpServletRequest request = mock(HttpServletRequest.class);
6164
ServletInputStream sis = mock(ServletInputStream.class);
62-
doReturn("test data".getBytes()).when(sis).readAllBytes();
65+
doReturn(testData.getBytes()).when(sis).readNBytes(anyInt());
6366
when(request.getInputStream()).thenReturn(sis);
6467
when(request.getMethod()).thenReturn("POST");
6568
when(request.getHeaderNames()).thenReturn(mock(Enumeration.class));
@@ -70,7 +73,7 @@ public void testMultiPass() throws Exception {
7073
Message<?> received = requestChannel.receive(10000);
7174
assertThat(received).isNotNull();
7275
assertThat(received.getPayload()).isInstanceOf(byte[].class);
73-
assertThat(new String((byte[]) received.getPayload())).isEqualTo("test data");
76+
assertThat(new String((byte[]) received.getPayload())).isEqualTo(testData);
7477
}
7578

7679
}

0 commit comments

Comments
 (0)