diff options
author | waynedunican <wayne.dunican@est.tech> | 2020-07-13 11:13:53 +0100 |
---|---|---|
committer | waynedunican <wayne.dunican@est.tech> | 2020-07-15 14:25:13 +0100 |
commit | aac3c1d70c439910e25a2634f872f497486509ec (patch) | |
tree | 8b0f552dc22bfa479bcac96094b67d193c6f49c1 /services/services-onappf/src | |
parent | 871421fb99f7e6221b2c084e43a9388f618f882d (diff) |
Replace try/catch with assertj
Replaced try/catch blocks with assertj assertions in apex-pdp. Last
batch of changes
Issue-ID: POLICY-2451
Change-Id: I39bd02fdbd8389818dcf1b786189c1e344ddcea5
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'services/services-onappf/src')
-rw-r--r-- | services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java index 4b79dc589..d39cbecf0 100644 --- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java +++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * 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.services.onappf.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; @@ -44,13 +45,9 @@ public class TestApexStarterParameterHandler { final ApexStarterCommandLineArguments emptyArguments = new ApexStarterCommandLineArguments(); emptyArguments.parse(emptyArgumentString); - try { - new ApexStarterParameterHandler().getParameters(emptyArguments); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getCause() instanceof CoderException); - assertTrue(e.getCause().getCause() instanceof FileNotFoundException); - } + assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(emptyArguments)) + .hasCauseInstanceOf(CoderException.class) + .hasRootCauseInstanceOf(FileNotFoundException.class); } @Test @@ -60,12 +57,8 @@ public class TestApexStarterParameterHandler { final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments(); noArguments.parse(noArgumentString); - try { - new ApexStarterParameterHandler().getParameters(noArguments); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().contains("no parameters found")); - } + assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(noArguments)) + .hasMessageContaining("no parameters found"); } @Test @@ -75,13 +68,9 @@ public class TestApexStarterParameterHandler { final ApexStarterCommandLineArguments invalidArguments = new ApexStarterCommandLineArguments(); invalidArguments.parse(invalidArgumentString); - try { - new ApexStarterParameterHandler().getParameters(invalidArguments); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith("error reading parameters from")); - assertTrue(e.getCause() instanceof CoderException); - } + assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(invalidArguments)) + .hasMessageStartingWith("error reading parameters from") + .hasCauseInstanceOf(CoderException.class); } @Test @@ -91,11 +80,8 @@ public class TestApexStarterParameterHandler { final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments(); noArguments.parse(noArgumentString); - try { - new ApexStarterParameterHandler().getParameters(noArguments); - } catch (final Exception e) { - assertTrue(e.getMessage().contains("is null")); - } + assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(noArguments)) + .hasMessageContaining("is null"); } @Test @@ -118,13 +104,9 @@ public class TestApexStarterParameterHandler { final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments(); arguments.parse(apexStarterConfigParameters); - try { - new ApexStarterParameterHandler().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 ApexStarterParameterHandler().getParameters(arguments)) + .hasMessageContaining("field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a " + + "non-blank string"); } @Test @@ -147,10 +129,7 @@ public class TestApexStarterParameterHandler { public void testApexStarterInvalidOption() throws ApexStarterException { final String[] apexStarterConfigParameters = { "-d" }; final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments(); - try { - arguments.parse(apexStarterConfigParameters); - } catch (final Exception exp) { - assertTrue(exp.getMessage().startsWith("invalid command line arguments specified")); - } + assertThatThrownBy(() -> arguments.parse(apexStarterConfigParameters)) + .hasMessageStartingWith("invalid command line arguments specified"); } } |