diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2020-07-16 13:51:38 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-07-16 13:51:38 +0000 |
commit | 8180d5fc70e966973390c0981c694091c6e6df49 (patch) | |
tree | 925baae0addde22712cb0ec28ce5d9232b852bd6 /plugins/plugins-executor | |
parent | e9f108f0fcfff74f8960136a1723742d97f72c26 (diff) | |
parent | b8e3df6f43e46159c210ac7d1ec6983871d52ea5 (diff) |
Merge "Replaced try/catch blocks with assertj - apex-pdp"
Diffstat (limited to 'plugins/plugins-executor')
-rw-r--r-- | plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java | 89 |
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(); + } } |