Skip to content

Commit df0d5f2

Browse files
committed
test: added error tests for map sources
1 parent e8a1fdb commit df0d5f2

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/test/java/ca/trackerforce/ExcludeTypeClassRecordTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,36 @@ void shouldAddDefaultExclusionPaths(String implementation, Object userDetail) {
121121
assertTrue(address.containsKey("street"));
122122
}
123123

124+
@ParameterizedTest(name = "{0}")
125+
@MethodSource("userDetailProvider")
126+
void shouldExcludeSimpleNestedFieldFromMapSource(String implementation, Object userDetail) {
127+
// When
128+
var source = dotPathQL.toMap(userDetail); // Convert to Map for testing
129+
var result = dotPathQL.exclude(source, List.of("orders.orderId"));
130+
131+
// Then
132+
var orders = DotUtils.listFrom(result, "orders");
133+
assertNotNull(orders);
134+
assertEquals(2, orders.size());
135+
assertFalse(orders.get(0).containsKey("orderId"));
136+
assertFalse(orders.get(1).containsKey("orderId"));
137+
assertTrue(orders.get(0).containsKey("products"));
138+
}
139+
140+
@ParameterizedTest(name = "{0}")
141+
@MethodSource("userDetailProvider")
142+
void shouldNotExcludeWhenPathNotExists(String implementation, Object userDetail) {
143+
// When
144+
var source = dotPathQL.toMap(userDetail); // Convert to Map for testing
145+
var result = dotPathQL.exclude(source, List.of(
146+
"invalidProperty" // Non-existent property
147+
));
148+
149+
// Then
150+
assertNotNull(result);
151+
assertFalse(result.isEmpty());
152+
}
153+
124154
@Test
125155
void shouldReturnEmptyMapWhenSourceIsNull() {
126156
// When

src/test/java/ca/trackerforce/FilterTypeClassRecordTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,18 @@ void shouldReturnEmptyMapWhenSourceIsNull() {
222222
assertTrue(result.isEmpty());
223223
}
224224

225+
@ParameterizedTest(name = "{0}")
226+
@MethodSource("userDetailProvider")
227+
void shouldReturnEmptyMapWhenPathNotExists(String implementation, Object userDetail) {
228+
// When
229+
var source = dotPathQL.toMap(userDetail); // Convert to Map for testing
230+
var result = dotPathQL.filter(source, List.of(
231+
"invalidProperty" // Non-existent property
232+
));
233+
234+
// Then
235+
assertNotNull(result);
236+
assertTrue(result.isEmpty());
237+
}
238+
225239
}

0 commit comments

Comments
 (0)