Skip to content

Commit

Permalink
Some fixes in QueryStatsTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Griffin committed Sep 19, 2024
1 parent 46f65a7 commit 1d1c3a8
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/test/java/com/fauna/response/QueryResponseTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.fauna.response;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -62,7 +64,7 @@ public void getFromResponseBody_Success() throws IOException {
}

@Test
public void handleResponseWithInvalidJsonThrowsProtocolException() {
public void handleResponseWithInvalidJsonThrowsClientResponseException() {
HttpResponse resp = mockResponse("{\"not valid json\"");
when(resp.statusCode()).thenReturn(400);

Expand All @@ -71,23 +73,15 @@ public void handleResponseWithInvalidJsonThrowsProtocolException() {
}

@Test
public void handleResponseWithMissingStatsThrowsProtocolException() {
HttpResponse resp = mockResponse("{\"not valid json\"");
assertThrows(ClientResponseException.class, () -> QueryResponse.parseResponse(resp, codecProvider.get(Object.class)));
public void handleResponseWithEmptyFieldsDoesNotThrow() {
HttpResponse resp = mockResponse("{}");
QuerySuccess<Object> response = QueryResponse.parseResponse(resp, codecProvider.get(Object.class));
assertEquals(QuerySuccess.class, response.getClass());
assertNull(response.getSchemaVersion());
assertNull(response.getSummary());
assertNull(response.getLastSeenTxn());
assertNull(response.getQueryTags());
assertNull(response.getData());
assertNull(response.getStats());
}

@Test
void getFromResponseBody_Exception() {
String body = "Invalid JSON";

// TODO call FaunaClient.handleResponse here.
CodecException exception = assertThrows(CodecException.class, () -> {
throw new CodecException("Error occurred while parsing the response body");
});

assertEquals("Error occurred while parsing the response body", exception.getMessage());
// assertTrue(exception.getCause().getMessage().contains(
// "Unrecognized token 'Invalid': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')"));
}

}

0 comments on commit 1d1c3a8

Please sign in to comment.