|
6 | 6 | package software.amazon.smithy.java.core.serde.document; |
7 | 7 |
|
8 | 8 | import static org.hamcrest.MatcherAssert.assertThat; |
| 9 | +import static org.hamcrest.Matchers.aMapWithSize; |
9 | 10 | import static org.hamcrest.Matchers.equalTo; |
10 | 11 | import static org.hamcrest.Matchers.hasSize; |
11 | 12 | import static org.hamcrest.Matchers.nullValue; |
@@ -36,4 +37,21 @@ public void doesNotDropNullListValues() { |
36 | 37 | assertThat(parser.getResult().asList().get(2).asString(), equalTo("There")); |
37 | 38 | assertThat(parser.getResult().asList().get(3), nullValue()); |
38 | 39 | } |
| 40 | + |
| 41 | + @Test |
| 42 | + void writesMapWithDocumentSchema() { |
| 43 | + DocumentParser parser = new DocumentParser(); |
| 44 | + parser.writeMap(PreludeSchemas.DOCUMENT, null, 2, (_ignore, ser) -> { |
| 45 | + ser.writeEntry(PreludeSchemas.STRING, "key1", null, (state, valueSer) -> { |
| 46 | + valueSer.writeString(PreludeSchemas.STRING, "value1"); |
| 47 | + }); |
| 48 | + ser.writeEntry(PreludeSchemas.STRING, "key2", null, (state, valueSer) -> { |
| 49 | + valueSer.writeInteger(PreludeSchemas.INTEGER, 42); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + assertThat(parser.getResult().asStringMap(), aMapWithSize(2)); |
| 54 | + assertThat(parser.getResult().asStringMap().get("key1").asString(), equalTo("value1")); |
| 55 | + assertThat(parser.getResult().asStringMap().get("key2").asNumber().intValue(), equalTo(42)); |
| 56 | + } |
39 | 57 | } |
0 commit comments