X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fkaraf%2FShowStatsCommandProviderTest.java;h=69a07f9eda44e41ebd9507cba76157845161f901;hb=6d7be341aa04f534b1cb0180336931aed6028cab;hp=cb96800a741a4a4296e2bce55c6f86a988f4022f;hpb=8a8f8b1fed451184aec459b720141d6236d60be6;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/karaf/ShowStatsCommandProviderTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/karaf/ShowStatsCommandProviderTest.java index cb96800a74..69a07f9eda 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/karaf/ShowStatsCommandProviderTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/karaf/ShowStatsCommandProviderTest.java @@ -5,74 +5,60 @@ * 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 org.junit.After; -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Matchers; -import org.mockito.Mockito; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import java.util.function.Function; +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.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 { +class ShowStatsCommandProviderTest extends AbstractKarafTest { + private final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl(); - private ShowStatsCommandProvider showStatsCommandProvider; - private MessageIntelligenceAgency messageIntelligenceAgency; + @InjectMocks + private ShowStatsCommandProvider showStatsCommand; - private static final Function CHECK_NO_ACTIVITY_FUNCTION = new Function() { - @Nullable - @Override - public Boolean apply(String input) { - return input.endsWith(": no activity detected"); - } - }; + private static final Function CHECK_NO_ACTIVITY_FUNCTION = + input -> input.endsWith(": no activity detected"); @Override - public void doSetUp() { - showStatsCommandProvider = new ShowStatsCommandProvider(); - messageIntelligenceAgency = OpenFlowPluginProviderImpl.getMessageIntelligenceAgency(); - messageIntelligenceAgency.resetStatistics(); - } - - @After - public void tearDown() throws Exception { - // Pattern.DOTALL is set inline via "(?s)" at the beginning - Mockito.verify(console).print(Matchers.matches("(?s).+")); + protected void doBeforeEach() { + showStatsCommand.messageIntelligenceAgency = messageIntelligenceAgency; messageIntelligenceAgency.resetStatistics(); + assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION); } /** - * Test for {@link ShowEventTimesComandProvider#doExecute()} when no stats were touched before. + * Test for {@link ShowEventTimesComandProvider#execute()} when no stats were touched before. */ @Test - public void testDoExecute_clean() throws Exception { - Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION)); - showStatsCommandProvider.execute(cmdSession); - Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION)); + void showNoActivity() { + showStatsCommand.execute(); + verify(console, never()).println(); + assertNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION); } /** - * Test for {@link ShowEventTimesComandProvider#doExecute()} when stats were touched before. + * Test for {@link ShowEventTimesComandProvider#execute()} when stats were touched before. */ @Test - public void testDoExecute_dirty() throws Exception { - Assert.assertTrue(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), CHECK_NO_ACTIVITY_FUNCTION)); - + void showHavingActivity() { messageIntelligenceAgency.spyMessage(OfHeader.class, MessageSpy.StatisticsGroup.FROM_SWITCH); - Assert.assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), - CHECK_NO_ACTIVITY_FUNCTION)); + assertHasActivity(messageIntelligenceAgency.provideIntelligence(),CHECK_NO_ACTIVITY_FUNCTION); - showStatsCommandProvider.execute(cmdSession); - Assert.assertFalse(checkNoActivity(messageIntelligenceAgency.provideIntelligence(), - CHECK_NO_ACTIVITY_FUNCTION)); + showStatsCommand.execute(); + verify(console, atLeastOnce()).println(anyString()); + assertHasActivity(messageIntelligenceAgency.provideIntelligence(),CHECK_NO_ACTIVITY_FUNCTION); } -} \ No newline at end of file +}