aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-02-08 13:22:06 -0500
committerJim Hahn <jrh3@att.com>2019-02-11 14:41:40 -0500
commit504970756b35b5f9e5388ee32c53f83d659b4ef1 (patch)
tree5c9d227dafff182df1bec1544d444994bb3bccf5
parentb695d1743c34e4fb1087c8766b8c41eb3aae926e (diff)
Replace PolicyAssert with assertj
PolicyAssert has a sonar issue and is no longer needed, as the same functionality (and more) is provided by assertj. Modified drools-pdp test code to replace PolicyAssert with assertj. Updated license dates. Removed trailing spaces. Remove assertj version from poms, as it's now included in parent pom. Change-Id: Ica82a959613e082dc6ed6fc9e103a198c2f17537 Issue-ID: POLICY-1393 Signed-off-by: Jim Hahn <jrh3@att.com>
-rw-r--r--feature-pooling-dmaap/pom.xml1
-rw-r--r--policy-core/pom.xml1
-rw-r--r--policy-management/pom.xml22
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java69
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java118
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java25
6 files changed, 125 insertions, 111 deletions
diff --git a/feature-pooling-dmaap/pom.xml b/feature-pooling-dmaap/pom.xml
index 6ff89ed1..6cce1f2b 100644
--- a/feature-pooling-dmaap/pom.xml
+++ b/feature-pooling-dmaap/pom.xml
@@ -150,7 +150,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
- <version>3.11.1</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/policy-core/pom.xml b/policy-core/pom.xml
index 42807489..83c3baea 100644
--- a/policy-core/pom.xml
+++ b/policy-core/pom.xml
@@ -118,7 +118,6 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
- <version>3.11.1</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/policy-management/pom.xml b/policy-management/pom.xml
index 061c5b06..5d3d9eeb 100644
--- a/policy-management/pom.xml
+++ b/policy-management/pom.xml
@@ -3,14 +3,14 @@
============LICENSE_START=======================================================
ONAP Policy Engine - Drools PDP
================================================================================
- Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -134,7 +134,7 @@
</goals>
<phase>process-sources</phase>
<configuration>
- <!-- Use Google Java Style Guide: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
+ <!-- Use Google Java Style Guide: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
with minor changes -->
<configLocation>onap-checkstyle/onap-java-style.xml</configLocation>
<!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory -->
@@ -255,10 +255,10 @@
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
-
+
<!-- if we don't explicitly specify the version here, we seem to end up
with version 1.4 (as a dependency to drools-core). This version is
- not compatible with 'saClientLibrary' version 1.2.1-oss
+ not compatible with 'saClientLibrary' version 1.2.1-oss
-->
<dependency>
<groupId>commons-codec</groupId>
@@ -275,7 +275,7 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
@@ -288,7 +288,7 @@
<version>${policy.common.version}</version>
<scope>test</scope>
</dependency>
-
+
<!--
The following dependencies are for features and drools
applications usage
@@ -324,6 +324,12 @@
<artifactId>commons-io</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java
index f5c71064..f5fc8a5c 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
package org.onap.policy.drools.system;
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
@@ -28,7 +30,6 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.policy.common.utils.test.PolicyAssert.assertThrows;
import java.util.Arrays;
import java.util.Collections;
@@ -127,7 +128,7 @@ public class PolicyControllerFactoryTest {
@Test
public void testPatchStringDroolsConfiguration() {
// unknown controller
- assertThrows(IllegalArgumentException.class, () -> ipc.patch(MY_NAME, config));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.patch(MY_NAME, config));
/*
* Build controller to be used by remaining tests.
@@ -136,10 +137,10 @@ public class PolicyControllerFactoryTest {
// null name
String nullName = null;
- assertThrows(IllegalArgumentException.class, () -> ipc.patch(nullName, config));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.patch(nullName, config));
// empty name
- assertThrows(IllegalArgumentException.class, () -> ipc.patch("", config));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.patch("", config));
// success
ipc.patch(MY_NAME, config);
@@ -153,7 +154,7 @@ public class PolicyControllerFactoryTest {
}
};
ipc.build(MY_NAME, properties);
- assertThrows(IllegalArgumentException.class, () -> ipc.patch(MY_NAME, config));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.patch(MY_NAME, config));
}
@Test
@@ -163,10 +164,10 @@ public class PolicyControllerFactoryTest {
// null controller
PolicyController nullCtlr = null;
- assertThrows(IllegalArgumentException.class, () -> ipc.patch(nullCtlr, config));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.patch(nullCtlr, config));
// null config
- assertThrows(IllegalArgumentException.class, () -> ipc.patch(controller, null));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.patch(controller, null));
// brained
when(drools.isBrained()).thenReturn(true);
@@ -174,17 +175,17 @@ public class PolicyControllerFactoryTest {
// update failed
when(controller.updateDrools(config)).thenReturn(false);
- assertThrows(IllegalArgumentException.class, () -> ipc.patch(controller, config));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.patch(controller, config));
}
@Test
public void testShutdownString() {
// null name
String nullName = null;
- assertThrows(IllegalArgumentException.class, () -> ipc.shutdown(nullName));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.shutdown(nullName));
// empty name
- assertThrows(IllegalArgumentException.class, () -> ipc.shutdown(""));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.shutdown(""));
// unknown controller
ipc.shutdown(MY_NAME);
@@ -205,7 +206,7 @@ public class PolicyControllerFactoryTest {
verify(controller).shutdown();
// should no longer be managed
- assertThrows(IllegalArgumentException.class, () -> ipc.get(MY_NAME));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(MY_NAME));
}
@Test
@@ -219,8 +220,8 @@ public class PolicyControllerFactoryTest {
verify(controller2).shutdown();
// should no longer be managed
- assertThrows(IllegalArgumentException.class, () -> ipc.get(MY_NAME));
- assertThrows(IllegalArgumentException.class, () -> ipc.get(MY_NAME2));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(MY_NAME));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(MY_NAME2));
}
@Test
@@ -234,14 +235,14 @@ public class PolicyControllerFactoryTest {
verify(controller2, never()).shutdown();
// should no longer be managed
- assertThrows(IllegalArgumentException.class, () -> ipc.get(MY_NAME));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(MY_NAME));
// should still be managed
assertEquals(controller2, ipc.get(MY_NAME2));
// null controller
PolicyController nullCtlr = null;
- assertThrows(IllegalArgumentException.class, () -> ipc.shutdown(nullCtlr));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.shutdown(nullCtlr));
// unknown controller
ipc.shutdown(controller);
@@ -252,10 +253,10 @@ public class PolicyControllerFactoryTest {
public void testDestroyString() {
// null name
String nullName = null;
- assertThrows(IllegalArgumentException.class, () -> ipc.destroy(nullName));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.destroy(nullName));
// empty name
- assertThrows(IllegalArgumentException.class, () -> ipc.destroy(""));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.destroy(""));
// unknown controller
ipc.destroy(MY_NAME);
@@ -276,7 +277,7 @@ public class PolicyControllerFactoryTest {
verify(controller).halt();
// should no longer be managed
- assertThrows(IllegalArgumentException.class, () -> ipc.get(MY_NAME));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(MY_NAME));
}
@Test
@@ -290,14 +291,14 @@ public class PolicyControllerFactoryTest {
verify(controller2).halt();
// should no longer be managed
- assertThrows(IllegalArgumentException.class, () -> ipc.get(MY_NAME));
- assertThrows(IllegalArgumentException.class, () -> ipc.get(MY_NAME2));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(MY_NAME));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(MY_NAME2));
}
@Test
public void testGetString() {
// unknown name
- assertThrows(IllegalArgumentException.class, () -> ipc.get(MY_NAME));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(MY_NAME));
ipc.build(MY_NAME, properties);
ipc.build(MY_NAME2, properties);
@@ -307,16 +308,16 @@ public class PolicyControllerFactoryTest {
// null name
String nullName = null;
- assertThrows(IllegalArgumentException.class, () -> ipc.get(nullName));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(nullName));
// empty name
- assertThrows(IllegalArgumentException.class, () -> ipc.get(""));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(""));
}
@Test
public void testGetStringString_testToKey() {
// unknown controller
- assertThrows(IllegalArgumentException.class, () -> ipc.get(GROUP1, ARTIFACT1));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(GROUP1, ARTIFACT1));
when(drools.isBrained()).thenReturn(true);
when(drools2.isBrained()).thenReturn(true);
@@ -328,22 +329,22 @@ public class PolicyControllerFactoryTest {
assertEquals(controller2, ipc.get(GROUP2, ARTIFACT2));
// null group
- assertThrows(IllegalArgumentException.class, () -> ipc.get(null, ARTIFACT1));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(null, ARTIFACT1));
// empty group
- assertThrows(IllegalArgumentException.class, () -> ipc.get("", ARTIFACT1));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get("", ARTIFACT1));
// null artifact
- assertThrows(IllegalArgumentException.class, () -> ipc.get(GROUP1, null));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(GROUP1, null));
// empty artifact
- assertThrows(IllegalArgumentException.class, () -> ipc.get(GROUP1, ""));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(GROUP1, ""));
}
@Test
public void testGetDroolsController() {
// unknown controller
- assertThrows(IllegalStateException.class, () -> ipc.get(drools));
+ assertThatIllegalStateException().isThrownBy(() -> ipc.get(drools));
when(drools.isBrained()).thenReturn(true);
when(drools2.isBrained()).thenReturn(true);
@@ -356,7 +357,7 @@ public class PolicyControllerFactoryTest {
// null controller
DroolsController nullDrools = null;
- assertThrows(IllegalArgumentException.class, () -> ipc.get(nullDrools));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.get(nullDrools));
}
@Test
@@ -382,13 +383,13 @@ public class PolicyControllerFactoryTest {
@Test
public void testGetFeatureProvider() {
// null name
- assertThrows(IllegalArgumentException.class, () -> ipc.getFeatureProvider(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.getFeatureProvider(null));
// empty name
- assertThrows(IllegalArgumentException.class, () -> ipc.getFeatureProvider(""));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.getFeatureProvider(""));
// unknown name
- assertThrows(IllegalArgumentException.class, () -> ipc.getFeatureProvider("unknown-feature"));
+ assertThatIllegalArgumentException().isThrownBy(() -> ipc.getFeatureProvider("unknown-feature"));
assertEquals(feature1, ipc.getFeatureProvider(FEATURE1));
assertEquals(feature2, ipc.getFeatureProvider(FEATURE2));
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index 5329dcc3..4f7e1b0a 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,9 @@
package org.onap.policy.drools.system;
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -33,7 +36,6 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.policy.common.utils.test.PolicyAssert.assertThrows;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -51,7 +53,6 @@ import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactory;
-import org.onap.policy.common.utils.test.PolicyAssert.RunnableWithEx;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
import org.onap.policy.drools.features.PolicyEngineFeatureAPI;
@@ -398,7 +399,7 @@ public class PolicyEngineManagerTest {
// null properties - nothing should be invoked
setUp();
Properties nullProps = null;
- assertThrows(IllegalArgumentException.class, () -> mgr.configure(nullProps));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.configure(nullProps));
verify(prov1, never()).beforeConfigure(mgr, properties);
verify(prov1, never()).afterConfigure(mgr);
@@ -422,10 +423,10 @@ public class PolicyEngineManagerTest {
// invalid params
PdpdConfiguration nullConfig = null;
- assertThrows(IllegalArgumentException.class, () -> mgr.configure(nullConfig));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.configure(nullConfig));
pdpConfig.setEntity("unknown-entity");
- assertThrows(IllegalArgumentException.class, () -> mgr.configure(pdpConfig));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.configure(pdpConfig));
// source list of size 1
setUp();
@@ -482,7 +483,7 @@ public class PolicyEngineManagerTest {
// mismatching name in properties - nothing should happen besides exception
setUp();
properties.setProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME, "mistmatched-name");
- assertThrows(IllegalStateException.class, () -> mgr.createPolicyController(MY_NAME, properties));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.createPolicyController(MY_NAME, properties));
verify(contProv1, never()).beforeCreate(MY_NAME, properties);
// first provider generates controller - stops after first provider
@@ -543,29 +544,29 @@ public class PolicyEngineManagerTest {
verify(engine).createPolicyController(CONTROLLER3, properties);
// invalid parameters
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(null));
// invalid name
setUp();
config3.setName(null);
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(config3));
config3.setName("");
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(config3));
// invalid operation
setUp();
config3.setOperation(null);
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(config3));
config3.setOperation("");
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(config3));
config3.setOperation(ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_LOCK);
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(config3));
config3.setOperation(ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_UNLOCK);
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(config3));
// exception from get() - should create controller
setUp();
@@ -576,12 +577,12 @@ public class PolicyEngineManagerTest {
// null properties
setUp();
when(persist.getControllerProperties(CONTROLLER3)).thenReturn(null);
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(config3));
// throw linkage error
setUp();
when(persist.getControllerProperties(CONTROLLER3)).thenThrow(new LinkageError(EXPECTED));
- assertThrows(IllegalStateException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.updatePolicyController(config3));
/*
* For remaining tests, the factory will return the controller instead of creating
@@ -629,7 +630,7 @@ public class PolicyEngineManagerTest {
// invalid operation
config3.setOperation("invalid-operation");
- assertThrows(IllegalArgumentException.class, () -> mgr.updatePolicyController(config3));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.updatePolicyController(config3));
}
@Test
@@ -669,7 +670,7 @@ public class PolicyEngineManagerTest {
setUp();
mgr.configure(properties);
mgr.lock();
- assertThrows(IllegalStateException.class, () -> mgr.start());
+ assertThatIllegalStateException().isThrownBy(() -> mgr.start());
verify(prov2).beforeStart(mgr);
verify(server2, never()).waitedStart(anyLong());
verify(source2, never()).start();
@@ -1152,13 +1153,13 @@ public class PolicyEngineManagerTest {
assertEquals(prov2, mgr.getFeatureProvider(FEATURE2));
// null feature
- assertThrows(IllegalArgumentException.class, () -> mgr.getFeatureProvider(null));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.getFeatureProvider(null));
// empty feature
- assertThrows(IllegalArgumentException.class, () -> mgr.getFeatureProvider(""));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.getFeatureProvider(""));
// unknown feature
- assertThrows(IllegalArgumentException.class, () -> mgr.getFeatureProvider("unknown-feature"));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.getFeatureProvider("unknown-feature"));
}
@Test
@@ -1186,20 +1187,20 @@ public class PolicyEngineManagerTest {
// invalid parameters
String nullStr = null;
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(nullStr, MY_EVENT));
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver("", MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(nullStr, MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver("", MY_EVENT));
Object nullObj = null;
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(MY_TOPIC, nullObj));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(MY_TOPIC, nullObj));
// locked
mgr.lock();
- assertThrows(IllegalStateException.class, () -> mgr.deliver(MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(MY_TOPIC, MY_EVENT));
mgr.unlock();
// not running
mgr.stop();
- assertThrows(IllegalStateException.class, () -> mgr.deliver(MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(MY_TOPIC, MY_EVENT));
// issues with topic
setUp();
@@ -1208,15 +1209,15 @@ public class PolicyEngineManagerTest {
// null sinks
when(endpoint.getTopicSinks(MY_TOPIC)).thenReturn(null);
- assertThrows(IllegalStateException.class, () -> mgr.deliver(MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(MY_TOPIC, MY_EVENT));
// empty sinks
when(endpoint.getTopicSinks(MY_TOPIC)).thenReturn(Collections.emptyList());
- assertThrows(IllegalStateException.class, () -> mgr.deliver(MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(MY_TOPIC, MY_EVENT));
// too many sinks
when(endpoint.getTopicSinks(MY_TOPIC)).thenReturn(sinks);
- assertThrows(IllegalStateException.class, () -> mgr.deliver(MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(MY_TOPIC, MY_EVENT));
}
@Test
@@ -1230,24 +1231,24 @@ public class PolicyEngineManagerTest {
// invalid parameters
String nullStr = null;
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(nullStr, MY_TOPIC, MY_EVENT));
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver("", MY_TOPIC, MY_EVENT));
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver("unknown-bus-type", MY_TOPIC, MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(nullStr, MY_TOPIC, MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver("", MY_TOPIC, MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver("unknown-bus-type", MY_TOPIC, MY_EVENT));
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(NOOP_STR, nullStr, MY_EVENT));
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(NOOP_STR, "", MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(NOOP_STR, nullStr, MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(NOOP_STR, "", MY_EVENT));
Object nullObj = null;
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(NOOP_STR, MY_TOPIC, nullObj));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(NOOP_STR, MY_TOPIC, nullObj));
// locked
mgr.lock();
- assertThrows(IllegalStateException.class, () -> mgr.deliver(NOOP_STR, MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(NOOP_STR, MY_TOPIC, MY_EVENT));
mgr.unlock();
// not running
mgr.stop();
- assertThrows(IllegalStateException.class, () -> mgr.deliver(NOOP_STR, MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(NOOP_STR, MY_TOPIC, MY_EVENT));
}
@Test
@@ -1263,27 +1264,28 @@ public class PolicyEngineManagerTest {
verify(sink1).send(MESSAGE);
// invalid parameters
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(CommInfrastructure.NOOP, null, MY_EVENT));
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(CommInfrastructure.NOOP, "", MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, null, MY_EVENT));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, "", MY_EVENT));
Object nullObj = null;
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, nullObj));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, nullObj));
// locked
mgr.lock();
- assertThrows(IllegalStateException.class, () -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MY_EVENT));
mgr.unlock();
// not started
mgr.stop();
- assertThrows(IllegalStateException.class, () -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MY_EVENT));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MY_EVENT));
// send() throws an exception
setUp();
mgr.configure(properties);
mgr.start();
when(sink1.send(any())).thenThrow(new ArithmeticException(EXPECTED));
- assertThrows(ArithmeticException.class, () -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MY_EVENT));
+ assertThatThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MY_EVENT))
+ .isInstanceOf(ArithmeticException.class);
/*
* For remaining tests, have the controller handle delivery.
@@ -1321,7 +1323,7 @@ public class PolicyEngineManagerTest {
mgr.configure(properties);
// not started yet
- assertThrows(IllegalStateException.class, () -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MESSAGE));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MESSAGE));
// start it
mgr.start();
@@ -1331,19 +1333,20 @@ public class PolicyEngineManagerTest {
verify(sink2, never()).send(any());
// invalid parameters
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(CommInfrastructure.NOOP, null, MESSAGE));
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(CommInfrastructure.NOOP, "", MESSAGE));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, null, MESSAGE));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, "", MESSAGE));
String nullStr = null;
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, nullStr));
- assertThrows(IllegalArgumentException.class, () -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, ""));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, nullStr));
+ assertThatIllegalArgumentException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, ""));
// unknown topic
- assertThrows(IllegalStateException.class, () -> mgr.deliver(CommInfrastructure.NOOP, "unknown-topic", MESSAGE));
+ assertThatIllegalStateException()
+ .isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, "unknown-topic", MESSAGE));
// locked
mgr.lock();
- assertThrows(IllegalStateException.class, () -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MESSAGE));
+ assertThatIllegalStateException().isThrownBy(() -> mgr.deliver(CommInfrastructure.NOOP, MY_TOPIC, MESSAGE));
mgr.unlock();
}
@@ -1597,7 +1600,7 @@ public class PolicyEngineManagerTest {
verifyMiddle.run();
verifyAfter.accept(prov1);
- assertThrows(AssertionError.class, () -> verifyAfter.accept(prov2));
+ assertThatThrownBy(() -> verifyAfter.accept(prov2)).isInstanceOf(AssertionError.class);
}
/**
@@ -1635,12 +1638,12 @@ public class PolicyEngineManagerTest {
verifyBefore.accept(prov1);
// remaining methods should not have been invoked
- assertThrows(AssertionError.class, () -> verifyBefore.accept(prov2));
+ assertThatThrownBy(() -> verifyBefore.accept(prov2)).isInstanceOf(AssertionError.class);
- assertThrows(AssertionError.class, () -> verifyMiddle.run());
+ assertThatThrownBy(() -> verifyMiddle.run()).isInstanceOf(AssertionError.class);
- assertThrows(AssertionError.class, () -> verifyAfter.accept(prov1));
- assertThrows(AssertionError.class, () -> verifyAfter.accept(prov2));
+ assertThatThrownBy(() -> verifyAfter.accept(prov1)).isInstanceOf(AssertionError.class);
+ assertThatThrownBy(() -> verifyAfter.accept(prov2)).isInstanceOf(AssertionError.class);
}
/**
@@ -1739,4 +1742,9 @@ public class PolicyEngineManagerTest {
}
}
}
+
+ @FunctionalInterface
+ private static interface RunnableWithEx {
+ void run() throws Exception;
+ }
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java
index bb944fc9..83344486 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
package org.onap.policy.drools.system.internal;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -30,7 +32,6 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.onap.policy.common.utils.test.PolicyAssert.assertThrows;
import java.util.Arrays;
import java.util.List;
@@ -159,7 +160,7 @@ public class AggregatedPolicyControllerTest {
@Override
protected DroolsControllerFactory getDroolsFactory() {
throw new RuntimeException(EXPECTED);
- }
+ }
};
}
@@ -169,7 +170,7 @@ public class AggregatedPolicyControllerTest {
@Override
protected DroolsControllerFactory getDroolsFactory() {
throw new LinkageError(EXPECTED);
- }
+ }
};
}
@@ -322,7 +323,7 @@ public class AggregatedPolicyControllerTest {
apc.lock();
// start it
- assertThrows(IllegalStateException.class, () -> apc.start());
+ assertThatIllegalStateException().isThrownBy(() -> apc.start());
assertFalse(apc.isAlive());
@@ -877,7 +878,7 @@ public class AggregatedPolicyControllerTest {
verifyMiddle.run();
verifyAfter.accept(prov1);
- assertThrows(AssertionError.class, () -> verifyAfter.accept(prov2));
+ assertThatThrownBy(() -> verifyAfter.accept(prov2)).isInstanceOf(AssertionError.class);
}
/**
@@ -914,14 +915,14 @@ public class AggregatedPolicyControllerTest {
verifyBefore.accept(prov1);
// remaining methods should not have been invoked
- assertThrows(AssertionError.class, () -> verifyBefore.accept(prov2));
+ assertThatThrownBy(() -> verifyBefore.accept(prov2)).isInstanceOf(AssertionError.class);
- assertThrows(AssertionError.class, () -> verifyMiddle.run());
+ assertThatThrownBy(() -> verifyMiddle.run()).isInstanceOf(AssertionError.class);
- assertThrows(AssertionError.class, () -> verifyAfter.accept(prov1));
- assertThrows(AssertionError.class, () -> verifyAfter.accept(prov2));
+ assertThatThrownBy(() -> verifyAfter.accept(prov1)).isInstanceOf(AssertionError.class);
+ assertThatThrownBy(() -> verifyAfter.accept(prov2)).isInstanceOf(AssertionError.class);
}
-
+
/**
* Controller with overrides.
*/
@@ -949,6 +950,6 @@ public class AggregatedPolicyControllerTest {
@Override
protected List<PolicyControllerFeatureAPI> getProviders() {
return providers;
- }
+ }
}
}