This can actually be simplified using built in Mockito mechanisms for checking 
call counts:

```
  @Test
  public void testFailToStartWithARangeOfPorts() throws IOException {
    InternalCache cache = mock(InternalCache.class);
    CacheServerImpl server = mock(CacheServerImpl.class);
    when(cache.addCacheServer(eq(true))).thenReturn(server);
    doThrow(new SocketException("Address already in use")).when(server).start();
    GatewayReceiverImpl gateway =
        new GatewayReceiverImpl(cache, 2000, 2100, 5, 100, null, null, null, 
true);
    assertThatThrownBy(() -> 
gateway.start()).isInstanceOf(GatewayReceiverException.class)
        .hasMessageContaining("No available free port found in the given 
range");
    assertTrue(gateway.getPort() == 0);
    verify(server, times(101)).start();
  }
```

[ Full content available at: https://github.com/apache/geode/pull/2435 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to