From 736ff7e062ca72a4a4ae81f4360302b9af176bd9 Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Wed, 17 Jan 2024 14:25:19 -0300 Subject: [PATCH 1/5] Add TokenStream interface for Fauna serialization --- .../com/fauna/interfaces/TokenStream.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 faunaJava/src/main/java/com/fauna/interfaces/TokenStream.java diff --git a/faunaJava/src/main/java/com/fauna/interfaces/TokenStream.java b/faunaJava/src/main/java/com/fauna/interfaces/TokenStream.java new file mode 100644 index 00000000..b9f5e695 --- /dev/null +++ b/faunaJava/src/main/java/com/fauna/interfaces/TokenStream.java @@ -0,0 +1,111 @@ +package com.fauna.interfaces; + +import com.fauna.common.enums.TokenType; + +import java.io.IOException; +import java.time.Instant; +import java.time.LocalDate; + +/** + * Represents a stream of JSON tokens that can be read sequentially. + * This interface abstracts the process of iterating over a sequence of JSON tokens, + * typically obtained from a JSON parsing process. + */ +public interface TokenStream { + + /** + * Retrieves the next JSON token from the stream. + * + * @return The next JsonToken, or null if the end of the stream is reached. + */ + TokenType nextToken() throws IOException; + + /** + * Closes the token stream and releases any system resources associated with it. + * + * @throws IOException If an I/O error occurs. + */ + void close() throws IOException; + + /** + * Method that will try to convert value of current token to a String. JSON Strings map naturally; scalar values get converted to their textual representation. If representation can not be converted to a String value (including structured types like Objects and Arrays and null token), default value of null will be returned; no exceptions are thrown. + * + * @return String value current token is converted to, if possible; null otherwise + */ + String getValueAsString(); + + /** + * Method that will try to convert value of current token to a Java int value. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules. + * If representation can not be converted to an int (including structured type markers like start/end Object/Array) default value of 0 will be returned; no exceptions are thrown. + * + * @return int value current token is converted to, if possible; exception thrown otherwise + */ + int getValueAsInt(); + + /** + * Method that will try to convert value of current token to a long. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules. + * If representation can not be converted to a long (including structured type markers like start/end Object/Array) default value of 0L will be returned; no exceptions are thrown. + * + * @return long value current token is converted to, if possible; exception thrown otherwise + */ + long getValueAsLong(); + + /** + * Method that will try to convert value of current token to a Java + * double. + * Numbers are coerced using default Java rules; booleans convert to 0.0 (false) + * and 1.0 (true), and Strings are parsed using default Java language floating + * point parsing rules. + *

+ * If representation can not be converted to a double (including structured types + * like Objects and Arrays), + * default value of 0.0 will be returned; no exceptions are thrown. + * + * @return {@code double} value current token is converted to, if possible; exception thrown + * otherwise + */ + double getValueAsDouble(); + + /** + * Method that will try to convert value of current token to a + * boolean. + * JSON booleans map naturally; integer numbers other than 0 map to true, and + * 0 maps to false + * and Strings 'true' and 'false' map to corresponding values. + *

+ * If representation can not be converted to a boolean value (including structured types + * like Objects and Arrays), + * default value of false will be returned; no exceptions are thrown. + * + * @return {@code boolean} value current token is converted to, if possible; + */ + boolean getValueAsBoolean(); + + /** + * Method that will try to convert the value of the current token to a LocalDate. + * This method is applicable when the current token represents a date value in + * ISO-8601 format (e.g., "2023-11-20"). It attempts to parse the token's value + * as a LocalDate. + *

+ * If the current token's value is not a valid date representation, a runtime + * exception is thrown. + * + * @return LocalDate representing the value of the current token, if applicable. + * @throws RuntimeException if the current token's value cannot be converted to a LocalDate. + */ + LocalDate getValueAsDate(); + + /** + * Method that will try to convert the value of the current token to an Instant. + * This method is applicable when the current token represents a time value in + * ISO-8601 format (e.g., "2023-11-20T13:33:10.300Z"). It attempts to parse the token's value + * as an Instant, representing a point on the timeline in UTC. + *

+ * If the current token's value is not a valid time representation, a runtime + * exception is thrown. + * + * @return Instant representing the value of the current token, if applicable. + * @throws RuntimeException if the current token's value cannot be converted to an Instant. + */ + Instant getValueAsTime(); +} From 36ac497351e1d3cb8c3bb73226b95c0a29e9fc42 Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Mon, 22 Jan 2024 18:05:09 -0300 Subject: [PATCH 2/5] Add string value reader --- build.gradle | 4 + .../exception/SerializationException.java | 12 +++ .../fauna/serialization/Utf8FaunaReader.java | 95 +++++++++++++++++++ .../serialization/Utf8FaunaReaderTest.java | 48 ++++++++++ gradle.properties | 3 +- 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 faunaJava/src/main/java/com/fauna/exception/SerializationException.java create mode 100644 faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java create mode 100644 faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java diff --git a/build.gradle b/build.gradle index 1c1bc38c..fb5d6346 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,10 @@ project(':faunaJava') { dependencies { implementation project(':common') + implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}" + implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}" + implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}" + testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" testImplementation "org.mockito:mockito-core:${mockitoVersion}" diff --git a/faunaJava/src/main/java/com/fauna/exception/SerializationException.java b/faunaJava/src/main/java/com/fauna/exception/SerializationException.java new file mode 100644 index 00000000..dd43cab6 --- /dev/null +++ b/faunaJava/src/main/java/com/fauna/exception/SerializationException.java @@ -0,0 +1,12 @@ +package com.fauna.exception; + +public class SerializationException extends RuntimeException { + + public SerializationException(String message) { + super(message); + } + + public SerializationException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java b/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java new file mode 100644 index 00000000..38c2bca2 --- /dev/null +++ b/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java @@ -0,0 +1,95 @@ +package com.fauna.serialization; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fauna.common.enums.FaunaTokenType; +import com.fauna.exception.SerializationException; + +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + +import static com.fauna.common.enums.FaunaTokenType.*; + +/** + * Represents a reader that provides fast, non-cached, forward-only access to serialized data. + */ +public class Utf8FaunaReader { + private static final String INT_TAG = "@int"; + private static final String LONG_TAG = "@long"; + private static final String DOUBLE_TAG = "@double"; + private static final String TIME_TAG = "@time"; + private static final String DATE_TAG = "@date"; + private static final String REF_TAG = "@ref"; + private static final String DOC_TAG = "@doc"; + private static final String MOD_TAG = "@mod"; + private static final String SET_TAG = "@set"; + private static final String OBJECT_TAG = "@object";//TODO Understand Module + private final JsonParser jsonParser; + private final Stack tokenStack = new Stack<>(); + private FaunaTokenType currentFaunaTokenType; + private FaunaTokenType bufferedFaunaTokenType; + private String taggedTokenValue; + + public Utf8FaunaReader(InputStream body) throws IOException { + JsonFactory factory = new JsonFactory(); + this.jsonParser = factory.createParser(body); + System.out.println(""); + currentFaunaTokenType = NONE; + } + + public JsonToken getCurrentTokenType() { + return jsonParser.currentToken(); + } + private final Set closers = new HashSet<>(Arrays.asList( + END_OBJECT, + END_PAGE, + END_DOCUMENT, + END_REF, + END_ARRAY + )); + + public boolean read() { + taggedTokenValue = null; + + if (bufferedFaunaTokenType != null) { + currentFaunaTokenType = bufferedFaunaTokenType; + bufferedFaunaTokenType = null; + if (closers.contains(currentFaunaTokenType)) { + tokenStack.pop(); + } + return true; + } + + if (!advance()) { + return false; + } + + switch (jsonParser.currentToken()) { + case VALUE_STRING: + currentFaunaTokenType = FaunaTokenType.STRING; + break; + default: + throw new SerializationException("Unhandled JSON token type " + jsonParser.currentToken() + "."); + } + + return true; + } + + private boolean advance() { + try { + return jsonParser.nextToken() != JsonToken.END_OBJECT; + } catch (IOException e) { + throw new SerializationException("Failed to advance underlying JSON reader.", e); + } + } + + public String getValueAsString() { + try { + return jsonParser.getValueAsString(); + } catch (IOException e) { + throw new RuntimeException("Error reading current token as String", e); + } + } +} \ No newline at end of file diff --git a/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java b/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java new file mode 100644 index 00000000..1d1646fb --- /dev/null +++ b/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java @@ -0,0 +1,48 @@ +package com.fauna.serialization; + +import com.fauna.common.enums.FaunaTokenType; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; +import java.util.Objects; + + +class Utf8FaunaReaderTest { + + public static void main(String[] args) throws IOException { + InputStream inputStream = new ByteArrayInputStream("\"hello\"".getBytes()); + Utf8FaunaReader reader = new Utf8FaunaReader(inputStream); + + List> expectedTokens = List.of( + Map.entry(FaunaTokenType.STRING, "hello") + ); + + assertReader(reader, expectedTokens); + } + + private static void assertReader(Utf8FaunaReader reader, List> tokens) throws IOException { + for (Map.Entry entry : tokens) { + reader.read(); + Objects.requireNonNull(entry.getKey()); + Objects.requireNonNull(reader.getCurrentTokenType()); + assert entry.getKey().equals(reader.getCurrentTokenType()); + + switch (entry.getKey()) { + case FIELD_NAME: + case STRING: + assert entry.getValue().equals(reader.getValueAsString()); + break; + default: + assert entry.getValue() == null; + break; + } + } + + assert !reader.read(); + } + +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c42a4e49..372461a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,5 @@ version=0.1.0 junitVersion=5.10.0 -mockitoVersion=5.6.0 \ No newline at end of file +mockitoVersion=5.6.0 +jacksonVersion=2.15.3 \ No newline at end of file From 88e874e384ed1ebece5c7e79f44618599f6efb3a Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Mon, 22 Jan 2024 18:24:53 -0300 Subject: [PATCH 3/5] Remove interface --- .../com/fauna/interfaces/TokenStream.java | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 faunaJava/src/main/java/com/fauna/interfaces/TokenStream.java diff --git a/faunaJava/src/main/java/com/fauna/interfaces/TokenStream.java b/faunaJava/src/main/java/com/fauna/interfaces/TokenStream.java deleted file mode 100644 index b9f5e695..00000000 --- a/faunaJava/src/main/java/com/fauna/interfaces/TokenStream.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.fauna.interfaces; - -import com.fauna.common.enums.TokenType; - -import java.io.IOException; -import java.time.Instant; -import java.time.LocalDate; - -/** - * Represents a stream of JSON tokens that can be read sequentially. - * This interface abstracts the process of iterating over a sequence of JSON tokens, - * typically obtained from a JSON parsing process. - */ -public interface TokenStream { - - /** - * Retrieves the next JSON token from the stream. - * - * @return The next JsonToken, or null if the end of the stream is reached. - */ - TokenType nextToken() throws IOException; - - /** - * Closes the token stream and releases any system resources associated with it. - * - * @throws IOException If an I/O error occurs. - */ - void close() throws IOException; - - /** - * Method that will try to convert value of current token to a String. JSON Strings map naturally; scalar values get converted to their textual representation. If representation can not be converted to a String value (including structured types like Objects and Arrays and null token), default value of null will be returned; no exceptions are thrown. - * - * @return String value current token is converted to, if possible; null otherwise - */ - String getValueAsString(); - - /** - * Method that will try to convert value of current token to a Java int value. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules. - * If representation can not be converted to an int (including structured type markers like start/end Object/Array) default value of 0 will be returned; no exceptions are thrown. - * - * @return int value current token is converted to, if possible; exception thrown otherwise - */ - int getValueAsInt(); - - /** - * Method that will try to convert value of current token to a long. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules. - * If representation can not be converted to a long (including structured type markers like start/end Object/Array) default value of 0L will be returned; no exceptions are thrown. - * - * @return long value current token is converted to, if possible; exception thrown otherwise - */ - long getValueAsLong(); - - /** - * Method that will try to convert value of current token to a Java - * double. - * Numbers are coerced using default Java rules; booleans convert to 0.0 (false) - * and 1.0 (true), and Strings are parsed using default Java language floating - * point parsing rules. - *

- * If representation can not be converted to a double (including structured types - * like Objects and Arrays), - * default value of 0.0 will be returned; no exceptions are thrown. - * - * @return {@code double} value current token is converted to, if possible; exception thrown - * otherwise - */ - double getValueAsDouble(); - - /** - * Method that will try to convert value of current token to a - * boolean. - * JSON booleans map naturally; integer numbers other than 0 map to true, and - * 0 maps to false - * and Strings 'true' and 'false' map to corresponding values. - *

- * If representation can not be converted to a boolean value (including structured types - * like Objects and Arrays), - * default value of false will be returned; no exceptions are thrown. - * - * @return {@code boolean} value current token is converted to, if possible; - */ - boolean getValueAsBoolean(); - - /** - * Method that will try to convert the value of the current token to a LocalDate. - * This method is applicable when the current token represents a date value in - * ISO-8601 format (e.g., "2023-11-20"). It attempts to parse the token's value - * as a LocalDate. - *

- * If the current token's value is not a valid date representation, a runtime - * exception is thrown. - * - * @return LocalDate representing the value of the current token, if applicable. - * @throws RuntimeException if the current token's value cannot be converted to a LocalDate. - */ - LocalDate getValueAsDate(); - - /** - * Method that will try to convert the value of the current token to an Instant. - * This method is applicable when the current token represents a time value in - * ISO-8601 format (e.g., "2023-11-20T13:33:10.300Z"). It attempts to parse the token's value - * as an Instant, representing a point on the timeline in UTC. - *

- * If the current token's value is not a valid time representation, a runtime - * exception is thrown. - * - * @return Instant representing the value of the current token, if applicable. - * @throws RuntimeException if the current token's value cannot be converted to an Instant. - */ - Instant getValueAsTime(); -} From e2596863906b624781ff0b201242e8ab67990ec0 Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Mon, 22 Jan 2024 19:00:10 -0300 Subject: [PATCH 4/5] Fix null on get current token --- build.gradle | 1 + .../fauna/serialization/Utf8FaunaReader.java | 18 ++++++++++------ .../serialization/Utf8FaunaReaderTest.java | 21 ++++++++++--------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index fb5d6346..698e549a 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,7 @@ project(':faunaJava') { implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}" testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" + testImplementation 'junit:junit:4.13.2' testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" testImplementation "org.mockito:mockito-core:${mockitoVersion}" } diff --git a/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java b/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java index 38c2bca2..77cb94a3 100644 --- a/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java +++ b/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java @@ -66,14 +66,20 @@ public boolean read() { return false; } - switch (jsonParser.currentToken()) { - case VALUE_STRING: - currentFaunaTokenType = FaunaTokenType.STRING; - break; - default: - throw new SerializationException("Unhandled JSON token type " + jsonParser.currentToken() + "."); + JsonToken currentToken = jsonParser.currentToken(); + if (currentToken != null) { + switch (currentToken) { + case VALUE_STRING: + currentFaunaTokenType = FaunaTokenType.STRING; + break; + default: + throw new SerializationException("Unhandled JSON token type " + currentToken + "."); + } + } else { + return false; } + return true; } diff --git a/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java b/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java index 1d1646fb..59a62ec0 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java @@ -1,19 +1,20 @@ package com.fauna.serialization; import com.fauna.common.enums.FaunaTokenType; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.math.BigDecimal; import java.util.List; import java.util.Map; -import java.util.Objects; +import static org.junit.Assert.*; class Utf8FaunaReaderTest { - public static void main(String[] args) throws IOException { + @Test + public void testGetValueAsString() throws IOException { InputStream inputStream = new ByteArrayInputStream("\"hello\"".getBytes()); Utf8FaunaReader reader = new Utf8FaunaReader(inputStream); @@ -24,25 +25,25 @@ public static void main(String[] args) throws IOException { assertReader(reader, expectedTokens); } - private static void assertReader(Utf8FaunaReader reader, List> tokens) throws IOException { + private static void assertReader(Utf8FaunaReader reader, List> tokens) { for (Map.Entry entry : tokens) { reader.read(); - Objects.requireNonNull(entry.getKey()); - Objects.requireNonNull(reader.getCurrentTokenType()); - assert entry.getKey().equals(reader.getCurrentTokenType()); + assertNotNull(entry.getKey()); + assertNotNull(reader.getCurrentTokenType()); + assertEquals(entry.getKey(), FaunaTokenType.STRING); switch (entry.getKey()) { case FIELD_NAME: case STRING: - assert entry.getValue().equals(reader.getValueAsString()); + assertEquals(entry.getValue(), reader.getValueAsString()); break; default: - assert entry.getValue() == null; + assertNull(entry.getValue() == null); break; } } - assert !reader.read(); + assertFalse(reader.read()); } } \ No newline at end of file From a9104643a36c407aec0426d693c843c00f0cf64a Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Wed, 24 Jan 2024 10:22:34 -0300 Subject: [PATCH 5/5] Code styling Class renaming PR changes --- ...{Utf8FaunaReader.java => FaunaParser.java} | 44 ++++++++++++------- ...naReaderTest.java => FaunaParserTest.java} | 18 +++++--- 2 files changed, 40 insertions(+), 22 deletions(-) rename faunaJava/src/main/java/com/fauna/serialization/{Utf8FaunaReader.java => FaunaParser.java} (73%) rename faunaJava/src/test/java/com/fauna/serialization/{Utf8FaunaReaderTest.java => FaunaParserTest.java} (73%) diff --git a/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java similarity index 73% rename from faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java rename to faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java index 77cb94a3..533e9f51 100644 --- a/faunaJava/src/main/java/com/fauna/serialization/Utf8FaunaReader.java +++ b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java @@ -1,21 +1,30 @@ package com.fauna.serialization; +import static com.fauna.common.enums.FaunaTokenType.END_ARRAY; +import static com.fauna.common.enums.FaunaTokenType.END_DOCUMENT; +import static com.fauna.common.enums.FaunaTokenType.END_OBJECT; +import static com.fauna.common.enums.FaunaTokenType.END_PAGE; +import static com.fauna.common.enums.FaunaTokenType.END_REF; +import static com.fauna.common.enums.FaunaTokenType.NONE; + import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fauna.common.enums.FaunaTokenType; import com.fauna.exception.SerializationException; - import java.io.IOException; import java.io.InputStream; -import java.util.*; - -import static com.fauna.common.enums.FaunaTokenType.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; +import java.util.Stack; /** * Represents a reader that provides fast, non-cached, forward-only access to serialized data. */ -public class Utf8FaunaReader { +public class FaunaParser { + private static final String INT_TAG = "@int"; private static final String LONG_TAG = "@long"; private static final String DOUBLE_TAG = "@double"; @@ -32,22 +41,27 @@ public class Utf8FaunaReader { private FaunaTokenType bufferedFaunaTokenType; private String taggedTokenValue; - public Utf8FaunaReader(InputStream body) throws IOException { + public FaunaParser(InputStream body) throws IOException { JsonFactory factory = new JsonFactory(); this.jsonParser = factory.createParser(body); - System.out.println(""); + currentFaunaTokenType = NONE; + } + + public FaunaParser(JsonParser jsonParser) { + this.jsonParser = jsonParser; currentFaunaTokenType = NONE; } public JsonToken getCurrentTokenType() { return jsonParser.currentToken(); } + private final Set closers = new HashSet<>(Arrays.asList( - END_OBJECT, - END_PAGE, - END_DOCUMENT, - END_REF, - END_ARRAY + END_OBJECT, + END_PAGE, + END_DOCUMENT, + END_REF, + END_ARRAY )); public boolean read() { @@ -73,19 +87,19 @@ public boolean read() { currentFaunaTokenType = FaunaTokenType.STRING; break; default: - throw new SerializationException("Unhandled JSON token type " + currentToken + "."); + throw new SerializationException( + "Unhandled JSON token type " + currentToken + "."); } } else { return false; } - return true; } private boolean advance() { try { - return jsonParser.nextToken() != JsonToken.END_OBJECT; + return Objects.nonNull(jsonParser.nextToken()); } catch (IOException e) { throw new SerializationException("Failed to advance underlying JSON reader.", e); } diff --git a/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java similarity index 73% rename from faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java rename to faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java index 59a62ec0..d2ba8acd 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/Utf8FaunaReaderTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -1,31 +1,35 @@ package com.fauna.serialization; -import com.fauna.common.enums.FaunaTokenType; -import org.junit.jupiter.api.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import com.fauna.common.enums.FaunaTokenType; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Map; -import static org.junit.Assert.*; +import org.junit.jupiter.api.Test; -class Utf8FaunaReaderTest { +class FaunaParserTest { @Test public void testGetValueAsString() throws IOException { InputStream inputStream = new ByteArrayInputStream("\"hello\"".getBytes()); - Utf8FaunaReader reader = new Utf8FaunaReader(inputStream); + FaunaParser reader = new FaunaParser(inputStream); List> expectedTokens = List.of( - Map.entry(FaunaTokenType.STRING, "hello") + Map.entry(FaunaTokenType.STRING, "hello") ); assertReader(reader, expectedTokens); } - private static void assertReader(Utf8FaunaReader reader, List> tokens) { + private static void assertReader(FaunaParser reader, + List> tokens) { for (Map.Entry entry : tokens) { reader.read(); assertNotNull(entry.getKey());