Cleanup use of Guava Function
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / karaf / ShowEventTimesComandProviderTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.karaf;
9
10 import static org.mockito.ArgumentMatchers.contains;
11
12 import java.util.function.Function;
13 import org.junit.After;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
18 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
19
20 /**
21  * Test for {@link ShowEventTimesComandProvider}.
22  */
23 public class ShowEventTimesComandProviderTest extends AbstractKarafTest {
24
25     private ShowEventTimesComandProvider showEventTimesComandProvider;
26     private static final Function<String, Boolean> CHECK_NO_ACTIVITY_FUNCTION = String::isEmpty;
27
28     @Override
29
30     public void doSetUp() {
31         showEventTimesComandProvider = new ShowEventTimesComandProvider();
32         EventsTimeCounter.resetAllCounters();
33     }
34
35     @After
36     public void tearDown() {
37         EventsTimeCounter.resetAllCounters();
38     }
39
40     /**
41      * Test for {@link ShowEventTimesComandProvider#doExecute()} when no stats were touched before.
42      */
43     @Test
44     public void testDoExecute_clean() throws Exception {
45         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
46         showEventTimesComandProvider.execute(cmdSession);
47         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
48         Mockito.verify(console).print("");
49     }
50
51     /**
52      * Test for {@link ShowEventTimesComandProvider#doExecute()} when stats were touched before.
53      */
54     @Test
55     public void testDoExecute_dirty() throws Exception {
56         final EventIdentifier dummyEvent = new EventIdentifier("junit", "junitDevice");
57         Assert.assertTrue(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
58
59         EventsTimeCounter.markStart(dummyEvent);
60         EventsTimeCounter.markEnd(dummyEvent);
61         Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
62
63         showEventTimesComandProvider.execute(cmdSession);
64         Assert.assertFalse(checkNoActivity(EventsTimeCounter.provideTimes(), CHECK_NO_ACTIVITY_FUNCTION));
65         Mockito.verify(console).print(contains("junitDevice"));
66     }
67 }