@ -36,8 +36,10 @@ public class JsonPathExpectationsHelperTests {
@@ -36,8 +36,10 @@ public class JsonPathExpectationsHelperTests {
"'num': 5, " + //
"'bool': true, " + //
"'arr': [42], " + //
"'emptyArray': [], " + //
"'colorMap': {'red': 'rojo'}, " + //
"'whitespace': ' ', " + //
"'emptyString': '', " + //
"'emptyArray': [], " + //
"'emptyMap': {} " + //
"}" ;
@ -113,8 +115,106 @@ public class JsonPathExpectationsHelperTests {
@@ -113,8 +115,106 @@ public class JsonPathExpectationsHelperTests {
@Test
public void doesNotExistForIndefinatePathWithEmptyResults ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.familyMembers[?(@.name == 'Dilbert')]" ) . doesNotExist ( SIMPSONS ) ;
}
@Test
public void assertValueIsEmptyForAnEmptyString ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.emptyString" ) . assertValueIsEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsEmptyForAnEmptyArray ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.emptyArray" ) . assertValueIsEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsEmptyForAnEmptyMap ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.emptyMap" ) . assertValueIsEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsEmptyForIndefinatePathWithEmptyResults ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.familyMembers[?(@.name == 'Dilbert')]" ) . assertValueIsEmpty ( SIMPSONS ) ;
}
@Test
public void assertValueIsEmptyForIndefinatePathWithResults ( ) throws Exception {
String expression = "$.familyMembers[?(@.name == 'Bart')]" ;
exception . expect ( AssertionError . class ) ;
exception . expectMessage ( "Expected an empty value at JSON path \"" + expression
+ "\" but found: [{\"name\":\"Bart\"}]" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsEmpty ( SIMPSONS ) ;
}
@Test
public void assertValueIsEmptyForWhitespace ( ) throws Exception {
String expression = "$.whitespace" ;
exception . expect ( AssertionError . class ) ;
exception . expectMessage ( "Expected an empty value at JSON path \"" + expression + "\" but found: ' '" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsNotEmptyForString ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.str" ) . assertValueIsNotEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsNotEmptyForNumber ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.num" ) . assertValueIsNotEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsNotEmptyForBoolean ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.bool" ) . assertValueIsNotEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsNotEmptyForArray ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.arr" ) . assertValueIsNotEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsNotEmptyForMap ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.colorMap" ) . assertValueIsNotEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsNotEmptyForIndefinatePathWithResults ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.familyMembers[?(@.name == 'Bart')]" ) . assertValueIsNotEmpty ( SIMPSONS ) ;
}
@Test
public void assertValueIsNotEmptyForIndefinatePathWithEmptyResults ( ) throws Exception {
String expression = "$.familyMembers[?(@.name == 'Dilbert')]" ;
new JsonPathExpectationsHelper ( expression ) . doesNotExist ( SIMPSONS ) ;
exception . expect ( AssertionError . class ) ;
exception . expectMessage ( "Expected a non-empty value at JSON path \"" + expression + "\" but found: []" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsNotEmpty ( SIMPSONS ) ;
}
@Test
public void assertValueIsNotEmptyForAnEmptyString ( ) throws Exception {
String expression = "$.emptyString" ;
exception . expect ( AssertionError . class ) ;
exception . expectMessage ( "Expected a non-empty value at JSON path \"" + expression + "\" but found: ''" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsNotEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsNotEmptyForAnEmptyArray ( ) throws Exception {
String expression = "$.emptyArray" ;
exception . expect ( AssertionError . class ) ;
exception . expectMessage ( "Expected a non-empty value at JSON path \"" + expression + "\" but found: []" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsNotEmpty ( CONTENT ) ;
}
@Test
public void assertValueIsNotEmptyForAnEmptyMap ( ) throws Exception {
String expression = "$.emptyMap" ;
exception . expect ( AssertionError . class ) ;
exception . expectMessage ( "Expected a non-empty value at JSON path \"" + expression + "\" but found: {}" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsNotEmpty ( CONTENT ) ;
}
@Test
@ -134,10 +234,17 @@ public class JsonPathExpectationsHelperTests {
@@ -134,10 +234,17 @@ public class JsonPathExpectationsHelperTests {
new JsonPathExpectationsHelper ( "$.str" ) . assertValueIsString ( CONTENT ) ;
}
@Test
public void assertValueIsStringForAnEmptyString ( ) throws Exception {
new JsonPathExpectationsHelper ( "$.emptyString" ) . assertValueIsString ( CONTENT ) ;
}
@Test
public void assertValueIsStringForNonString ( ) throws Exception {
String expression = "$.bool" ;
exception . expect ( AssertionError . class ) ;
new JsonPathExpectationsHelper ( "$.bool" ) . assertValueIsString ( CONTENT ) ;
exception . expectMessage ( "Expected a string at JSON path \"" + expression + "\" but found: true" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsString ( CONTENT ) ;
}
@Test
@ -147,8 +254,10 @@ public class JsonPathExpectationsHelperTests {
@@ -147,8 +254,10 @@ public class JsonPathExpectationsHelperTests {
@Test
public void assertValueIsNumberForNonNumber ( ) throws Exception {
String expression = "$.bool" ;
exception . expect ( AssertionError . class ) ;
new JsonPathExpectationsHelper ( "$.bool" ) . assertValueIsNumber ( CONTENT ) ;
exception . expectMessage ( "Expected a number at JSON path \"" + expression + "\" but found: true" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsNumber ( CONTENT ) ;
}
@Test
@ -158,8 +267,10 @@ public class JsonPathExpectationsHelperTests {
@@ -158,8 +267,10 @@ public class JsonPathExpectationsHelperTests {
@Test
public void assertValueIsBooleanForNonBoolean ( ) throws Exception {
String expression = "$.num" ;
exception . expect ( AssertionError . class ) ;
new JsonPathExpectationsHelper ( "$.num" ) . assertValueIsBoolean ( CONTENT ) ;
exception . expectMessage ( "Expected a boolean at JSON path \"" + expression + "\" but found: 5" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsBoolean ( CONTENT ) ;
}
@Test
@ -174,8 +285,10 @@ public class JsonPathExpectationsHelperTests {
@@ -174,8 +285,10 @@ public class JsonPathExpectationsHelperTests {
@Test
public void assertValueIsArrayForNonArray ( ) throws Exception {
String expression = "$.str" ;
exception . expect ( AssertionError . class ) ;
new JsonPathExpectationsHelper ( "$.str" ) . assertValueIsArray ( CONTENT ) ;
exception . expectMessage ( "Expected an array at JSON path \"" + expression + "\" but found: 'foo'" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsArray ( CONTENT ) ;
}
@Test
@ -190,8 +303,10 @@ public class JsonPathExpectationsHelperTests {
@@ -190,8 +303,10 @@ public class JsonPathExpectationsHelperTests {
@Test
public void assertValueIsMapForNonMap ( ) throws Exception {
String expression = "$.str" ;
exception . expect ( AssertionError . class ) ;
new JsonPathExpectationsHelper ( "$.str" ) . assertValueIsMap ( CONTENT ) ;
exception . expectMessage ( "Expected a map at JSON path \"" + expression + "\" but found: 'foo'" ) ;
new JsonPathExpectationsHelper ( expression ) . assertValueIsMap ( CONTENT ) ;
}
}