*/
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;
/**
* 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);
}
}