From eee719c07bfe5155559d4cf6e251db90fec3c5a3 Mon Sep 17 00:00:00 2001 From: kristiaan Date: Mon, 28 Aug 2023 07:47:47 +0200 Subject: [PATCH] Add more tests to BigqueyGsonBuilderTest. --- .../rules/BigqueryGsonBuilderTest.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/schema-util/bigquery/src/test/java/io/apicurio/registry/rules/BigqueryGsonBuilderTest.java b/schema-util/bigquery/src/test/java/io/apicurio/registry/rules/BigqueryGsonBuilderTest.java index b81c910fa6..3493c4c337 100644 --- a/schema-util/bigquery/src/test/java/io/apicurio/registry/rules/BigqueryGsonBuilderTest.java +++ b/schema-util/bigquery/src/test/java/io/apicurio/registry/rules/BigqueryGsonBuilderTest.java @@ -1,14 +1,30 @@ package io.apicurio.registry.rules; +import com.google.cloud.bigquery.Field; +import com.google.cloud.bigquery.FieldList; +import com.google.gson.JsonSyntaxException; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class BigqueryGsonBuilderTest { + private final BigqueryGsonBuilder gsonBuilder = new BigqueryGsonBuilder(); + @Test public void testParse() { - BigqueryGsonBuilder gsonBuilder = new BigqueryGsonBuilder(); + FieldList fieldList = gsonBuilder.parseFields("[{\"name\":\"id\",\"type\":\"STRING\",\"mode\":\"NULLABLE\"}]"); + assertEquals(Field.Mode.NULLABLE, fieldList.get(0).getMode()); + } + + @Test + public void testParse_other_content() { + FieldList fieldList = gsonBuilder.parseFields("[{\"name\":\"id\",\"type\":\"STRING\",\"count\":1}]"); + assertNull(fieldList.get(0).getMode()); + } + + @Test + public void testParse_illegal_argument() { try { gsonBuilder.parseFields("[{\"name\":\"id\",\"type\":\"STRING\",\"mode\":\"NULLEABLE\"}]"); fail("Exception expected"); @@ -16,4 +32,14 @@ public void testParse() { assertEquals("No enum constant com.google.cloud.bigquery.Field.Mode.NULLEABLE", e.getMessage()); } } + + @Test + public void testParse_no_json() { + try { + gsonBuilder.parseFields("phgp'çàh'nmslenb"); + fail("Exception expected"); + } catch (JsonSyntaxException e) { + assertEquals("java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $", e.getMessage()); + } + } } \ No newline at end of file