Polishing

This commit is contained in:
Juergen Hoeller
2017-03-07 10:33:48 +01:00
parent e58b17a3a1
commit 98dbc17591
6 changed files with 66 additions and 47 deletions

View File

@@ -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.
@@ -35,6 +35,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.ClassPathResource;
@@ -67,10 +69,10 @@ public class RestTemplateIntegrationTests extends AbstractMockWebServerTestCase
private RestTemplate template;
@Parameterized.Parameter
@Parameter
public ClientHttpRequestFactory clientHttpRequestFactory;
@Parameterized.Parameters
@Parameters
public static Iterable<? extends ClientHttpRequestFactory> data() {
return Arrays.asList(
new SimpleClientHttpRequestFactory(),
@@ -81,11 +83,13 @@ public class RestTemplateIntegrationTests extends AbstractMockWebServerTestCase
);
}
@Before
public void setUpClient() {
public void setupClient() {
this.template = new RestTemplate(this.clientHttpRequestFactory);
}
@Test
public void getString() {
String s = template.getForObject(baseUrl + "/{method}", String.class, "get");

View File

@@ -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.
@@ -69,7 +69,7 @@ public class RestTemplateTests {
@Before
public void setUp() {
public void setup() {
requestFactory = mock(ClientHttpRequestFactory.class);
request = mock(ClientHttpRequest.class);
response = mock(ClientHttpResponse.class);
@@ -146,6 +146,21 @@ public class RestTemplateTests {
verify(response).close();
}
@Test // SPR-15201
public void uriTemplateWithTrailingSlash() throws Exception {
String url = "http://example.com/spring/";
given(requestFactory.createRequest(new URI(url), HttpMethod.GET)).willReturn(request);
given(request.execute()).willReturn(response);
given(errorHandler.hasError(response)).willReturn(false);
HttpStatus status = HttpStatus.OK;
given(response.getStatusCode()).willReturn(status);
given(response.getStatusText()).willReturn(status.getReasonPhrase());
template.execute(url, HttpMethod.GET, null, null);
verify(response).close();
}
@Test
public void errorHandling() throws Exception {
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.GET)).willReturn(request);
@@ -265,7 +280,6 @@ public class RestTemplateTests {
@Test
public void getForObjectWithCustomUriTemplateHandler() throws Exception {
DefaultUriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
uriTemplateHandler.setParsePath(true);
template.setUriTemplateHandler(uriTemplateHandler);
@@ -292,7 +306,6 @@ public class RestTemplateTests {
verify(response).close();
}
@Test
public void headForHeaders() throws Exception {
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.HEAD)).willReturn(request);