Skip to content

Commit 5aa58ff

Browse files
committed
Move test models to blackbox module, and add ExampleTest to verify behavior
1 parent 7de0472 commit 5aa58ff

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.avaje.jsonb.generator.models.valid.custom;
1+
package org.example.other.custom;
22

33
import java.util.List;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.avaje.jsonb.generator.models.valid.custom;
1+
package org.example.other.custom;
22

33
import java.util.AbstractMap;
44
import java.util.Map;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.avaje.jsonb.generator.models.valid.custom;
1+
package org.example.other.custom;
22

33
import java.util.AbstractMap;
44
import java.util.Map;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.avaje.jsonb.generator.models.valid.custom;
1+
package org.example.other.custom;
22

33
import java.util.Map;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.avaje.jsonb.generator.models.valid.custom;
1+
package org.example.other.custom;
22

33
import java.util.Map;
44

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.example.other.custom;
2+
3+
import io.avaje.jsonb.JsonType;
4+
import io.avaje.jsonb.Jsonb;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
class ExampleTest {
13+
14+
Jsonb jsonb = Jsonb.builder().build();
15+
JsonType<Example> jsonType = jsonb.type(Example.class);
16+
17+
@Test
18+
void toFromJson() {
19+
Example bean = new Example();
20+
bean.setCode(34);
21+
bean.setMap(new WrapMap(Map.of("a", "b")));
22+
bean.setMap2(List.of(new WrapMap2(Map.of("2a", "z")), new WrapMap2(Map.of("2b", "x"))));
23+
24+
final String asJson = jsonType.toJson(bean);
25+
assertThat(asJson).isEqualTo("{\"code\":34,\"map\":{\"a\":\"b\"},\"map2\":[{\"2a\":\"z\"},{\"2b\":\"x\"}]}");
26+
27+
final var fromJson = jsonType.fromJson(asJson);
28+
assertThat(fromJson.getCode()).isEqualTo(34);
29+
assertThat(fromJson.getMap()).containsEntry("a", "b");
30+
assertThat(fromJson.getMap2()).hasSize(2);
31+
assertThat(fromJson.getMap2().getFirst()).containsEntry("2a", "z");
32+
assertThat(fromJson.getMap2().getLast()).containsEntry("2b", "x");
33+
}
34+
}

0 commit comments

Comments
 (0)