Consistent use of @Nullable across the codebase (even for internals)
Beyond just formally declaring the current behavior, this revision actually enforces non-null behavior in selected signatures now, not tolerating null values anymore when not explicitly documented. It also changes some utility methods with historic null-in/null-out tolerance towards enforced non-null return values, making them a proper citizen in non-null assignments. Some issues are left as to-do: in particular a thorough revision of spring-test, and a few tests with unclear failures (ignored as "TODO: NULLABLE") to be sorted out in a follow-up commit. Issue: SPR-15540
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.web.client;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -27,16 +28,14 @@ import org.springframework.http.client.ClientHttpRequest;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.http.HttpMethod.GET;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.test.web.client.ExpectedCount.once;
|
||||
import static org.springframework.test.web.client.ExpectedCount.twice;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
|
||||
import static org.springframework.http.HttpMethod.*;
|
||||
import static org.springframework.test.web.client.ExpectedCount.*;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultRequestExpectation}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class DefaultRequestExpectationTests {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.web.client;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -20,11 +21,12 @@ import org.junit.Test;
|
||||
import org.springframework.test.web.client.MockRestServiceServer.MockRestServiceServerBuilder;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MockRestServiceServer}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class MockRestServiceServerTests {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.http.client.MockClientHttpResponse;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertTrue(response.getHeaders().isEmpty());
|
||||
assertNull(response.getBody());
|
||||
assertEquals(0, StreamUtils.copyToByteArray(response.getBody()).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,7 +50,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertEquals(MediaType.TEXT_PLAIN, response.getHeaders().getContentType());
|
||||
assertArrayEquals("foo".getBytes(), FileCopyUtils.copyToByteArray(response.getBody()));
|
||||
assertArrayEquals("foo".getBytes(), StreamUtils.copyToByteArray(response.getBody()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,7 +60,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNull(response.getHeaders().getContentType());
|
||||
assertArrayEquals("foo".getBytes(), FileCopyUtils.copyToByteArray(response.getBody()));
|
||||
assertArrayEquals("foo".getBytes(), StreamUtils.copyToByteArray(response.getBody()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +71,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.CREATED, response.getStatusCode());
|
||||
assertEquals(location, response.getHeaders().getLocation());
|
||||
assertNull(response.getBody());
|
||||
assertEquals(0, StreamUtils.copyToByteArray(response.getBody()).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +81,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
|
||||
assertTrue(response.getHeaders().isEmpty());
|
||||
assertNull(response.getBody());
|
||||
assertEquals(0, StreamUtils.copyToByteArray(response.getBody()).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,7 +91,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
assertTrue(response.getHeaders().isEmpty());
|
||||
assertNull(response.getBody());
|
||||
assertEquals(0, StreamUtils.copyToByteArray(response.getBody()).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +101,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
|
||||
assertTrue(response.getHeaders().isEmpty());
|
||||
assertNull(response.getBody());
|
||||
assertEquals(0, StreamUtils.copyToByteArray(response.getBody()).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,7 +111,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
|
||||
assertTrue(response.getHeaders().isEmpty());
|
||||
assertNull(response.getBody());
|
||||
assertEquals(0, StreamUtils.copyToByteArray(response.getBody()).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,7 +121,7 @@ public class ResponseCreatorsTests {
|
||||
|
||||
assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
|
||||
assertTrue(response.getHeaders().isEmpty());
|
||||
assertNull(response.getBody());
|
||||
assertEquals(0, StreamUtils.copyToByteArray(response.getBody()).length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user