Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class FlattenedFieldRootBlockLoaderTests extends BlockLoaderTestCase {

Expand Down Expand Up @@ -96,7 +98,30 @@ private List<Object> parseActual(Object actual) throws IOException {

@Override
protected Object expected(Map<String, Object> fieldMapping, Object value, TestContext testContext) {
return value;
var nullValue = (String) fieldMapping.get("null_value");
return nullValue == null ? value : applyFlattenedNullValue(value, nullValue);
}

/**
* Mirrors flattened source normalization by materializing mapped {@code null_value}
* for null leaves in the expected source tree before comparison.
*/
private static Object applyFlattenedNullValue(Object value, String nullValue) {
return switch (value) {
case null -> nullValue;
case Map<?, ?> map -> map.entrySet()
.stream()
.collect(
Collectors.toMap(
e -> (String) e.getKey(),
e -> applyFlattenedNullValue(e.getValue(), nullValue),
(a, b) -> b,
LinkedHashMap::new
)
);
case List<?> list -> list.stream().map(v -> applyFlattenedNullValue(v, nullValue)).toList();
default -> value;
};
}

@Override
Expand Down