-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReflectionPathResolverTest.java
More file actions
49 lines (38 loc) · 1.66 KB
/
ReflectionPathResolverTest.java
File metadata and controls
49 lines (38 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package io.cloudquery.helper;
import lombok.Builder;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class ReflectionPathResolverTest {
@Builder
private static class TestClass {
private String name;
@Builder.Default
private List<Integer> numbers = List.of(1, 2, 3);
private TestClass singleChild;
private List<TestClass> multipleChildren;
}
private static final TestClass TEST_DATA = TestClass.builder().name("root").
singleChild(TestClass.builder().name("single-child1").build()).
multipleChildren(
List.of(
TestClass.builder().name("multi-child1").build(),
TestClass.builder().name("multi-child2").build()
)
).
build();
@Test
public void shouldResolveSimpleFields() throws ReflectionPathResolver.PathResolverException {
assertEquals("root", ReflectionPathResolver.resolve(TEST_DATA, "name"));
assertEquals(List.of(1, 2, 3), ReflectionPathResolver.resolve(TEST_DATA, "numbers"));
}
@Test
public void shouldResolveNestedField() throws ReflectionPathResolver.PathResolverException {
assertEquals("single-child1", ReflectionPathResolver.resolve(TEST_DATA, "singleChild.name"));
}
@Test
public void shouldThrowAnErrorIfWeEncounterACollection() {
assertThrows(ReflectionPathResolver.PathResolverException.class, () -> ReflectionPathResolver.resolve(TEST_DATA, "multiplChildren.name"));
}
}