BGPCEP-742 Fix BGP NPE filter null BGP State
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / state / BGPStateCollectorImplTest.java
index 9b201d52f1c0d98e5ac2e8c4ade8ae2ae996c713..dc5f3584fb6f38f9123a19d017fb7b9e2a78b350 100644 (file)
@@ -31,12 +31,12 @@ public class BGPStateCollectorImplTest {
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-        doReturn(mock(BGPPeerState.class)).when(this.bgpPeerStateConsumer).getPeerState();
-        doReturn(mock(BGPRIBState.class)).when(this.bgpribStateConsumer).getRIBState();
     }
 
     @Test
-    public void getRibStats() throws Exception {
+    public void getRibStatsTest() throws Exception {
+        doReturn(mock(BGPPeerState.class)).when(this.bgpPeerStateConsumer).getPeerState();
+        doReturn(mock(BGPRIBState.class)).when(this.bgpribStateConsumer).getRIBState();
         final BGPStateCollectorImpl collector = new BGPStateCollectorImpl();
         final BGPRIBStateConsumer ribStateConsumerNull = null;
         collector.bind(ribStateConsumerNull);
@@ -56,4 +56,42 @@ public class BGPStateCollectorImplTest {
         assertTrue(collector.getRibStats().isEmpty());
         assertTrue(collector.getPeerStats().isEmpty());
     }
+
+    @Test
+    public void getRibStatsEmptyPeerTest() throws Exception {
+        doReturn(mock(BGPRIBState.class)).when(this.bgpribStateConsumer).getRIBState();
+        doReturn(null).when(this.bgpPeerStateConsumer).getPeerState();
+        final BGPStateCollectorImpl collector = new BGPStateCollectorImpl();
+        final BGPRIBStateConsumer ribStateConsumerNull = null;
+        collector.bind(ribStateConsumerNull);
+        assertTrue(collector.getRibStats().isEmpty());
+
+        final BGPPeerStateConsumer peerStateConsumerNull = null;
+        collector.bind(peerStateConsumerNull);
+        assertTrue(collector.getPeerStats().isEmpty());
+
+        collector.bind(this.bgpribStateConsumer);
+        collector.bind(this.bgpPeerStateConsumer);
+        assertFalse(collector.getRibStats().isEmpty());
+        assertTrue(collector.getPeerStats().isEmpty());
+    }
+
+    @Test
+    public void getRibStatsEmptyRibTest() throws Exception {
+        doReturn(null).when(this.bgpribStateConsumer).getRIBState();
+        doReturn(null).when(this.bgpPeerStateConsumer).getPeerState();
+        final BGPStateCollectorImpl collector = new BGPStateCollectorImpl();
+        final BGPRIBStateConsumer ribStateConsumerNull = null;
+        collector.bind(ribStateConsumerNull);
+        assertTrue(collector.getRibStats().isEmpty());
+
+        final BGPPeerStateConsumer peerStateConsumerNull = null;
+        collector.bind(peerStateConsumerNull);
+        assertTrue(collector.getPeerStats().isEmpty());
+
+        collector.bind(this.bgpribStateConsumer);
+        collector.bind(this.bgpPeerStateConsumer);
+        assertTrue(collector.getRibStats().isEmpty());
+        assertTrue(collector.getPeerStats().isEmpty());
+    }
 }
\ No newline at end of file