Skip to content

Commit 417bce8

Browse files
Yin-Juisbrannen
authored andcommitted
Add tests for MessageBodyClientHttpResponseWrapper
Closes spring-projectsgh-26984
1 parent 19283c9 commit 417bce8

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2002-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.web.client;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.springframework.http.HttpHeaders;
20+
import org.springframework.http.HttpStatus;
21+
import org.springframework.http.client.ClientHttpResponse;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
import static org.mockito.BDDMockito.given;
25+
import static org.mockito.Mockito.mock;
26+
27+
import java.io.ByteArrayInputStream;
28+
import java.io.IOException;
29+
import java.io.InputStream;
30+
31+
/**
32+
* Unit tests for {MessageBodyClientHttpResponseWrapper}.
33+
*
34+
* @author Yin-Jui Liao
35+
*/
36+
class MessageBodyClientHttpResponseWrapperTests {
37+
38+
private final ClientHttpResponse response = mock(ClientHttpResponse.class);
39+
40+
@Test
41+
void testMessageBodyNotExist() throws IOException {
42+
given(response.getBody()).willReturn(null);
43+
MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response);
44+
assertThat(responseWrapper.hasEmptyMessageBody()).isTrue();
45+
}
46+
47+
@Test
48+
void testMessageBodyExist() throws IOException {
49+
String body = "Accepted request";
50+
InputStream stream = new ByteArrayInputStream(body.getBytes());
51+
given(response.getBody()).willReturn(stream);
52+
MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response);
53+
assertThat(responseWrapper.hasEmptyMessageBody()).isFalse();
54+
}
55+
}

0 commit comments

Comments
 (0)