From 03118542f4e3b95d24959f3ba907b3c0b891b899 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 12 Jan 2018 11:44:42 -0500 Subject: [PATCH] MockHttpInputMessage respects getBody contract Issue: SPR-16367 --- .../springframework/mock/http/MockHttpInputMessage.java | 4 ++-- .../mock/http/client/MockClientHttpResponse.java | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java b/spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java index 4c7881cdf0..3fe46ce034 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java +++ b/spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -38,7 +38,7 @@ public class MockHttpInputMessage implements HttpInputMessage { public MockHttpInputMessage(byte[] contents) { - this.body = (contents != null ? new ByteArrayInputStream(contents) : null); + this.body = new ByteArrayInputStream(contents != null ? contents : new byte[0]); } public MockHttpInputMessage(InputStream body) { diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java b/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java index 5044215e1c..22eca1c38c 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -72,10 +72,7 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie @Override public void close() { try { - InputStream body = getBody(); - if (body != null) { - body.close(); - } + getBody().close(); } catch (IOException ex) { // ignore