Unit tests in dg-util 51/54951/2
authorMichal Kabaj <michal.kabaj@nokia.com>
Fri, 15 Jun 2018 09:53:55 +0000 (11:53 +0200)
committerTakamune Cho <tc012c@att.com>
Tue, 19 Jun 2018 12:55:45 +0000 (12:55 +0000)
Replace powermock usage with mockito.
Add assertj test dependency for assertions.

Change-Id: I8b268aaf4fe51f1709479a60919b987696f1a9a6
Issue-ID: APPC-1008
Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
appc-dg-util/appc-dg-util-bundle/pom.xml
appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java
appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java

index faf77e4..bc032ec 100644 (file)
             <artifactId>httpclient</artifactId>
             <version>4.5.3</version>
         </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.onap.ccsdk.sli.core</groupId>
             <artifactId>sli-common</artifactId>
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.powermock</groupId>
             <artifactId>powermock-api-mockito</artifactId>
index 4470137..910987c 100644 (file)
@@ -5,7 +5,9 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
- * =============================================================================
+ * ================================================================================
+ * Copyright (C) 2018 Nokia
+ * ================================================================================
  * 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
 
 package org.onap.appc.dg.util;
 
-import org.junit.Before;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
 import org.osgi.framework.BundleContext;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.modules.junit4.PowerMockRunner;
 
-@RunWith(PowerMockRunner.class)
+@RunWith(MockitoJUnitRunner.class)
 public class AppcDgUtilActivatorTest {
 
     @Mock
     private BundleContext bundleContext;
 
-    private AppcDgUtilActivator appcDgUtilActivator;
-
-    @Before
-    public void setUp() throws Exception {
-        appcDgUtilActivator = new AppcDgUtilActivator();
-    }
-
     @Test
     public void start() {
-        appcDgUtilActivator.start(bundleContext);
-        PowerMockito.verifyStatic();
+        new AppcDgUtilActivator().start(bundleContext);
+        verifyZeroInteractions(bundleContext);
     }
 
     @Test
     public void stop() {
-        appcDgUtilActivator.stop(bundleContext);
-        PowerMockito.verifyStatic();
+        new AppcDgUtilActivator().stop(bundleContext);
+        verifyZeroInteractions(bundleContext);
     }
 }
\ No newline at end of file
index 8bb1451..c59d5d4 100644 (file)
@@ -6,6 +6,8 @@
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
+ * Copyright (C) 2018 Nokia
+ * =============================================================================
  * 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
 
 package org.onap.appc.dg.util.impl;
 
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+import java.util.HashMap;
+import java.util.Map;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.appc.dg.util.UpgradeStubNode;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
-import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
-import org.onap.ccsdk.sli.adaptors.aai.AAIService;
-
-import java.util.HashMap;
-import java.util.Map;
 
+@RunWith(MockitoJUnitRunner.class)
 public class UpgradeStubNodeImplTest {
+
     @Mock
     private SvcLogicContext svcLogicContext;
 
-    private UpgradeStubNodeImpl upgradeStubNode;
+    private UpgradeStubNode upgradeStubNode;
 
     @Before
-    public void setUp() throws Exception {
+    public void setUp() {
         upgradeStubNode = new UpgradeStubNodeImpl();
     }
 
     @Test
-    public void testHandleUpgradeStubSuccess() throws APPCException {
+    public void handleUpgradeStub_shouldCompleteSuccessfully_whenFailureIndicatorIsNull() throws APPCException {
         Map<String, String> params = new HashMap<>();
         upgradeStubNode.handleUpgradeStub(params, svcLogicContext);
+        verifyZeroInteractions(svcLogicContext);
     }
 
-    @Test(expected = APPCException.class)
-    public void testHandleUpgradeStubException() throws APPCException {
+    @Test
+    public void handleUpgradeStub_shouldCompleteSuccessfully_whenFailureIndicatorIsFalse() throws APPCException {
+        // GIVEN
         Map<String, String> params = new HashMap<>();
-        params.put("failureIndicator", "true");
+        params.put("failureIndicator", "false");
+        // WHEN
         upgradeStubNode.handleUpgradeStub(params, svcLogicContext);
+        // THEN
+        verifyZeroInteractions(svcLogicContext);
+    }
+
+    @Test
+    public void handleUpgradeStub_shouldThrowAPPCException_whenFailureIndicatorIsTrue() throws APPCException {
+        // GIVEN
+        Map<String, String> params = new HashMap<>();
+        params.put("failureIndicator", "true");
+        // WHEN // THEN
+        assertThatExceptionOfType(APPCException.class)
+            .isThrownBy(() -> upgradeStubNode.handleUpgradeStub(params, svcLogicContext));
+        verifyZeroInteractions(svcLogicContext);
     }
 }
\ No newline at end of file