16
16
package com .vonage .client ;
17
17
18
18
import com .fasterxml .jackson .annotation .JsonProperty ;
19
- import org . junit . jupiter . api .* ;
19
+ import com . vonage . client . common . HttpMethod ;
20
20
import static org .junit .jupiter .api .Assertions .*;
21
+ import org .junit .jupiter .api .*;
21
22
import java .util .List ;
22
23
import java .util .Map ;
23
24
@@ -79,7 +80,7 @@ public void testDelete() throws Exception {
79
80
stubResponse (204 );
80
81
client .delete (URL );
81
82
assertNull (client .delete (URL , (Object ) null ));
82
- assertNull ( client .delete (URL , (Object []) null ));
83
+ assertThrows ( NullPointerException . class , () -> client .delete (URL , (Object []) null ));
83
84
stubResponse (204 , PAYLOAD_STR );
84
85
TestResponse responseBody = client .delete (URL );
85
86
assertEquals (TEST_JSONABLE , responseBody );
@@ -110,7 +111,7 @@ public void testPost() throws Exception {
110
111
stubResponse (201 );
111
112
client .post (URL , TEST_JSONABLE );
112
113
assertNull (client .post (URL , TEST_JSONABLE , (Object ) null ));
113
- assertNull ( client .post (URL , TEST_JSONABLE , (Object []) null ));
114
+ assertThrows ( NullPointerException . class , () -> client .post (URL , TEST_JSONABLE , (Object []) null ));
114
115
stubResponse (PAYLOAD_STR );
115
116
responseBody = client .post (URL , (Jsonable ) null );
116
117
assertEquals (TEST_JSONABLE , responseBody );
@@ -129,7 +130,7 @@ public void testPut() throws Exception {
129
130
stubResponse (202 );
130
131
client .put (URL , TEST_JSONABLE );
131
132
assertNull (client .put (URL , TEST_JSONABLE , (Object ) null ));
132
- assertNull ( client .put (URL , TEST_JSONABLE , (Object []) null ));
133
+ assertThrows ( NullPointerException . class , () -> client .put (URL , TEST_JSONABLE , (Object []) null ));
133
134
stubResponse (409 );
134
135
assertThrows (VonageApiResponseException .class , () -> client .put (URL , TEST_JSONABLE ));
135
136
}
@@ -145,8 +146,39 @@ public void testPatch() throws Exception {
145
146
stubResponse (204 );
146
147
client .patch (URL , TEST_JSONABLE );
147
148
assertNull (client .patch (URL , TEST_JSONABLE , (Object ) null ));
148
- assertNull ( client .patch (URL , TEST_JSONABLE , (Object []) null ));
149
+ assertThrows ( NullPointerException . class , () -> client .patch (URL , TEST_JSONABLE , (Object []) null ));
149
150
stubResponse (406 );
150
151
assertThrows (VonageApiResponseException .class , () -> client .patch (URL , TEST_JSONABLE ));
151
152
}
153
+
154
+ @ Test
155
+ public void testVarResponse () throws Exception {
156
+ stubResponse (PAYLOAD_STR );
157
+ var var = client .makeRequest (HttpMethod .GET , URL , TEST_JSONABLE );
158
+ assertNull (var );
159
+ }
160
+
161
+ @ Test
162
+ public void testCollectionResponse () throws Exception {
163
+ stubResponse ("[ " + PAYLOAD_STR + ", {}]" );
164
+ List <Map <String , ?>> list = client .makeRequest (HttpMethod .GET , URL , TEST_JSONABLE );
165
+ assertNotNull (list );
166
+ assertEquals (2 , list .size ());
167
+ assertEquals (PAYLOAD_MAP , list .getFirst ());
168
+ assertEquals (Map .of (), list .get (1 ));
169
+ }
170
+
171
+ @ Test
172
+ public void testUnknownObjectResponse () throws Exception {
173
+ stubResponse (PAYLOAD_STR );
174
+ class MyClass {}
175
+ MyClass object = client .makeRequest (HttpMethod .GET , URL , TEST_JSONABLE );
176
+ assertNull (object );
177
+ }
178
+
179
+ @ Test
180
+ public void testUnassignedResponse () throws Exception {
181
+ stubResponse (PAYLOAD_STR );
182
+ client .makeRequest (HttpMethod .GET , URL , TEST_JSONABLE );
183
+ }
152
184
}
0 commit comments