Skip to content

Commit c69703a

Browse files
committed
Add tests for ArrayList and LinkedHashSet
1 parent a44370c commit c69703a

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.example.customer.stream;
2+
3+
import io.avaje.jsonb.Json;
4+
5+
import java.util.ArrayList;
6+
7+
@Json
8+
public record MyArrayList(int id, ArrayList<String> names) {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.example.customer.stream;
2+
3+
import io.avaje.jsonb.Json;
4+
5+
import java.util.LinkedHashSet;
6+
7+
@Json
8+
public record MyLinked(int id, LinkedHashSet<String> names) {
9+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.example.customer.stream;
2+
3+
import io.avaje.jsonb.Jsonb;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.util.ArrayList;
7+
import java.util.LinkedHashSet;
8+
import java.util.List;
9+
import java.util.Set;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertNotNull;
14+
15+
class MyArrayListTest {
16+
17+
Jsonb jsonb = Jsonb.builder().build();
18+
19+
@Test
20+
void toJson_fromJson() {
21+
MyArrayList myLinked = new MyArrayList(1, new ArrayList<>(List.of("a", "b", "c")));
22+
23+
String json = jsonb.toJson(myLinked);
24+
assertNotNull(json);
25+
assertThat(json).isEqualTo("{\"id\":1,\"names\":[\"a\",\"b\",\"c\"]}");
26+
27+
MyArrayList fromJson = jsonb.type(MyArrayList.class).fromJson(json);
28+
assertEquals(myLinked, fromJson);
29+
}
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.example.customer.stream;
2+
3+
import io.avaje.jsonb.Jsonb;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.util.LinkedHashSet;
7+
import java.util.List;
8+
import java.util.Set;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
import static org.junit.jupiter.api.Assertions.*;
12+
13+
class MyLinkedHashSetTest {
14+
15+
Jsonb jsonb = Jsonb.builder().build();
16+
17+
@Test
18+
void toJson_fromJson() {
19+
MyLinked myLinked = new MyLinked(1, new LinkedHashSet<>(List.of("a", "b", "c")));
20+
21+
String json = jsonb.toJson(myLinked);
22+
assertNotNull(json);
23+
assertThat(json).isEqualTo("{\"id\":1,\"names\":[\"a\",\"b\",\"c\"]}");
24+
25+
MyLinked fromJson = jsonb.type(MyLinked.class).fromJson(json);
26+
assertEquals(myLinked, fromJson);
27+
}
28+
}

0 commit comments

Comments
 (0)