Polishing

This commit is contained in:
Sam Brannen
2015-08-14 22:45:10 +02:00
parent 07bb0378b9
commit d4d5e5ce40
8 changed files with 62 additions and 64 deletions

View File

@@ -32,21 +32,21 @@ import static org.hamcrest.CoreMatchers.*;
public class JsonPathExpectationsHelperTests {
private static final String CONTENT = "{" + //
"\"str\": \"foo\", " + //
"\"num\": 5, " + //
"\"bool\": true, " + //
"\"arr\": [\"bar\"], " + //
"\"emptyArray\": [], " + //
"\"colorMap\": {\"red\": \"rojo\"}, " + //
"\"emptyMap\": {} " + //
"'str': 'foo', " + //
"'num': 5, " + //
"'bool': true, " + //
"'arr': [42], " + //
"'emptyArray': [], " + //
"'colorMap': {'red': 'rojo'}, " + //
"'emptyMap': {} " + //
"}";
private static final String SIMPSONS = "{ \"familyMembers\": [ " + //
"{\"name\": \"Homer\" }, " + //
"{\"name\": \"Marge\" }, " + //
"{\"name\": \"Bart\" }, " + //
"{\"name\": \"Lisa\" }, " + //
"{\"name\": \"Maggie\"} " + //
private static final String SIMPSONS = "{ 'familyMembers': [ " + //
"{'name': 'Homer' }, " + //
"{'name': 'Marge' }, " + //
"{'name': 'Bart' }, " + //
"{'name': 'Lisa' }, " + //
"{'name': 'Maggie'} " + //
" ] }";
@Rule

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.web.client.match;
import java.io.IOException;
@@ -24,20 +25,20 @@ import org.junit.Test;
import org.springframework.mock.http.client.MockClientHttpRequest;
/**
* Tests for {@link JsonPathRequestMatchers}.
* Unit tests for {@link JsonPathRequestMatchers}.
*
* @author Rossen Stoyanchev
*/
public class JsonPathRequestMatchersTests {
private static final String RESPONSE_CONTENT = "{\"foo\":\"bar\", \"qux\":[\"baz1\",\"baz2\"]}";
private static final String REQUEST_CONTENT = "{ 'foo': 'bar', 'qux': ['baz1', 'baz2'] }";
private MockClientHttpRequest request;
@Before
public void setUp() throws IOException {
this.request = new MockClientHttpRequest();
this.request.getBody().write(RESPONSE_CONTENT.getBytes());
this.request.getBody().write(REQUEST_CONTENT.getBytes());
}
@Test
@@ -45,7 +46,7 @@ public class JsonPathRequestMatchersTests {
new JsonPathRequestMatchers("$.foo").value("bar").match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void valueNoMatch() throws Exception {
new JsonPathRequestMatchers("$.foo").value("bogus").match(this.request);
}
@@ -55,7 +56,7 @@ public class JsonPathRequestMatchersTests {
new JsonPathRequestMatchers("$.foo").value(Matchers.equalTo("bar")).match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void valueMatcherNoMatch() throws Exception {
new JsonPathRequestMatchers("$.foo").value(Matchers.equalTo("bogus")).match(this.request);
}
@@ -65,7 +66,7 @@ public class JsonPathRequestMatchersTests {
new JsonPathRequestMatchers("$.foo").exists().match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void existsNoMatch() throws Exception {
new JsonPathRequestMatchers("$.bogus").exists().match(this.request);
}
@@ -75,7 +76,7 @@ public class JsonPathRequestMatchersTests {
new JsonPathRequestMatchers("$.bogus").doesNotExist().match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void doesNotExistNoMatch() throws Exception {
new JsonPathRequestMatchers("$.foo").doesNotExist().match(this.request);
}
@@ -85,7 +86,7 @@ public class JsonPathRequestMatchersTests {
new JsonPathRequestMatchers("$.qux").isArray().match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void isArrayNoMatch() throws Exception {
new JsonPathRequestMatchers("$.bar").isArray().match(this.request);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.web.client.match;
import java.net.URI;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.HttpMethod;
@@ -27,19 +27,15 @@ import org.springframework.mock.http.client.MockClientHttpRequest;
import static org.hamcrest.Matchers.*;
/**
* Tests for {@link MockRestRequestMatchers}.
* Unit tests for {@link MockRestRequestMatchers}.
*
* @author Craig Walls
* @author Rossen Stoyanchev
*/
public class RequestMatchersTests {
private MockClientHttpRequest request;
private final MockClientHttpRequest request = new MockClientHttpRequest();
@Before
public void setUp() {
this.request = new MockClientHttpRequest();
}
@Test
public void requestTo() throws Exception {
@@ -48,7 +44,7 @@ public class RequestMatchersTests {
MockRestRequestMatchers.requestTo("http://foo.com/bar").match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void requestToNoMatch() throws Exception {
this.request.setURI(new URI("http://foo.com/bar"));
@@ -69,7 +65,7 @@ public class RequestMatchersTests {
MockRestRequestMatchers.method(HttpMethod.GET).match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void methodNoMatch() throws Exception {
this.request.setMethod(HttpMethod.POST);
@@ -83,12 +79,12 @@ public class RequestMatchersTests {
MockRestRequestMatchers.header("foo", "bar", "baz").match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void headerMissing() throws Exception {
MockRestRequestMatchers.header("foo", "bar").match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void headerMissingValue() throws Exception {
this.request.getHeaders().put("foo", Arrays.asList("bar", "baz"));
@@ -104,13 +100,13 @@ public class RequestMatchersTests {
}
@SuppressWarnings("unchecked")
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void headerContainsWithMissingHeader() throws Exception {
MockRestRequestMatchers.header("foo", containsString("baz")).match(this.request);
}
@SuppressWarnings("unchecked")
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void headerContainsWithMissingValue() throws Exception {
this.request.getHeaders().put("foo", Arrays.asList("bar", "baz"));
@@ -124,12 +120,12 @@ public class RequestMatchersTests {
MockRestRequestMatchers.header("foo", "bar", "baz").match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void headersWithMissingHeader() throws Exception {
MockRestRequestMatchers.header("foo", "bar").match(this.request);
}
@Test(expected=AssertionError.class)
@Test(expected = AssertionError.class)
public void headersWithMissingValue() throws Exception {
this.request.getHeaders().put("foo", Arrays.asList("bar"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.web.client.samples.matchers;
import java.net.URI;
@@ -37,9 +38,10 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
/**
* Examples of defining expectations on JSON request content with
* <a href="http://goessner.net/articles/JsonPath/">JSONPath</a> expressions.
* <a href="https://github.com/jayway/JsonPath">JsonPath</a> expressions.
*
* @author Rossen Stoyanchev
* @see org.springframework.test.web.client.match.JsonPathRequestMatchers
*/
public class JsonPathRequestMatcherTests {

View File

@@ -24,7 +24,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.StubMvcResult;
/**
* Tests for {@link JsonPathResultMatchers}.
* Unit tests for {@link JsonPathResultMatchers}.
*
* @author Rossen Stoyanchev
* @author Craig Andrews
@@ -32,7 +32,7 @@ import org.springframework.test.web.servlet.StubMvcResult;
*/
public class JsonPathResultMatchersTests {
private static final String RESPONSE_CONTENT = "{\"foo\": \"bar\", \"qux\": [\"baz\"], \"emptyArray\": [], \"icanhaz\": true, \"howmanies\": 5, \"cheeseburger\": {\"pickles\": true}, \"emptyMap\": {} }";
private static final String RESPONSE_CONTENT = "{'foo': 'bar', 'qux': ['baz'], 'emptyArray': [], 'icanhaz': true, 'howmanies': 5, 'cheeseburger': {'pickles': true}, 'emptyMap': {} }";
private static final StubMvcResult stubMvcResult;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -22,13 +22,12 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.test.web.Person;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
@@ -37,10 +36,9 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
/**
* Examples of defining expectations on JSON response content with
* <a href="http://goessner.net/articles/JsonPath/">JSONPath</a> expressions.
* <a href="https://github.com/jayway/JsonPath">JsonPath</a> expressions.
*
* @author Rossen Stoyanchev
*
* @see ContentAssertionTests
*/
public class JsonPathAssertionTests {
@@ -73,7 +71,6 @@ public class JsonPathAssertionTests {
.andExpect(jsonPath("$.composers[1]").exists())
.andExpect(jsonPath("$.composers[2]").exists())
.andExpect(jsonPath("$.composers[3]").exists());
}
@Test
@@ -120,11 +117,11 @@ public class JsonPathAssertionTests {
}
@Controller
@RestController
private class MusicController {
@RequestMapping(value="/music/people")
public @ResponseBody MultiValueMap<String, Person> get() {
@RequestMapping("/music/people")
public MultiValueMap<String, Person> get() {
MultiValueMap<String, Person> map = new LinkedMultiValueMap<String, Person>();
map.add("composers", new Person("Johann Sebastian Bach"));