1313import java .io .ByteArrayInputStream ;
1414import java .io .ByteArrayOutputStream ;
1515import java .io .IOException ;
16+ import java .net .URL ;
1617import java .nio .charset .StandardCharsets ;
1718import java .util .ArrayList ;
1819import java .util .List ;
@@ -31,7 +32,11 @@ private JsonMaskerTestUtil() {
3132
3233 public static List <JsonMaskerTestInstance > getJsonMaskerTestInstancesFromFile (String fileName ) throws IOException {
3334 List <JsonMaskerTestInstance > testInstances = new ArrayList <>();
34- ArrayNode jsonArray = mapper .readValue (JsonMaskerTestUtil .class .getClassLoader ().getResource (fileName ), ArrayNode .class );
35+ URL fileUrl = JsonMaskerTestUtil .class .getClassLoader ().getResource (fileName );
36+ if (fileUrl == null ) {
37+ throw new IllegalArgumentException ("File not found: " + fileName );
38+ }
39+ ArrayNode jsonArray = mapper .readValue (fileUrl .openStream (), ArrayNode .class );
3540 for (JsonNode jsonNode : jsonArray ) {
3641 JsonMaskingConfig .Builder builder = JsonMaskingConfig .builder ();
3742 JsonNode jsonMaskingConfig = jsonNode .findValue ("maskingConfig" );
@@ -47,9 +52,9 @@ public static List<JsonMaskerTestInstance> getJsonMaskerTestInstancesFromFile(St
4752 }
4853
4954 private static void applyConfig (JsonNode jsonMaskingConfig , JsonMaskingConfig .Builder builder ) {
50- jsonMaskingConfig .fields ().forEachRemaining ( e -> {
51- String key = e .getKey ();
52- JsonNode value = e .getValue ();
55+ jsonMaskingConfig .properties ().forEach ( p -> {
56+ String key = p .getKey ();
57+ JsonNode value = p .getValue ();
5358 switch (key ) {
5459 case "maskKeys" -> StreamSupport .stream (value .spliterator (), false ).forEach (node -> {
5560 if (node .isTextual ()) {
@@ -95,9 +100,9 @@ private static void applyConfig(JsonNode jsonMaskingConfig, JsonMaskingConfig.Bu
95100
96101 private static KeyMaskingConfig applyKeyConfig (JsonNode jsonNode ) {
97102 KeyMaskingConfig .Builder builder = KeyMaskingConfig .builder ();
98- jsonNode .fields ().forEachRemaining ( e -> {
99- String key = e .getKey ();
100- JsonNode value = e .getValue ();
103+ jsonNode .properties ().forEach ( p -> {
104+ String key = p .getKey ();
105+ JsonNode value = p .getValue ();
101106 switch (key ) {
102107 case "maskStringsWith" -> builder .maskStringsWith (value .textValue ());
103108 case "maskStringCharactersWith" -> builder .maskStringCharactersWith (value .textValue ());
@@ -126,7 +131,7 @@ private static <T> Set<T> asSet(JsonNode value, Function<JsonNode, T> mapper) {
126131 }
127132
128133 /**
129- * Asserts that JsonMasker result matches the expected output and is the same when using bytes mode,
134+ * Asserts that JsonMasker result matches the expected output and is the same when using byte mode,
130135 * streaming mode and streaming mode with minimal buffer size.
131136 *
132137 * @param jsonMasker an instance of JsonMasker
0 commit comments