Replaced try/catch blocks in policy/models with assertj assertions. 93/109293/4
authorwaynedunican <wayne.dunican@est.tech>
Thu, 18 Jun 2020 09:46:36 +0000 (10:46 +0100)
committerwaynedunican <wayne.dunican@est.tech>
Thu, 18 Jun 2020 16:04:43 +0000 (17:04 +0100)
Issue-ID: POLICY-2451
Change-Id: I095beb674196d5ec5c4dd9b93d3a56cca5ee4788
Signed-off-by: waynedunican <wayne.dunican@est.tech>
models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java
models-errors/src/test/java/org/onap/policy/models/errors/concepts/ErrorResponseUtilsTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java

index b418234..2e742c3 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-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.
 
 package org.onap.policy.models.base;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 
 import javax.ws.rs.core.Response;
-
 import org.junit.Test;
 import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
 
@@ -36,19 +36,13 @@ public class PfModelExceptionInfoTest {
 
     @Test
     public void testExceptionInfo() {
-        try {
-            throw new PfModelException(Response.Status.ACCEPTED, "HELLO");
-        } catch (PfModelException pfme) {
-            String errorMessage = getErrorMessage(pfme);
-            assertEquals("Server returned: Accepted", errorMessage.substring(0, 25));
-        }
+        final PfModelException pfme = new PfModelException(Response.Status.ACCEPTED, "HELLO");
+        assertThat(pfme).hasMessage("HELLO");
+        assertEquals("Server returned: Accepted", getErrorMessage(pfme).substring(0, 25));
 
-        try {
-            throw new PfModelRuntimeException(Response.Status.ACCEPTED, "HELLO");
-        } catch (PfModelRuntimeException pfme) {
-            String errorMessage = getErrorMessage(pfme);
-            assertEquals("Server returned: Accepted", errorMessage.substring(0, 25));
-        }
+        final PfModelRuntimeException pfmr = new PfModelRuntimeException(Response.Status.ACCEPTED, "HELLO");
+        assertThat(pfmr).hasMessage("HELLO");
+        assertEquals("Server returned: Accepted", getErrorMessage(pfmr).substring(0, 25));
     }
 
     private String getErrorMessage(final ErrorResponseInfo eri) {
index 261e58a..c19b18b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 package org.onap.policy.models.errors.concepts;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
-
 import org.junit.Test;
 
 /**
@@ -37,15 +37,13 @@ public class ErrorResponseUtilsTest {
 
     @Test
     public void testErrorResponseUtils() {
-        try {
-            throw new IOException(EXCEPTION1, new NumberFormatException("Exception 0"));
-        } catch (Exception ioe) {
-            ErrorResponse errorResponse = new ErrorResponse();
-            ErrorResponseUtils.getExceptionMessages(errorResponse, ioe);
+        final IOException ioe = new IOException(EXCEPTION1, new NumberFormatException("Exception 0"));
+        final ErrorResponse errorResponse = new ErrorResponse();
+        assertThat(ioe).hasMessage(EXCEPTION1);
 
-            assertEquals(EXCEPTION1, errorResponse.getErrorMessage());
-            assertEquals(EXCEPTION1, errorResponse.getErrorDetails().get(0));
-            assertEquals("Exception 0", errorResponse.getErrorDetails().get(1));
-        }
+        ErrorResponseUtils.getExceptionMessages(errorResponse, ioe);
+        assertEquals(EXCEPTION1, errorResponse.getErrorMessage());
+        assertEquals(EXCEPTION1, errorResponse.getErrorDetails().get(0));
+        assertEquals("Exception 0", errorResponse.getErrorDetails().get(1));
     }
 }
index 318eaee..fb01d5e 100644 (file)
 
 package org.onap.policy.models.tosca.simple.serialization;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
-
 import java.util.Map;
-
 import org.junit.Test;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -132,7 +130,7 @@ public class MonitoringPolicySerializationTest {
 
     @Test
     public void testSerialization() {
-        try {
+        assertThatCode(() -> {
             // vCPE
             JpaToscaServiceTemplate serviceTemplate = deserializeMonitoringInputJson(VCPE_MON_INPUT_JSON);
             String serializedServiceTemplate = serializeMonitoringServiceTemplate(serviceTemplate);
@@ -148,10 +146,7 @@ public class MonitoringPolicySerializationTest {
             serializedServiceTemplate = serializeMonitoringServiceTemplate(serviceTemplate);
             verifyVfwMonitoringOutputserialization(serializedServiceTemplate);
 
-        } catch (Exception e) {
-            LOGGER.warn("No exception should be thrown", e);
-            fail("No exception should be thrown");
-        }
+        }).as("No exception should be thrown").doesNotThrowAnyException();
     }
 
     private JpaToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath) throws Exception {