-
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.
- Loading branch information
1 parent
beba18f
commit ed5be21
Showing
2 changed files
with
190 additions
and
7 deletions.
There are no files selected for viewing
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
77 changes: 72 additions & 5 deletions
77
faunaJava/src/test/java/com/fauna/serialization/FaunaGeneratorTest.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,25 +1,92 @@ | ||
package com.fauna.serialization; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import java.nio.charset.StandardCharsets; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class FaunaGeneratorTest { | ||
public class FaunaGeneratorTest { | ||
|
||
private FaunaGenerator writer; | ||
private ByteArrayOutputStream stream; | ||
|
||
@Before | ||
@BeforeEach | ||
public void setUp() throws IOException { | ||
stream = new ByteArrayOutputStream(); | ||
writer = new FaunaGenerator(stream); | ||
} | ||
|
||
@After | ||
@AfterEach | ||
public void tearDown() throws IOException { | ||
writer.close(); | ||
stream.close(); | ||
} | ||
|
||
@Test | ||
public void writeIntValue() throws IOException { | ||
writer.writeIntValue(42); | ||
assertWriter("{\"@int\":\"42\"}"); | ||
} | ||
|
||
@Test | ||
public void writeLongValue() throws IOException { | ||
writer.writeLongValue(42L); | ||
assertWriter("{\"@long\":\"42\"}"); | ||
} | ||
|
||
@Test | ||
public void writeDoubleValue() throws IOException { | ||
writer.writeDoubleValue(1.2d); | ||
assertWriter("{\"@double\":\"1.2\"}"); | ||
} | ||
|
||
@Test | ||
public void writeTrueValue() throws IOException { | ||
writer.writeBooleanValue(true); | ||
assertWriter("true"); | ||
} | ||
|
||
@Test | ||
public void writeFalseValue() throws IOException { | ||
writer.writeBooleanValue(false); | ||
assertWriter("false"); | ||
} | ||
|
||
@Test | ||
public void writeNullValue() throws IOException { | ||
writer.writeNullValue(); | ||
assertWriter("null"); | ||
} | ||
|
||
@Test | ||
public void writeDate() throws IOException { | ||
LocalDate dateTime = LocalDate.of(2023, 1, 1); | ||
writer.writeDateValue(dateTime); | ||
assertWriter("{\"@date\":\"2023-01-01\"}"); | ||
} | ||
|
||
@Test | ||
public void writeTime() throws IOException { | ||
Instant instant = Instant.parse("2024-01-23T13:33:10.300Z"); | ||
writer.writeTimeValue(instant); | ||
assertWriter("{\"@time\":\"2024-01-23T13:33:10.300Z\"}"); | ||
} | ||
|
||
private void assertWriter(String expected) throws IOException { | ||
writer.flush(); | ||
String actual = new String(stream.toByteArray(), StandardCharsets.UTF_8); | ||
System.out.println("Expected: " + expected); | ||
System.out.println("Actual : " + actual); | ||
|
||
// Add this line to explicitly print the stream content | ||
System.out.println("Stream Content: " + stream.toString(StandardCharsets.UTF_8)); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
} |