diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-08-22 14:47:22 +0100 |
---|---|---|
committer | Liam Fallon <liam.fallon@est.tech> | 2023-08-24 14:30:09 +0000 |
commit | a354531009fcfe529d08183249601adb6d0adc6e (patch) | |
tree | c6386f6056c62c20e1730ddc535fff40aeb1e27f /reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java | |
parent | 960773d01db3072b4a57dbd69e911df1af2df47c (diff) |
Upgrade policy-distribution to JUnit 5java-17
Issue-ID: POLICY-4805
Change-Id: I47aaed48f3f05c2f1c5814882386e114dbad0443
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java')
-rw-r--r-- | reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java index 127f1223..d3a0e3d4 100644 --- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java +++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderConfigurationParametersJsonAdapter.java @@ -21,19 +21,16 @@ package org.onap.policy.distribution.reception.parameters; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.distribution.reception.testclasses.DummyPolicyDecoderParameterGroup; /** @@ -45,49 +42,48 @@ import org.onap.policy.distribution.reception.testclasses.DummyPolicyDecoderPara public class TestPolicyDecoderConfigurationParametersJsonAdapter { @Test - public void testDeserialize() throws JsonSyntaxException, IOException { - final String validJsonFile = "src/test/resources/PolicyDecoderConfiguration.json"; - final JsonElement mockJsonElement = JsonParser.parseString(getJsonValues(validJsonFile)); + void testDeserialize() throws JsonSyntaxException, IOException { + final var validJsonFile = "src/test/resources/PolicyDecoderConfiguration.json"; + final var mockJsonElement = JsonParser.parseString(getJsonValues(validJsonFile)); - Gson gson = new GsonBuilder().registerTypeAdapter(PolicyDecoderConfigurationParameterGroup.class, + var gson = new GsonBuilder().registerTypeAdapter(PolicyDecoderConfigurationParameterGroup.class, new PolicyDecoderConfigurationParametersJsonAdapter()).create(); - PolicyDecoderConfigurationParameterGroup result = - gson.fromJson(mockJsonElement, PolicyDecoderConfigurationParameterGroup.class); + var result = gson.fromJson(mockJsonElement, PolicyDecoderConfigurationParameterGroup.class); assertNotNull(result); assertEquals(result.getClass(), DummyPolicyDecoderParameterGroup.class); } @Test - public void testDeserialize_shouldThrowExceptionEmptyClassName() throws JsonSyntaxException, IOException { - final String jsonFile = "src/test/resources/EmptyClassName.json"; - String expectedErrorMsg = "parameter \"parameterClassName\" value \"\" invalid in JSON file"; + void testDeserialize_shouldThrowExceptionEmptyClassName() throws JsonSyntaxException, IOException { + final var jsonFile = "src/test/resources/EmptyClassName.json"; + var expectedErrorMsg = "parameter \"parameterClassName\" value \"\" invalid in JSON file"; validateParsing(jsonFile, expectedErrorMsg); } @Test - public void testDeserialize_shouldThrowExceptionNullClassName() throws JsonSyntaxException, IOException { - final String jsonFile = "src/test/resources/NullClassName.json"; - String expectedErrorMsg = "parameter \"parameterClassName\" value \"null\" invalid in JSON file"; + void testDeserialize_shouldThrowExceptionNullClassName() throws JsonSyntaxException, IOException { + final var jsonFile = "src/test/resources/NullClassName.json"; + var expectedErrorMsg = "parameter \"parameterClassName\" value \"null\" invalid in JSON file"; validateParsing(jsonFile, expectedErrorMsg); } @Test - public void testDeserialize_shouldThrowExceptionWrongClassName() throws JsonSyntaxException, IOException { - final String jsonFile = "src/test/resources/WrongClassName.json"; - String expectedErrorMsg = "parameter \"parameterClassName\" value " + void testDeserialize_shouldThrowExceptionWrongClassName() throws JsonSyntaxException, IOException { + final var jsonFile = "src/test/resources/WrongClassName.json"; + var expectedErrorMsg = "parameter \"parameterClassName\" value " + "\"org.onap.policy.distribution.reception.testclasses.NotExistentClass\", could not find class"; validateParsing(jsonFile, expectedErrorMsg); } private void validateParsing(final String jsonFile, String expectedErrorMsg) throws IOException { - final JsonElement mockJsonElement = JsonParser.parseString(getJsonValues(jsonFile)); + final var mockJsonElement = JsonParser.parseString(getJsonValues(jsonFile)); - Gson gson = new GsonBuilder().registerTypeAdapter(PolicyDecoderConfigurationParameterGroup.class, + var gson = new GsonBuilder().registerTypeAdapter(PolicyDecoderConfigurationParameterGroup.class, new PolicyDecoderConfigurationParametersJsonAdapter()).create(); assertThatThrownBy(() -> gson.fromJson(mockJsonElement, PolicyDecoderConfigurationParameterGroup.class)) @@ -95,7 +91,7 @@ public class TestPolicyDecoderConfigurationParametersJsonAdapter { } private String getJsonValues(String path) throws IOException { - return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8); + return Files.readString(new File(path).toPath()); } } |