aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor/plugins-executor-java/src
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-07-10 08:25:22 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-15 13:42:21 +0100
commitb8e3df6f43e46159c210ac7d1ec6983871d52ea5 (patch)
tree4992a599861db084882ad6d881ed011dd9569aaa /plugins/plugins-executor/plugins-executor-java/src
parent592e04f6301dd38ae48d38501cc251fc3d5ad2fb (diff)
Replaced try/catch blocks with assertj - apex-pdp
Removed try/catch blocks in apex-pdp with assertj assertions Part IV Issue-ID: POLICY-2451 Change-Id: I4b6accb9f944195db9ccf8a5de165b169301ac7f Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-java/src')
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java89
1 files changed, 25 insertions, 64 deletions
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
index 106467ac4..a1c296436 100644
--- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
@@ -1,6 +1,7 @@
/*-
* ============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.
@@ -20,9 +21,9 @@
package org.onap.policy.apex.plugins.executor.java;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import java.util.Properties;
import org.junit.After;
@@ -75,88 +76,48 @@ public class JavaStateFinalizerExecutorTest {
}
@Test
- public void testJavaStateFinalizerExecutor() {
+ public void testJavaStateFinalizerExecutor() throws StateMachineException, ContextException {
JavaStateFinalizerExecutor jsfe = new JavaStateFinalizerExecutor();
assertNotNull(jsfe);
- try {
- jsfe.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals(java.lang.NullPointerException.class, jtseException.getClass());
- }
-
+ assertThatThrownBy(jsfe::prepare).isInstanceOf(java.lang.NullPointerException.class);
ApexInternalContext internalContext = null;
- try {
- internalContext = new ApexInternalContext(new AxPolicyModel());
- } catch (ContextException e) {
- fail("test should not throw an exception here");
- }
+
+ internalContext = new ApexInternalContext(new AxPolicyModel());
StateExecutor parentStateExcutor = null;
- try {
- parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
- } catch (StateMachineException e) {
- fail("test should not throw an exception here");
- }
+
+ parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
AxState state = new AxState();
parentStateExcutor.setContext(null, state, internalContext);
AxStateFinalizerLogic stateFinalizerLogic = new AxStateFinalizerLogic();
jsfe.setContext(parentStateExcutor, stateFinalizerLogic, internalContext);
- try {
- jsfe.prepare();
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("instantiation error on Java class \"\"", jtseException.getMessage());
- }
-
+ assertThatThrownBy(jsfe::prepare)
+ .hasMessage("instantiation error on Java class \"\"");
stateFinalizerLogic.setLogic("java.lang.String");
- try {
- jsfe.prepare();
- } catch (Exception jtseException) {
- fail("test should not throw an exception here");
- }
-
- try {
- jsfe.execute(-1, new Properties(), null);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"",
- jtseException.getMessage());
- }
+ jsfe.prepare();
+ assertThatThrownBy(() -> jsfe.execute(-1, new Properties(), null))
+ .hasMessage("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"");
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- try {
- jsfe.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"",
- jtseException.getMessage());
- }
-
+ assertThatThrownBy(() -> jsfe.execute(-1, new Properties(), event))
+ .hasMessage("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"");
stateFinalizerLogic.setLogic("org.onap.policy.apex.plugins.executor.java.DummyJavaStateFinalizerLogic");
- try {
- jsfe.prepare();
+ jsfe.prepare();
+ assertThatThrownBy(() -> {
jsfe.execute(-1, new Properties(), event);
- fail("test should throw an exception here");
- } catch (Exception jtseException) {
- assertEquals("execute-post: state finalizer logic execution failure on state \"NULL:0.0.0:NULL:NULL\" "
- + "on finalizer logic NULL:0.0.0:NULL:NULL", jtseException.getMessage());
- }
-
+ }).hasMessage("execute-post: state finalizer logic execution failure on state "
+ + "\"NULL:0.0.0:NULL:NULL\" on finalizer logic NULL:0.0.0:NULL:NULL");
state.getStateOutputs().put("SelectedOutputIsMe", null);
- try {
- jsfe.prepare();
- String stateOutput = jsfe.execute(0, new Properties(), event);
- assertEquals("SelectedOutputIsMe", stateOutput);
- jsfe.cleanUp();
- } catch (Exception jtseException) {
- jtseException.printStackTrace();
- fail("test should not throw an exception here");
- }
+
+ jsfe.prepare();
+ String stateOutput = jsfe.execute(0, new Properties(), event);
+ assertEquals("SelectedOutputIsMe", stateOutput);
+ jsfe.cleanUp();
+
}
}