From 1d1c3a8c26038d96d4afb7ca7e6c141312ec9f02 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Wed, 18 Sep 2024 16:54:49 -0700 Subject: [PATCH] Some fixes in QueryStatsTest. --- .../com/fauna/response/QueryResponseTest.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/test/java/com/fauna/response/QueryResponseTest.java b/src/test/java/com/fauna/response/QueryResponseTest.java index 7fd33a04..afbaf835 100644 --- a/src/test/java/com/fauna/response/QueryResponseTest.java +++ b/src/test/java/com/fauna/response/QueryResponseTest.java @@ -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; @@ -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); @@ -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 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')")); - } - } \ No newline at end of file