Skip to content

Commit 24af0aa

Browse files
authored
Replace deprecated methods in tests and bump copyright year (#275)
1 parent 0b3ba83 commit 24af0aa

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2024 [Breus Blaauwendraad](https://github.com/Breus) & [Artur Havliukovskyi](https://github.com/gavlyukovskiy)
1+
Copyright (c) 2025 [Breus Blaauwendraad](https://github.com/Breus) & [Artur Havliukovskyi](https://github.com/gavlyukovskiy)
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

src/test/java/dev/blaauwendraad/masker/json/InstanceCreationMemoryUsageTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,8 +1592,11 @@ public class InstanceCreationMemoryUsageTest {
15921592
@Test
15931593
public void defaultInstanceCreation() throws IOException {
15941594
URL targetKeyFileUrl = RandomJsonGenerator.class.getResource("/target_keys.json");
1595+
if (targetKeyFileUrl == null) {
1596+
throw new IllegalStateException("target_keys.json is not found.");
1597+
}
15951598
Set<String> targetKeys = new HashSet<>();
1596-
objectMapper.readValue(targetKeyFileUrl, ArrayNode.class).forEach(t -> targetKeys.add(t.textValue()));
1599+
objectMapper.readValue(targetKeyFileUrl.openStream(), ArrayNode.class).forEach(t -> targetKeys.add(t.textValue()));
15971600

15981601
long memoryBeforeInstanceCreationKb = getCurrentRetainedMemory();
15991602

src/test/java/dev/blaauwendraad/masker/json/JsonMaskerTestUtil.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.ByteArrayInputStream;
1414
import java.io.ByteArrayOutputStream;
1515
import java.io.IOException;
16+
import java.net.URL;
1617
import java.nio.charset.StandardCharsets;
1718
import java.util.ArrayList;
1819
import 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

Comments
 (0)