/
ObjectHandlerTest.java
71 lines (60 loc) · 2.4 KB
/
ObjectHandlerTest.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.burningwave.json;
import java.util.Map;
import org.burningwave.json.bean.Question;
import org.burningwave.json.bean.Root;
import org.burningwave.json.bean.Sport;
import org.junit.jupiter.api.Test;
class ObjectHandlerTest extends BaseTest {
static final Facade facade = Facade.create();
@Test
void findFirstTestOne() {
testNotNull(() -> {
//Loading the JSON object
ObjectHandler objectHandler = facade.newObjectHandler(
ObjectHandlerTest.class.getClassLoader().getResourceAsStream("quiz.json"),
Root.class
);
ObjectHandler.Finder finder = objectHandler.newFinder();
ObjectHandler sportOH = finder.findFirstForPathEndsWith("sport");
//Retrieving the path of the sport object ("quiz.sport")
String sportPath = sportOH.getPath();
//Retrieving the value of the sport object
Sport sport = sportOH.getValue();
ObjectHandler option2OfSportQuestionOH = finder.findFirstForPathEndsWith(Path.of("sport", "q1", "options[1]"));
String option2OfSportQuestionOHPath = option2OfSportQuestionOH.getPath();
String option2OfSportQuestion = option2OfSportQuestionOH.getValue();
ObjectHandler questionOneOH = finder.findForPathEquals(Path.of("quiz", "sport", "q1"));
String questionOnePath = questionOneOH.getPath();
Question questionOne = questionOneOH.getValue();
return questionOne;
});
}
@Test
void findFirstValueTestOne() {
testNotNull(() -> {
//Loading the JSON object
ObjectHandler objectHandler = facade.newObjectHandler(
ObjectHandlerTest.class.getClassLoader().getResourceAsStream("quiz.json"),
Root.class
);
ObjectHandler.ValueFinder finder = objectHandler.newValueFinder();
Sport sport = finder.findFirstForPathEndsWith("sport");
String option2OfSportQuestion = finder.findFirstForPathEndsWith(Path.of("sport", "q1", "options[1]"));
Question questionOne = finder.findForPathEquals(Path.of("quiz", "sport", "q1"));
return questionOne;
});
}
@Test
void findFirstValueAndConvertItTestOne() {
testNotNull(() -> {
//Loading the JSON object
ObjectHandler objectHandler = facade.newObjectHandler(
ObjectHandlerTest.class.getClassLoader().getResourceAsStream("quiz.json"),
Root.class
);
ObjectHandler.ValueFinderAndConverter finderAndConverter = objectHandler.newValueFinderAndConverter(Map.class);
Map<String, Object> sportAsMap = finderAndConverter.findFirstForPathEndsWith("sport");
return sportAsMap;
});
}
}