From 1e80f98e25442b4badf570fd6ca652c21e499e28 Mon Sep 17 00:00:00 2001 From: waynedunican Date: Thu, 9 Jul 2020 13:03:28 +0100 Subject: Remove try/catch blocks with assertj - apex-pdp Removed try/catch blocks in apex-pdp and replaced with assertj assertions Part III Issue-ID: POLICY-2451 Change-Id: I1e6ede1c256c5bcf7899e1af130add71fdf1381c Signed-off-by: waynedunican --- .../apex/model/contextmodel/concepts/ContextAlbumsTest.java | 12 ++++-------- .../model/contextmodel/concepts/ContextSchemasTest.java | 13 ++++--------- 2 files changed, 8 insertions(+), 17 deletions(-) (limited to 'model/context-model') diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java index 0406543fb..74b000ff3 100644 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java @@ -21,11 +21,11 @@ package org.onap.policy.apex.model.contextmodel.concepts; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -57,13 +57,9 @@ public class ContextAlbumsTest { assertEquals("NewAlbumName:0.0.1", album.getKeys().get(0).getId()); album.setKey(albumKey); - try { - album.setScope(""); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("parameter \"scope\": value \"\", does not match regular expression \"[A-Za-z0-9\\-_]+\"", - e.getMessage()); - } + assertThatThrownBy(() -> album.setScope("")) + .hasMessage("parameter \"scope\": value \"\", does not match regular expression " + + "\"[A-Za-z0-9\\-_]+\""); album.setScope("NewAlbumScope"); assertEquals("NewAlbumScope", album.getScope()); diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java index e5fc19a20..abe7c008f 100644 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java @@ -21,11 +21,11 @@ package org.onap.policy.apex.model.contextmodel.concepts; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -51,14 +51,9 @@ public class ContextSchemasTest { assertEquals("NewSchemaName:0.0.1", schema.getKey().getId()); assertEquals("NewSchemaName:0.0.1", schema.getKeys().get(0).getId()); - try { - schema.setSchemaFlavour(""); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("parameter \"schemaFlavour\": value \"\", " - + "does not match regular expression \"[A-Za-z0-9\\-_]+\"", e.getMessage()); - } - + assertThatThrownBy(() -> schema.setSchemaFlavour("")) + .hasMessage("parameter \"schemaFlavour\": value \"\", " + + "does not match regular expression \"[A-Za-z0-9\\-_]+\""); schema.setSchemaFlavour("NewSchemaFlavour"); assertEquals("NewSchemaFlavour", schema.getSchemaFlavour()); -- cgit 1.2.3-korg