Use URI#create instead of URI constructor where feasible in spring-test
This commit is contained in:
parent
4caf3c8ce0
commit
a1a140f7d5
|
@ -18,7 +18,6 @@ package org.springframework.mock.http.client;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpRequest;
|
||||
|
@ -51,12 +50,7 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
|
|||
*/
|
||||
public MockClientHttpRequest() {
|
||||
this.httpMethod = HttpMethod.GET;
|
||||
try {
|
||||
this.uri = new URI("/");
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
this.uri = URI.create("/");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.test.web.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -38,17 +37,16 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
|||
* Unit tests for {@link DefaultRequestExpectation}.
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class DefaultRequestExpectationTests {
|
||||
|
||||
class DefaultRequestExpectationTests {
|
||||
|
||||
@Test
|
||||
public void match() throws Exception {
|
||||
void match() throws Exception {
|
||||
RequestExpectation expectation = new DefaultRequestExpectation(once(), requestTo("/foo"));
|
||||
expectation.match(createRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWithFailedExpectation() {
|
||||
void matchWithFailedExpectation() {
|
||||
RequestExpectation expectation = new DefaultRequestExpectation(once(), requestTo("/foo"));
|
||||
expectation.andExpect(method(POST));
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
|
||||
|
@ -57,7 +55,7 @@ public class DefaultRequestExpectationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void hasRemainingCount() {
|
||||
void hasRemainingCount() {
|
||||
RequestExpectation expectation = new DefaultRequestExpectation(twice(), requestTo("/foo"));
|
||||
expectation.andRespond(withSuccess());
|
||||
|
||||
|
@ -69,7 +67,7 @@ public class DefaultRequestExpectationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void isSatisfied() {
|
||||
void isSatisfied() {
|
||||
RequestExpectation expectation = new DefaultRequestExpectation(twice(), requestTo("/foo"));
|
||||
expectation.andRespond(withSuccess());
|
||||
|
||||
|
@ -82,12 +80,7 @@ public class DefaultRequestExpectationTests {
|
|||
|
||||
|
||||
private ClientHttpRequest createRequest() {
|
||||
try {
|
||||
return new MockClientHttpRequest(HttpMethod.GET, new URI("/foo"));
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
return new MockClientHttpRequest(HttpMethod.GET, URI.create("/foo"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.springframework.test.web.client;
|
|||
|
||||
import java.net.SocketException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -199,12 +198,7 @@ class SimpleRequestExpectationManagerTests {
|
|||
|
||||
|
||||
private ClientHttpRequest createRequest(HttpMethod method, String url) {
|
||||
try {
|
||||
return new MockClientHttpRequest(method, new URI(url));
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
return new MockClientHttpRequest(method, URI.create(url));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.test.web.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -121,12 +120,7 @@ class UnorderedRequestExpectationManagerTests {
|
|||
|
||||
|
||||
private ClientHttpRequest createRequest(HttpMethod method, String url) {
|
||||
try {
|
||||
return new MockClientHttpRequest(method, new URI(url));
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
return new MockClientHttpRequest(method, URI.create(url));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
@ -36,28 +36,28 @@ import static org.hamcrest.Matchers.containsString;
|
|||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class MockRestRequestMatchersTests {
|
||||
class MockRestRequestMatchersTests {
|
||||
|
||||
private final MockClientHttpRequest request = new MockClientHttpRequest();
|
||||
|
||||
|
||||
@Test
|
||||
public void requestTo() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/bar"));
|
||||
void requestTo() throws Exception {
|
||||
this.request.setURI(URI.create("http://www.foo.example/bar"));
|
||||
|
||||
MockRestRequestMatchers.requestTo("http://www.foo.example/bar").match(this.request);
|
||||
}
|
||||
|
||||
@Test // SPR-15819
|
||||
public void requestToUriTemplate() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/bar"));
|
||||
void requestToUriTemplate() throws Exception {
|
||||
this.request.setURI(URI.create("http://www.foo.example/bar"));
|
||||
|
||||
MockRestRequestMatchers.requestToUriTemplate("http://www.foo.example/{bar}", "bar").match(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestToNoMatch() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/bar"));
|
||||
void requestToNoMatch() {
|
||||
this.request.setURI(URI.create("http://www.foo.example/bar"));
|
||||
|
||||
assertThatThrownBy(
|
||||
() -> MockRestRequestMatchers.requestTo("http://www.foo.example/wrong").match(this.request))
|
||||
|
@ -65,21 +65,21 @@ public class MockRestRequestMatchersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void requestToContains() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/bar"));
|
||||
void requestToContains() throws Exception {
|
||||
this.request.setURI(URI.create("http://www.foo.example/bar"));
|
||||
|
||||
MockRestRequestMatchers.requestTo(containsString("bar")).match(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void method() throws Exception {
|
||||
void method() throws Exception {
|
||||
this.request.setMethod(HttpMethod.GET);
|
||||
|
||||
MockRestRequestMatchers.method(HttpMethod.GET).match(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodNoMatch() throws Exception {
|
||||
void methodNoMatch() {
|
||||
this.request.setMethod(HttpMethod.POST);
|
||||
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.method(HttpMethod.GET).match(this.request))
|
||||
|
@ -88,14 +88,14 @@ public class MockRestRequestMatchersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void header() throws Exception {
|
||||
void header() throws Exception {
|
||||
this.request.getHeaders().put("foo", Arrays.asList("bar", "baz"));
|
||||
|
||||
MockRestRequestMatchers.header("foo", "bar", "baz").match(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headerDoesNotExist() throws Exception {
|
||||
void headerDoesNotExist() throws Exception {
|
||||
MockRestRequestMatchers.headerDoesNotExist(null).match(this.request);
|
||||
MockRestRequestMatchers.headerDoesNotExist("").match(this.request);
|
||||
MockRestRequestMatchers.headerDoesNotExist("foo").match(this.request);
|
||||
|
@ -108,14 +108,14 @@ public class MockRestRequestMatchersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headerMissing() throws Exception {
|
||||
void headerMissing() {
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.header("foo", "bar").match(this.request))
|
||||
.isInstanceOf(AssertionError.class)
|
||||
.hasMessageContaining("was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headerMissingValue() throws Exception {
|
||||
void headerMissingValue() {
|
||||
this.request.getHeaders().put("foo", Arrays.asList("bar", "baz"));
|
||||
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.header("foo", "bad").match(this.request))
|
||||
|
@ -124,21 +124,21 @@ public class MockRestRequestMatchersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headerContains() throws Exception {
|
||||
void headerContains() throws Exception {
|
||||
this.request.getHeaders().put("foo", Arrays.asList("bar", "baz"));
|
||||
|
||||
MockRestRequestMatchers.header("foo", containsString("ba")).match(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headerContainsWithMissingHeader() throws Exception {
|
||||
void headerContainsWithMissingHeader() {
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.header("foo", containsString("baz")).match(this.request))
|
||||
.isInstanceOf(AssertionError.class)
|
||||
.hasMessageContaining("but was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headerContainsWithMissingValue() throws Exception {
|
||||
void headerContainsWithMissingValue() {
|
||||
this.request.getHeaders().put("foo", Arrays.asList("bar", "baz"));
|
||||
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.header("foo", containsString("bx")).match(this.request))
|
||||
|
@ -147,21 +147,21 @@ public class MockRestRequestMatchersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void headers() throws Exception {
|
||||
void headers() throws Exception {
|
||||
this.request.getHeaders().put("foo", Arrays.asList("bar", "baz"));
|
||||
|
||||
MockRestRequestMatchers.header("foo", "bar", "baz").match(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headersWithMissingHeader() throws Exception {
|
||||
void headersWithMissingHeader() {
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.header("foo", "bar").match(this.request))
|
||||
.isInstanceOf(AssertionError.class)
|
||||
.hasMessageContaining("but was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headersWithMissingValue() throws Exception {
|
||||
void headersWithMissingValue() {
|
||||
this.request.getHeaders().put("foo", Collections.singletonList("bar"));
|
||||
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.header("foo", "bar", "baz").match(this.request))
|
||||
|
@ -170,15 +170,15 @@ public class MockRestRequestMatchersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void queryParam() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/a?foo=bar&foo=baz"));
|
||||
void queryParam() throws Exception {
|
||||
this.request.setURI(URI.create("http://www.foo.example/a?foo=bar&foo=baz"));
|
||||
|
||||
MockRestRequestMatchers.queryParam("foo", "bar", "baz").match(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParamMissing() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/a"));
|
||||
void queryParamMissing() {
|
||||
this.request.setURI(URI.create("http://www.foo.example/a"));
|
||||
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.queryParam("foo", "bar").match(this.request))
|
||||
.isInstanceOf(AssertionError.class)
|
||||
|
@ -186,8 +186,8 @@ public class MockRestRequestMatchersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void queryParamMissingValue() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/a?foo=bar&foo=baz"));
|
||||
void queryParamMissingValue() {
|
||||
this.request.setURI(URI.create("http://www.foo.example/a?foo=bar&foo=baz"));
|
||||
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.queryParam("foo", "bad").match(this.request))
|
||||
.isInstanceOf(AssertionError.class)
|
||||
|
@ -195,15 +195,15 @@ public class MockRestRequestMatchersTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void queryParamContains() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/a?foo=bar&foo=baz"));
|
||||
void queryParamContains() throws Exception {
|
||||
this.request.setURI(URI.create("http://www.foo.example/a?foo=bar&foo=baz"));
|
||||
|
||||
MockRestRequestMatchers.queryParam("foo", containsString("ba")).match(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParamContainsWithMissingValue() throws Exception {
|
||||
this.request.setURI(new URI("http://www.foo.example/a?foo=bar&foo=baz"));
|
||||
void queryParamContainsWithMissingValue() {
|
||||
this.request.setURI(URI.create("http://www.foo.example/a?foo=bar&foo=baz"));
|
||||
|
||||
assertThatThrownBy(() -> MockRestRequestMatchers.queryParam("foo", containsString("bx")).match(this.request))
|
||||
.isInstanceOf(AssertionError.class)
|
||||
|
|
|
@ -71,7 +71,7 @@ class ResponseCreatorsTests {
|
|||
|
||||
@Test
|
||||
void created() throws Exception {
|
||||
URI location = new URI("/foo");
|
||||
URI location = URI.create("/foo");
|
||||
DefaultResponseCreator responseCreator = MockRestResponseCreators.withCreatedEntity(location);
|
||||
MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
@ -17,15 +17,12 @@
|
|||
package org.springframework.test.web.client.samples.matchers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.test.web.Person;
|
||||
|
@ -42,31 +39,24 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class HeaderRequestMatchersIntegrationTests {
|
||||
class HeaderRequestMatchersIntegrationTests {
|
||||
|
||||
private static final String RESPONSE_BODY = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
private MockRestServiceServer mockServer;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
private final MockRestServiceServer mockServer = MockRestServiceServer.createServer(this.restTemplate);
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
converters.add(new MappingJackson2HttpMessageConverter());
|
||||
|
||||
this.restTemplate = new RestTemplate();
|
||||
this.restTemplate.setMessageConverters(converters);
|
||||
|
||||
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
|
||||
void setup() {
|
||||
this.restTemplate.setMessageConverters(
|
||||
List.of(new StringHttpMessageConverter(), new MappingJackson2HttpMessageConverter()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testString() throws Exception {
|
||||
void testString() {
|
||||
this.mockServer.expect(requestTo("/person/1"))
|
||||
.andExpect(header("Accept", "application/json, application/*+json"))
|
||||
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));
|
||||
|
@ -75,7 +65,7 @@ public class HeaderRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testStringContains() throws Exception {
|
||||
void testStringContains() {
|
||||
this.mockServer.expect(requestTo("/person/1"))
|
||||
.andExpect(header("Accept", containsString("json")))
|
||||
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));
|
||||
|
@ -83,8 +73,8 @@ public class HeaderRequestMatchersIntegrationTests {
|
|||
executeAndVerify();
|
||||
}
|
||||
|
||||
private void executeAndVerify() throws URISyntaxException {
|
||||
this.restTemplate.getForObject(new URI("/person/1"), Person.class);
|
||||
private void executeAndVerify() {
|
||||
this.restTemplate.getForObject(URI.create("/person/1"), Person.class);
|
||||
this.mockServer.verify();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.test.web.client.samples.matchers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
|
@ -51,7 +50,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
|||
* @see org.springframework.test.web.client.match.JsonPathRequestMatchers
|
||||
* @see org.springframework.test.web.client.match.JsonPathRequestMatchersTests
|
||||
*/
|
||||
public class JsonPathRequestMatchersIntegrationTests {
|
||||
class JsonPathRequestMatchersIntegrationTests {
|
||||
|
||||
private static final MultiValueMap<String, Person> people = new LinkedMultiValueMap<>();
|
||||
|
||||
|
@ -72,7 +71,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
|
||||
|
||||
@Test
|
||||
public void exists() throws Exception {
|
||||
void exists() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.composers[0]").exists())
|
||||
|
@ -85,7 +84,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void doesNotExist() throws Exception {
|
||||
void doesNotExist() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.composers[?(@.name == 'Edvard Grieeeeeeg')]").doesNotExist())
|
||||
|
@ -97,7 +96,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void value() throws Exception {
|
||||
void value() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.composers[0].name").value("Johann Sebastian Bach"))
|
||||
|
@ -108,7 +107,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void hamcrestMatchers() throws Exception {
|
||||
void hamcrestMatchers() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.composers[0].name").value(equalTo("Johann Sebastian Bach")))
|
||||
|
@ -124,7 +123,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void hamcrestMatchersWithParameterizedJsonPaths() throws Exception {
|
||||
void hamcrestMatchersWithParameterizedJsonPaths() {
|
||||
String composerName = "$.composers[%s].name";
|
||||
String performerName = "$.performers[%s].name";
|
||||
|
||||
|
@ -140,7 +139,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void isArray() throws Exception {
|
||||
void isArray() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.composers").isArray())
|
||||
|
@ -150,7 +149,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void isString() throws Exception {
|
||||
void isString() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.composers[0].name").isString())
|
||||
|
@ -160,7 +159,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void isNumber() throws Exception {
|
||||
void isNumber() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.composers[0].someDouble").isNumber())
|
||||
|
@ -170,7 +169,7 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void isBoolean() throws Exception {
|
||||
void isBoolean() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/json"))
|
||||
.andExpect(jsonPath("$.composers[0].someBoolean").isBoolean())
|
||||
|
@ -179,8 +178,8 @@ public class JsonPathRequestMatchersIntegrationTests {
|
|||
executeAndVerify();
|
||||
}
|
||||
|
||||
private void executeAndVerify() throws URISyntaxException {
|
||||
this.restTemplate.put(new URI("/composers"), people);
|
||||
private void executeAndVerify() {
|
||||
this.restTemplate.put(URI.create("/composers"), people);
|
||||
this.mockServer.verify();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.test.web.client.samples.matchers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -48,7 +47,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
|||
* @see ContentRequestMatchersIntegrationTests
|
||||
* @see XpathRequestMatchersIntegrationTests
|
||||
*/
|
||||
public class XmlContentRequestMatchersIntegrationTests {
|
||||
class XmlContentRequestMatchersIntegrationTests {
|
||||
|
||||
private static final String PEOPLE_XML =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
|
||||
|
@ -68,7 +67,7 @@ public class XmlContentRequestMatchersIntegrationTests {
|
|||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
void setup() {
|
||||
List<Person> composers = Arrays.asList(
|
||||
new Person("Johann Sebastian Bach").setSomeDouble(21),
|
||||
new Person("Johannes Brahms").setSomeDouble(.0025),
|
||||
|
@ -87,7 +86,7 @@ public class XmlContentRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testXmlEqualTo() throws Exception {
|
||||
void testXmlEqualTo() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/xml"))
|
||||
.andExpect(content().xml(PEOPLE_XML))
|
||||
|
@ -97,7 +96,7 @@ public class XmlContentRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testHamcrestNodeMatcher() throws Exception {
|
||||
void testHamcrestNodeMatcher() {
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/xml"))
|
||||
.andExpect(content().node(hasXPath("/people/composers/composer[1]")))
|
||||
|
@ -106,8 +105,8 @@ public class XmlContentRequestMatchersIntegrationTests {
|
|||
executeAndVerify();
|
||||
}
|
||||
|
||||
private void executeAndVerify() throws URISyntaxException {
|
||||
this.restTemplate.put(new URI("/composers"), this.people);
|
||||
private void executeAndVerify() {
|
||||
this.restTemplate.put(URI.create("/composers"), this.people);
|
||||
this.mockServer.verify();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
@ -191,7 +191,7 @@ public class XpathRequestMatchersIntegrationTests {
|
|||
}
|
||||
|
||||
private void executeAndVerify() throws URISyntaxException {
|
||||
this.restTemplate.put(new URI("/composers"), this.people);
|
||||
this.restTemplate.put(URI.create("/composers"), this.people);
|
||||
this.mockServer.verify();
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ class MockHttpServletRequestBuilderTests {
|
|||
|
||||
@Test // SPR-13435
|
||||
void requestUriWithDoubleSlashes() throws URISyntaxException {
|
||||
this.builder = new MockHttpServletRequestBuilder(GET, new URI("/test//currentlyValid/0"));
|
||||
this.builder = new MockHttpServletRequestBuilder(GET, URI.create("/test//currentlyValid/0"));
|
||||
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
|
||||
|
||||
assertThat(request.getRequestURI()).isEqualTo("/test//currentlyValid/0");
|
||||
|
|
|
@ -176,7 +176,7 @@ class PrintingResultHandlerTests {
|
|||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("header", "headerValue");
|
||||
headers.setContentType(MediaType.TEXT_PLAIN);
|
||||
headers.setLocation(new URI("/redirectFoo"));
|
||||
headers.setLocation(URI.create("/redirectFoo"));
|
||||
headers.put("Set-Cookie", cookieValues);
|
||||
|
||||
String heading = "MockHttpServletResponse";
|
||||
|
|
Loading…
Reference in New Issue