-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't close IonParser on EOF to be compatible with MappingIterator wh…
…en source is an empty InputStream (#487)
- Loading branch information
1 parent
d90dd25
commit 9f9df25
Showing
2 changed files
with
50 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
50 changes: 50 additions & 0 deletions
50
ion/src/test/java/com/fasterxml/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,50 @@ | ||
package com.fasterxml.jackson.dataformat.ion.sequence; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.fasterxml.jackson.databind.MappingIterator; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SequenceWriter; | ||
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import org.junit.Test; | ||
|
||
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()); | ||
} | ||
} | ||
} |