@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2015 the original author or authors .
* Copyright 2002 - 2018 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -18,6 +18,8 @@ package org.springframework.test.web.client.match;
import java.io.IOException ;
import java.io.IOException ;
import org.hamcrest.Matchers ;
import org.junit.Test ;
import org.junit.Test ;
import org.springframework.mock.http.client.MockClientHttpRequest ;
import org.springframework.mock.http.client.MockClientHttpRequest ;
@ -55,14 +57,19 @@ public class JsonPathRequestMatchersTests {
}
}
@Test ( expected = AssertionError . class )
public void valueWithMismatch ( ) throws Exception {
new JsonPathRequestMatchers ( "$.str" ) . value ( "bogus" ) . match ( request ) ;
}
@Test
@Test
public void value ( ) throws Exception {
public void valueWithDirectMatch ( ) throws Exception {
new JsonPathRequestMatchers ( "$.str" ) . value ( "foo" ) . match ( request ) ;
new JsonPathRequestMatchers ( "$.str" ) . value ( "foo" ) . match ( request ) ;
}
}
@Test ( expected = AssertionError . class )
@Test // SPR-14498
public void valueNoMatch ( ) throws Exception {
public void valueWithNumberConversion ( ) throws Exception {
new JsonPathRequestMatchers ( "$.str " ) . value ( "bogus" ) . match ( request ) ;
new JsonPathRequestMatchers ( "$.num " ) . value ( 5 . 0f ) . match ( request ) ;
}
}
@Test
@Test
@ -70,8 +77,13 @@ public class JsonPathRequestMatchersTests {
new JsonPathRequestMatchers ( "$.str" ) . value ( equalTo ( "foo" ) ) . match ( request ) ;
new JsonPathRequestMatchers ( "$.str" ) . value ( equalTo ( "foo" ) ) . match ( request ) ;
}
}
@Test // SPR-14498
public void valueWithMatcherAndNumberConversion ( ) throws Exception {
new JsonPathRequestMatchers ( "$.num" ) . value ( Matchers . equalTo ( 5 . 0f ) , Float . class ) . match ( request ) ;
}
@Test ( expected = AssertionError . class )
@Test ( expected = AssertionError . class )
public void valueWithMatcherNoMatch ( ) throws Exception {
public void valueWithMatcherAndMism atch ( ) throws Exception {
new JsonPathRequestMatchers ( "$.str" ) . value ( equalTo ( "bogus" ) ) . match ( request ) ;
new JsonPathRequestMatchers ( "$.str" ) . value ( equalTo ( "bogus" ) ) . match ( request ) ;
}
}