Skip to content

Commit 57669fb

Browse files
committed
tests added
1 parent c3795f1 commit 57669fb

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

json-nonblocking/src/test/java/reactivejson/TokenizerTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,19 @@ private void testTokenize(List<String> source, List<String> expected, boolean to
219219
}
220220
}
221221

222+
@Test
223+
public void shouldReadSequence() {
224+
testTokenize(
225+
asList("{\"foo\": \"foofoo1\", \"bar\": \"barbar1\"}", "{\"foo\": \"foofoo2\", \"bar\": \"barbar2\"}"),
226+
asList("{\"foo\": \"foofoo1\", \"bar\": \"barbar1\"}", "{\"foo\": \"foofoo2\", \"bar\": \"barbar2\"}"),
227+
true);
228+
229+
testTokenize(
230+
asList("{\"foo\": \"foofoo1\", \"bar\": \"barbar1\"}", "{\"foo\": \"foofoo2\", \"bar\": \"barbar2\"}"),
231+
asList("{\"foo\": \"foofoo1\", \"bar\": \"barbar1\"}", "{\"foo\": \"foofoo2\", \"bar\": \"barbar2\"}"),
232+
false);
233+
}
234+
222235
private ByteBuffer stringBuffer(String value) {
223236
return ByteBuffer.wrap(value.getBytes(StandardCharsets.UTF_8));
224237
}

json-reactor/src/test/java/reactivejson/ReactorObjectReaderTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import reactor.core.publisher.Mono;
1111
import reactor.test.StepVerifier;
1212

13+
import java.io.UncheckedIOException;
1314
import java.nio.ByteBuffer;
1415
import java.nio.charset.StandardCharsets;
1516
import java.util.ArrayList;
@@ -51,6 +52,31 @@ public void shouldReadElements() throws JsonProcessingException {
5152
.verifyComplete();
5253
}
5354

55+
@Test
56+
public void shouldReadSequence() {
57+
TestEntity[] testEntities = new TestEntity[]{
58+
new TestEntity(1, "testName1"),
59+
new TestEntity(3, "testName3"),
60+
new TestEntity(7, "testName7")};
61+
62+
Publisher<ByteBuffer> byteBuffers = Flux.fromArray(testEntities)
63+
.flatMap(testEntity -> {
64+
try {
65+
return stringBuffer(objectMapper.writeValueAsString(testEntity));
66+
} catch (JsonProcessingException e) {
67+
throw new UncheckedIOException(e);
68+
}
69+
}) ;
70+
71+
Flux<TestEntity> testEntityRed = reader.readElements(byteBuffers, objectMapper.readerFor(TestEntity.class));
72+
73+
StepVerifier.create(testEntityRed)
74+
.expectNextMatches(testEntity -> testEntity.equals(testEntities[0]))
75+
.expectNextMatches(testEntity -> testEntity.equals(testEntities[1]))
76+
.expectNextMatches(testEntity -> testEntity.equals(testEntities[2]))
77+
.verifyComplete();
78+
}
79+
5480
@Test
5581
public void shouldReadElementsAsArray() throws JsonProcessingException {
5682
TestEntity[] testEntities = new TestEntity[]{

json-rx2/src/test/java/reactivejson/Rx2ObjectReaderTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ public void shouldReadElements() throws JsonProcessingException {
4747
.assertResult(testEntities);
4848
}
4949

50+
@Test
51+
public void shouldReadSequence() {
52+
TestEntity[] testEntities = new TestEntity[]{
53+
new TestEntity(1, "testName1"),
54+
new TestEntity(3, "testName3"),
55+
new TestEntity(7, "testName7")};
56+
57+
Publisher<ByteBuffer> byteBuffers = Flowable.fromArray(testEntities)
58+
.flatMap(testEntity -> stringBuffer(objectMapper.writeValueAsString(testEntity)));
59+
60+
Flowable<TestEntity> testEntityRed = reader.readElements(byteBuffers,
61+
objectMapper.readerFor(TestEntity.class));
62+
63+
testEntityRed.test()
64+
.assertResult(testEntities);
65+
}
66+
5067
@Test
5168
public void shouldReadElementsAsArray() throws JsonProcessingException {
5269
TestEntity[] testEntities = new TestEntity[]{

0 commit comments

Comments
 (0)