Clean up warnings and polish tests

This commit is contained in:
Sam Brannen
2015-06-19 14:57:28 +01:00
parent 20a1474554
commit 23547a72f3
3 changed files with 75 additions and 65 deletions

View File

@@ -13,17 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.web.servlet.result;
import java.nio.charset.Charset;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.StubMvcResult;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
/**
* Tests for {@link XpathResultMatchers}.
@@ -33,77 +34,77 @@ import org.springframework.util.StringUtils;
public class XpathResultMatchersTests {
@Test
public void testNodeMatcher() throws Exception {
public void node() throws Exception {
new XpathResultMatchers("/foo/bar", null).node(Matchers.notNullValue()).match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void testNodeMatcherNoMatch() throws Exception {
@Test(expected = AssertionError.class)
public void nodeNoMatch() throws Exception {
new XpathResultMatchers("/foo/bar", null).node(Matchers.nullValue()).match(getStubMvcResult());
}
@Test
public void testExists() throws Exception {
public void exists() throws Exception {
new XpathResultMatchers("/foo/bar", null).exists().match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void testExistsNoMatch() throws Exception {
@Test(expected = AssertionError.class)
public void existsNoMatch() throws Exception {
new XpathResultMatchers("/foo/Bar", null).exists().match(getStubMvcResult());
}
@Test
public void testDoesNotExist() throws Exception {
public void doesNotExist() throws Exception {
new XpathResultMatchers("/foo/Bar", null).doesNotExist().match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void testDoesNotExistNoMatch() throws Exception {
@Test(expected = AssertionError.class)
public void doesNotExistNoMatch() throws Exception {
new XpathResultMatchers("/foo/bar", null).doesNotExist().match(getStubMvcResult());
}
@Test
public void testNodeCount() throws Exception {
public void nodeCount() throws Exception {
new XpathResultMatchers("/foo/bar", null).nodeCount(2).match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void testNodeCountNoMatch() throws Exception {
@Test(expected = AssertionError.class)
public void nodeCountNoMatch() throws Exception {
new XpathResultMatchers("/foo/bar", null).nodeCount(1).match(getStubMvcResult());
}
@Test
public void testString() throws Exception {
public void string() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).string("111").match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void testStringNoMatch() throws Exception {
@Test(expected = AssertionError.class)
public void stringNoMatch() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).string("112").match(getStubMvcResult());
}
@Test
public void testNumber() throws Exception {
public void number() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).number(111.0).match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void testNumberNoMatch() throws Exception {
@Test(expected = AssertionError.class)
public void numberNoMatch() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).number(111.1).match(getStubMvcResult());
}
@Test
public void testBoolean() throws Exception {
public void booleanValue() throws Exception {
new XpathResultMatchers("/foo/bar[2]", null).booleanValue(true).match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void testBooleanNoMatch() throws Exception {
@Test(expected = AssertionError.class)
public void booleanValueNoMatch() throws Exception {
new XpathResultMatchers("/foo/bar[2]", null).booleanValue(false).match(getStubMvcResult());
}
@Test
public void testStringEncodingDetection() throws Exception {
public void stringEncodingDetection() throws Exception {
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<person><name>Jürgen</name></person>";
byte[] bytes = content.getBytes(Charset.forName("UTF-8"));