Fix checkstyle in BGPSessionImplTest 18/80818/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 13 Mar 2019 10:35:08 +0000 (11:35 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 13 Mar 2019 11:46:09 +0000 (12:46 +0100)
Rename a local variable and properly assert mocked exception.

Change-Id: I9f5087852f8d6720b9e218debbf86a74edf0942e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImplTest.java

index 2d3835c2cd935276b1ec52ec9cc285309922cc66..770711ea375ae338eb236a7c55bdcf1601b47685 100644 (file)
@@ -9,10 +9,12 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -218,10 +220,12 @@ public class BGPSessionImplTest {
 
     @Test
     public void testSessionRecoveryOnException() throws Exception {
-        final BGPSessionListener listener = mock(BGPSessionListener.class);
-        doThrow(new RuntimeException("Mocked runtime exception."))
-                .when(listener).onSessionUp(any());
-        this.bgpSession = spy(new BGPSessionImpl(listener, this.speakerListener, this.classicOpen,
+        final BGPSessionListener mockListener = mock(BGPSessionListener.class);
+        final IllegalStateException mockedEx = new IllegalStateException("Mocked runtime exception.");
+
+        doThrow(mockedEx).when(mockListener).onSessionUp(any());
+        doNothing().when(mockListener).onSessionTerminated(any(), any());
+        this.bgpSession = spy(new BGPSessionImpl(mockListener, this.speakerListener, this.classicOpen,
                 this.classicOpen.getHoldTimer(), null));
         this.bgpSession.setChannelExtMsgCoder(this.classicOpen);
 
@@ -230,14 +234,15 @@ public class BGPSessionImplTest {
         verify(this.bgpSession, never()).terminate(any(BGPDocumentedException.class));
         try {
             this.bgpSession.sessionUp();
-            fail();  // expect the exception to be populated
-        } catch (final RuntimeException ignored) {
-            // Ignored
+            // expect the exception to be populated
+            fail();
+        } catch (final IllegalStateException e) {
+            assertSame(mockedEx, e);
         }
         assertNotEquals(State.UP, this.bgpSession.getState());
         verify(this.bgpSession).handleException(any());
         verify(this.bgpSession).writeAndFlush(any(Notification.class));
         verify(this.bgpSession).terminate(any(BGPDocumentedException.class));
-        verify(listener).onSessionTerminated(this.bgpSession, new BGPTerminationReason(BGPError.CEASE));
+        verify(mockListener).onSessionTerminated(this.bgpSession, new BGPTerminationReason(BGPError.CEASE));
     }
 }