Eliminate blueprint for openflowplugins-impl karaf commands
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ClearStatsCommandProviderTest.java
index 3d24436290eef02ac47a1558b11a2d6bdb834d28..c797fd2ec4a707471a1fb48c1b873ae36a859ef3 100644 (file)
@@ -7,15 +7,12 @@
  */
 package org.opendaylight.openflowplugin.impl.karaf;
 
-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.Test;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyImpl;
@@ -24,46 +21,41 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 /**
  * Test for {@link ClearStatsCommandProvider}.
  */
-public class ClearStatsCommandProviderTest extends AbstractKarafTest {
+class ClearStatsCommandProviderTest extends AbstractKarafTest {
     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION =
         input -> input.endsWith(": no activity detected");
 
-    private final MessageIntelligenceAgency mi5 = new MessageIntelligenceAgencyImpl();
-    private final ClearStatsCommandProvider clearStatsCommandProvider = new ClearStatsCommandProvider();
+    private final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
 
-    @Override
-    public void doSetUp() {
-        clearStatsCommandProvider.messageIntelligenceAgency = mi5;
-        when(cmdSession.getConsole()).thenReturn(console);
-    }
+    @InjectMocks
+    private ClearStatsCommandProvider clearStatsCommand;
 
-    @After
-    public void tearDown() {
-        verify(console).print(anyString());
-        mi5.resetStatistics();
+    @Override
+    protected void doBeforeEach() {
+        clearStatsCommand.messageIntelligenceAgency = messageIntelligenceAgency;
+        messageIntelligenceAgency.resetStatistics();
+        assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
     }
 
     /**
-     * Test for {@link ClearStatsCommandProvider#doExecute()} when no stats were touched before.
+     * Test for {@link ClearStatsCommandProvider#execute()} when no stats were touched before.
      */
     @Test
-    public void testDoExecute_clean() throws Exception {
-        assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
-        clearStatsCommandProvider.execute(cmdSession);
-
-        assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+    void clearNoActivity() {
+        clearStatsCommand.execute();
+        verify(console).println(anyString());
+        assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
     }
 
     /**
-     * Test for {@link ClearStatsCommandProvider#doExecute()} when stats were touched before.
+     * Test for {@link ClearStatsCommandProvider#execute()} when stats were touched before.
      */
     @Test
-    public void testDoExecute_dirty() throws Exception {
-        assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
-        mi5.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
-        assertFalse(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
-
-        clearStatsCommandProvider.execute(cmdSession);
-        assertTrue(checkNoActivity(mi5.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION));
+    void clearHavingActivity() {
+        messageIntelligenceAgency.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH);
+        assertHasActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
+        clearStatsCommand.execute();
+        verify(console).println(anyString());
+        assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION);
     }
 }