Skip to content

Commit

Permalink
Add more tests to BigqueyGsonBuilderTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristiaan committed Aug 28, 2023
1 parent 2f66f66 commit eee719c
Showing 1 changed file with 27 additions and 1 deletion.
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());
}
}
}

0 comments on commit eee719c

Please sign in to comment.