summaryrefslogtreecommitdiffstats
path: root/testsuites/integration/integration-common/src
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-06 09:31:10 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-06 15:15:55 +0100
commit6ae054c03543bc4d323ff0ae710c0b57e4f4e610 (patch)
tree27df3dc522dae259b7b8bd1c2e6a1b4e8ed5c3cd /testsuites/integration/integration-common/src
parent9519d1257b4fe4fbb68d3e9ab155de8ff0f13052 (diff)
Replace try/catch blocks with assertj - apex-pdp
Replaced try/catch blocks in apex-pdp with assertj assertions Issue-ID: POLICY-2451 Change-Id: I83375b9e0f38d399b84bb68ce5d441e1cec73ef5 Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'testsuites/integration/integration-common/src')
-rw-r--r--testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelSaverTest.java31
-rw-r--r--testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/testclasses/TestPingClassTest.java83
2 files changed, 31 insertions, 83 deletions
diff --git a/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelSaverTest.java b/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelSaverTest.java
index 241f69dc0..c7ab1d9a0 100644
--- a/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelSaverTest.java
+++ b/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelSaverTest.java
@@ -1,28 +1,29 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.testsuites.integration.common.model;
+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.File;
import java.io.IOException;
@@ -30,6 +31,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
/**
* Test the sample domain model saver.
@@ -37,32 +39,19 @@ import org.junit.Test;
public class SampleDomainModelSaverTest {
@Test
- public void testSampleDomainModelSaver() throws IOException {
- try {
- SampleDomainModelSaver.main(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("java.lang.NullPointerException", exc.getClass().getName());
- }
+ public void testSampleDomainModelSaver() throws IOException, ApexException {
+ assertThatThrownBy(() -> SampleDomainModelSaver.main(null)).isInstanceOf(NullPointerException.class);
String[] args0 =
{ "two", "arguments" };
- try {
- SampleDomainModelSaver.main(args0);
- } catch (Exception exc) {
- fail("test should not throw an exception");
- }
+ SampleDomainModelSaver.main(args0);
Path tempDirectory = Files.createTempDirectory("ApexModelTempDir");
String[] args1 =
{ tempDirectory.toString() };
- try {
- SampleDomainModelSaver.main(args1);
- } catch (Exception exc) {
- fail("test should not throw an exception");
- }
+ SampleDomainModelSaver.main(args1);
File tempDir = new File(tempDirectory.toString());
assertTrue(tempDir.isDirectory());
diff --git a/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/testclasses/TestPingClassTest.java b/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/testclasses/TestPingClassTest.java
index 82f46c04a..92f86f434 100644
--- a/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/testclasses/TestPingClassTest.java
+++ b/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/testclasses/TestPingClassTest.java
@@ -21,8 +21,8 @@
package org.onap.policy.apex.testsuites.integration.common.testclasses;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
@@ -32,7 +32,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
*/
public class TestPingClassTest {
@Test
- public void testPingClass() {
+ public void testPingClass() throws ApexException {
PingTestClass ptc = new PingTestClass();
ptc.setName("Hello");
@@ -46,84 +46,43 @@ public class TestPingClassTest {
ptc.setPongTime(-1);
assertEquals(-1, ptc.getPongTime());
-
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, name does not start with \"Rose\"", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, name does not start with \"Rose\"");
ptc.setName(null);
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, name length null or less than 4", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, name length null or less than 4");
ptc.setName("Ros");
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, name length null or less than 4", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, name length null or less than 4");
ptc.setName("Rose");
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, description length null or less than 44", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, description length null or less than 44");
ptc.setDescription(null);
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, description length null or less than 44", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, description length null or less than 44");
ptc.setDescription("A rose by any other name would smell as swee");
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, description length null or less than 44", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, description length null or less than 44");
ptc.setDescription("A rose by any other name would smell as swell");
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, description is incorrect", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, description is incorrect");
ptc.setDescription("A rose by any other name would smell as sweet");
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, pong time -1 is less than ping time 0", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, pong time -1 is less than ping time 0");
ptc.setPongTime(-2);
- try {
- ptc.verify();
- fail("test should throw an exception");
- } catch (ApexException ae) {
- assertEquals("TestPing is not valid, pong time -2 is less than ping time 0", ae.getMessage());
- }
+ assertThatThrownBy(() -> ptc.verify()).isInstanceOf(ApexException.class)
+ .hasMessageContaining("TestPing is not valid, pong time -2 is less than ping time 0");
ptc.setPongTime(1);
- try {
- ptc.verify();
- } catch (ApexException ae) {
- fail("test should not throw an exception");
- }
+ ptc.verify();
assertEquals(
"PingTestClass(id=0, name=Rose, "