Use OSGi DS for MessageIntelligenceAgencyImpl
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ShowStatsCommandProviderTest.java
index f9bb9763bff07a459c804d52548770420708ab43..c7b517c0506554a3f81228035852be09f0f72dce 100644 (file)
@@ -8,40 +8,38 @@
 
 package org.opendaylight.openflowplugin.impl.karaf;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.matches;
+import static org.mockito.Mockito.verify;
 
 import java.util.function.Function;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Test;
-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 ShowStatsCommandProvider}.
  */
 public class ShowStatsCommandProviderTest extends AbstractKarafTest {
-
-    private ShowStatsCommandProvider showStatsCommandProvider;
-    private MessageIntelligenceAgency messageIntelligenceAgency;
+    private final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
+    private final ShowStatsCommandProvider showStatsCommandProvider = new ShowStatsCommandProvider();
 
     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION =
         input -> input.endsWith(": no activity detected");
 
     @Override
     public void doSetUp() {
-        showStatsCommandProvider = new ShowStatsCommandProvider();
-        messageIntelligenceAgency = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency();
-        messageIntelligenceAgency.resetStatistics();
+        showStatsCommandProvider.messageIntelligenceAgency = messageIntelligenceAgency;
     }
 
     @After
     public void tearDown() {
         // Pattern.DOTALL is set inline via "(?s)" at the beginning
-        Mockito.verify(console).print(matches("(?s).+"));
+        verify(console).print(matches("(?s).+"));
         messageIntelligenceAgency.resetStatistics();
     }
 
@@ -50,9 +48,9 @@ public class ShowStatsCommandProviderTest extends AbstractKarafTest {
      */
     @Test
     public void testDoExecute_clean() throws Exception {
-        Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+        assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
         showStatsCommandProvider.execute(cmdSession);
-        Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+        assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
     }
 
     /**
@@ -60,14 +58,12 @@ public class ShowStatsCommandProviderTest extends AbstractKarafTest {
      */
     @Test
     public void testDoExecute_dirty() throws Exception {
-        Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+        assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
 
         messageIntelligenceAgency.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
-        Assert.assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(),
-                CHECK_NO_ACTIVITY_FUNCTION));
+        assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
 
         showStatsCommandProvider.execute(cmdSession);
-        Assert.assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(),
-                CHECK_NO_ACTIVITY_FUNCTION));
+        assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
     }
 }