-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
Showing
4 changed files
with
61 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
ion/src/test/java/tools/jackson/dataformat/ion/sequence/MappingIteratorTest.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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package tools.jackson.dataformat.ion.sequence; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
|
||
import org.junit.Test; | ||
|
||
import tools.jackson.databind.MappingIterator; | ||
import tools.jackson.databind.ObjectMapper; | ||
import tools.jackson.databind.SequenceWriter; | ||
import tools.jackson.dataformat.ion.IonObjectMapper; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class MappingIteratorTest { | ||
|
||
private static final ObjectMapper MAPPER = new IonObjectMapper(); | ||
|
||
@Test | ||
public void testReadFromWrite() throws Exception { | ||
final Object[] values = new String[]{"1", "2", "3", "4"}; | ||
|
||
// write | ||
final ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
try (SequenceWriter seq = MAPPER.writer().writeValues(out)) { | ||
for (Object value : values) { | ||
seq.write(value); | ||
} | ||
} | ||
|
||
// read | ||
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); | ||
try (MappingIterator<Object> it = MAPPER.readerFor(Object.class).readValues(in)) { | ||
for (Object value : values) { | ||
assertTrue(it.hasNext()); | ||
assertTrue(it.hasNext()); // should not alter the iterator state | ||
assertEquals(value, it.next()); | ||
} | ||
assertFalse(it.hasNext()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testReadFromEmpty() throws Exception { | ||
final ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]); | ||
try (MappingIterator<Object> it = MAPPER.readerFor(Object.class).readValues(in)) { | ||
assertFalse(it.hasNext()); | ||
} | ||
} | ||
} |
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
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