Use OSGi DS for MessageIntelligenceAgencyImpl
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ClearStatsCommandProviderTest.java
index 8b016e982a7272a7477c6c111bc222c34b6ba59d..3d24436290eef02ac47a1558b11a2d6bdb834d28 100644 (file)
@@ -5,47 +5,41 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.karaf;
 
-import com.google.common.base.Function;
-import javax.annotation.Nullable;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.function.Function;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
-import org.opendaylight.openflowplugin.impl.OpenFlowPluginProviderImpl;
+import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 
 /**
  * Test for {@link ClearStatsCommandProvider}.
  */
 public class ClearStatsCommandProviderTest extends AbstractKarafTest {
+    private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION =
+        input -> input.endsWith(": no activity detected");
 
-    private ClearStatsCommandProvider clearStatsCommandProvider;
-    private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = new Function<String, Boolean>() {
-        @Nullable
-        @Override
-        public Boolean apply(String input) {
-            return input.endsWith(": no activity detected");
-        }
-    };
-    private MessageIntelligenceAgency mi5;
+    private final MessageIntelligenceAgency mi5 = new MessageIntelligenceAgencyImpl();
+    private final ClearStatsCommandProvider clearStatsCommandProvider = new ClearStatsCommandProvider();
 
     @Override
     public void doSetUp() {
-        clearStatsCommandProvider = new ClearStatsCommandProvider();
-        mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
-        mi5.resetStatistics();
-        Mockito.when(cmdSession.getConsole()).thenReturn(console);
+        clearStatsCommandProvider.messageIntelligenceAgency = mi5;
+        when(cmdSession.getConsole()).thenReturn(console);
     }
 
     @After
     public void tearDown() {
-        Mockito.verify(console).print(Matchers.anyString());
+        verify(console).print(anyString());
         mi5.resetStatistics();
     }
 
@@ -54,10 +48,10 @@ public class ClearStatsCommandProviderTest extends AbstractKarafTest {
      */
     @Test
     public void testDoExecute_clean() throws Exception {
-        Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+        assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
         clearStatsCommandProvider.execute(cmdSession);
 
-        Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+        assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
     }
 
     /**
@@ -65,12 +59,11 @@ public class ClearStatsCommandProviderTest extends AbstractKarafTest {
      */
     @Test
     public void testDoExecute_dirty() throws Exception {
-        mi5 = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
-        Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+        assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
         mi5.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
-        Assert.assertFalse(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+        assertFalse(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
 
         clearStatsCommandProvider.execute(cmdSession);
-        Assert.assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+        assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
     }
 }