summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-01 11:37:07 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-06 14:00:59 +0100
commitd29a57a558336feb74d4c46b706686bb3253c60c (patch)
tree5beb8f7f19f4d7f4f9e05ab31563528036508f8b /main/src/test
parent01dac20f3d52bc5edcf8c7f4548f2e8613af4b4a (diff)
Replace try/catch blocks with assertj - pap
Replaced try/catch blocks in policy/pap test cases with assertj assertions Issue-ID: POLICY-2451 Change-Id: Ic963558e812b59d321e12fa87e7285732d6761e5 Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java48
1 files changed, 14 insertions, 34 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java
index 363a130a..b817677b 100644
--- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +25,6 @@ package org.onap.policy.pap.main.parameters;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.FileNotFoundException;
import org.junit.Test;
@@ -46,13 +46,9 @@ public class TestPapParameterHandler {
final PapCommandLineArguments noArguments = new PapCommandLineArguments();
noArguments.parse(noArgumentString);
- try {
- new PapParameterHandler().getParameters(noArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getCause() instanceof CoderException);
- assertTrue(e.getCause().getCause() instanceof FileNotFoundException);
- }
+ assertThatThrownBy(() -> new PapParameterHandler().getParameters(noArguments))
+ .hasCauseInstanceOf(CoderException.class)
+ .hasRootCauseInstanceOf(FileNotFoundException.class);
}
@Test
@@ -62,12 +58,8 @@ public class TestPapParameterHandler {
final PapCommandLineArguments emptyArguments = new PapCommandLineArguments();
emptyArguments.parse(emptyArgumentString);
- try {
- new PapParameterHandler().getParameters(emptyArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
- }
+ assertThatThrownBy(() -> new PapParameterHandler().getParameters(emptyArguments))
+ .hasMessageContaining("no parameters found in \"parameters/EmptyParameters.json\"");
}
@Test
@@ -77,14 +69,9 @@ public class TestPapParameterHandler {
final PapCommandLineArguments invalidArguments = new PapCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
- try {
- new PapParameterHandler().getParameters(invalidArguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().startsWith(
- "error reading parameters from \"parameters/InvalidParameters.json\""));
- assertTrue(e.getCause() instanceof CoderException);
- }
+ assertThatThrownBy(() -> new PapParameterHandler().getParameters(invalidArguments))
+ .hasMessageStartingWith("error reading parameters from \"parameters/InvalidParameters.json\"")
+ .hasCauseInstanceOf(CoderException.class);
}
@Test
@@ -127,13 +114,9 @@ public class TestPapParameterHandler {
final PapCommandLineArguments arguments = new PapCommandLineArguments();
arguments.parse(papConfigParameters);
- try {
- new PapParameterHandler().getParameters(arguments);
- fail("test should throw an exception here");
- } catch (final Exception e) {
- assertTrue(e.getMessage().contains(
- "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
- }
+ assertThatThrownBy(() -> new PapParameterHandler().getParameters(arguments))
+ .hasMessageContaining("field \"name\" type \"java.lang.String\" value \" \" "
+ + "INVALID, must be a non-blank string");
}
@Test
@@ -156,10 +139,7 @@ public class TestPapParameterHandler {
public void testPapInvalidOption() throws PolicyPapException {
final String[] papConfigParameters = { "-d" };
final PapCommandLineArguments arguments = new PapCommandLineArguments();
- try {
- arguments.parse(papConfigParameters);
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
- }
+ assertThatThrownBy(() -> arguments.parse(papConfigParameters))
+ .hasMessageStartingWith("invalid command line arguments specified");
}
}