import static org.junit.Assert.fail;
import java.net.InetSocketAddress;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@Before
public void setUp() throws Exception {
- droppingBGPSessionRegistry = new StrictBGPPeerRegistry();
- mockPreferences = getMockPreferences();
+ this.droppingBGPSessionRegistry = new StrictBGPPeerRegistry();
+ this.mockPreferences = getMockPreferences();
}
@Test
final Ipv4Address to = new Ipv4Address("255.255.255.255");
final ReusableBGPPeer session1 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp, session1, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
try {
- droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
} catch (final IllegalStateException e) {
- Mockito.verifyZeroInteractions(session1);
+ Mockito.verify(session1).isSessionActive();
return;
}
final Ipv4Address to = new Ipv4Address("255.255.255.255");
try {
- droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
} catch (final IllegalStateException e) {
return;
}
final IpAddress remoteIp2 = new IpAddress(to2);
final ReusableBGPPeer session1 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp, session1, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
final ReusableBGPPeer session2 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp2, session2, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp2, session2, this.mockPreferences);
- final BGPSessionListener returnedSession1 = droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
+ final BGPSessionListener returnedSession1 = this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
assertSame(session1, returnedSession1);
- final BGPSessionListener returnedSession2 = droppingBGPSessionRegistry.getPeer(remoteIp2, from, to2);
+ final BGPSessionListener returnedSession2 = this.droppingBGPSessionRegistry.getPeer(remoteIp2, from, to2);
assertSame(session2, returnedSession2);
Mockito.verifyZeroInteractions(session1);
final IpAddress remoteIp = new IpAddress(lower);
final ReusableBGPPeer session1 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp, session1, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower);
try {
- droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher);
} catch (final BGPDocumentedException e) {
- Mockito.verifyZeroInteractions(session1);
+ Mockito.verify(session1).isSessionActive();
return;
}
final IpAddress remoteIp = new IpAddress(lower);
final ReusableBGPPeer session1 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp, session1, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher);
- droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower);
Mockito.verify(session1).releaseConnection();
}
private ReusableBGPPeer getMockSession() {
final ReusableBGPPeer mock = Mockito.mock(ReusableBGPPeer.class);
Mockito.doNothing().when(mock).releaseConnection();
+ Mockito.doReturn(Boolean.TRUE).when(mock).isSessionActive();
return mock;
}