Skip to content

Commit 0311854

Browse files
committed
MockHttpInputMessage respects getBody contract
Issue: SPR-16367
1 parent 1b3b058 commit 0311854

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -38,7 +38,7 @@ public class MockHttpInputMessage implements HttpInputMessage {
3838

3939

4040
public MockHttpInputMessage(byte[] contents) {
41-
this.body = (contents != null ? new ByteArrayInputStream(contents) : null);
41+
this.body = new ByteArrayInputStream(contents != null ? contents : new byte[0]);
4242
}
4343

4444
public MockHttpInputMessage(InputStream body) {

spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -72,10 +72,7 @@ public String getStatusText() throws IOException {
7272
@Override
7373
public void close() {
7474
try {
75-
InputStream body = getBody();
76-
if (body != null) {
77-
body.close();
78-
}
75+
getBody().close();
7976
}
8077
catch (IOException ex) {
8178
// ignore

0 commit comments

Comments
 (0)