forked from Apicurio/apicurio-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests to BigqueyGsonBuilderTest.
- Loading branch information
kristiaan
committed
Aug 28, 2023
1 parent
2f66f66
commit eee719c
Showing
1 changed file
with
27 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 27 additions & 1 deletion
28
schema-util/bigquery/src/test/java/io/apicurio/registry/rules/BigqueryGsonBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,45 @@ | ||
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"); | ||
} catch (IllegalArgumentException e) { | ||
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()); | ||
} | ||
} | ||
} |