2
2
3
3
import org .junit .Test ;
4
4
5
- import static com .jayway .jsonassert .JsonAssert .with ;
5
+ import static com .jayway .jsonassert .JsonAssert .* ;
6
6
import static org .hamcrest .Matchers .*;
7
7
8
8
/**
@@ -57,7 +57,8 @@ public void list_content_can_be_asserted_with_matcher() throws Exception {
57
57
58
58
with (JSON ).assertThat ("$..book[*].author" , hasItems ("Nigel Rees" , "Evelyn Waugh" , "Herman Melville" , "J. R. R. Tolkien" ));
59
59
60
- with (JSON ).assertThat ("$..author" , hasItems ("Nigel Rees" , "Evelyn Waugh" , "Herman Melville" , "J. R. R. Tolkien" ));
60
+ with (JSON ).assertThat ("$..author" , hasItems ("Nigel Rees" , "Evelyn Waugh" , "Herman Melville" , "J. R. R. Tolkien" ))
61
+ .assertThat ("$..author" , is (collectionWithSize (equalTo (4 ))));
61
62
}
62
63
63
64
@ Test
@@ -69,56 +70,25 @@ public void list_content_can_be_asserted_with_nested_matcher() throws Exception
69
70
public void map_content_can_be_asserted_with_matcher () throws Exception {
70
71
71
72
with (JSON ).assertThat ("$.store.book[0]" , hasEntry ("category" , "reference" ))
72
- .assertThat ("$.store.book[0]" , hasEntry ("title" , "Sayings of the Century" ));
73
-
74
- with (JSON ).assertThat ("$..book[0]" , hasItems (hasEntry ("category" , "reference" )));
75
- }
76
-
77
- @ Test
78
- public void a_path_can_be_asserted_equal_to () throws Exception {
79
-
80
- with (JSON ).assertEquals ("$.store.book[0].title" , "Sayings of the Century" )
81
- .assertThat ("$.store.book[0].title" , equalTo ("Sayings of the Century" ));
73
+ .assertThat ("$.store.book[0]" , hasEntry ("title" , "Sayings of the Century" ))
74
+ .and ()
75
+ .assertThat ("$..book[0]" , hasItems (hasEntry ("category" , "reference" )))
76
+ .and ()
77
+ .assertThat ("$.store.book[0]" , mapContainingKey (equalTo ("category" )))
78
+ .and ()
79
+ .assertThat ("$.store.book[0]" , mapContainingValue (equalTo ("reference" )));
82
80
}
83
81
84
-
85
- /*
86
82
@ Test
87
- public void a_sub_document_can_asserted_on__by_path () throws Exception {
88
- JsonAssert. with(TEST_DOCUMENT ).assertThat("subDocument.subField ", is(equalTo("sub-field") ));
83
+ public void an_empty_collection () throws Exception {
84
+ with (JSON ).assertThat ("$.store.book[?(@.category = 'x')] " , emptyCollection ( ));
89
85
}
90
86
91
87
@ Test
92
88
public void a_path_can_be_asserted_equal_to () throws Exception {
93
89
94
- JsonAssert.with(TEST_DOCUMENT).assertEquals("stringField", "string-field");
95
- }
96
-
97
- @Test
98
- public void a_path_can_be_asserted_is_null() throws Exception {
99
-
100
- JsonAssert.with(TEST_DOCUMENT).assertNull("nullField");
101
- }
102
-
103
- @Test(expected = AssertionError.class)
104
- public void failed_assert_throws() throws Exception {
105
-
106
- JsonAssert.with(TEST_DOCUMENT).assertThat("stringField", equalTo("SOME CRAP"));
107
- }
108
-
109
- @Test
110
- public void multiple_asserts_can_be_chained() throws Exception {
111
-
112
- JsonAssert.with(TEST_DOCUMENT)
113
- .assertThat("stringField", equalTo("string-field"))
114
- .assertThat("numberField", is(notNullValue()))
115
- .and()
116
- .assertNull("nullField")
117
- .and()
118
- .assertEquals("stringField", "string-field");
119
-
90
+ with (JSON ).assertEquals ("$.store.book[0].title" , "Sayings of the Century" )
91
+ .assertThat ("$.store.book[0].title" , equalTo ("Sayings of the Century" ));
120
92
}
121
- */
122
-
123
93
124
94
}
0 commit comments