@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testRegisterLeaderLocationListener() {

    final LeaderLocationListener listener1 = mock(LeaderLocationListener.class);
    // first registration should be OK
    shardAccess.registerLeaderLocationListener(listener1);
    // second registration should fail with IllegalArgumentEx
    try {
        shardAccess.registerLeaderLocationListener(listener1);
        fail("Should throw exception");
    } catch (final Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    // null listener registration should fail with NPE
    try {
        shardAccess.registerLeaderLocationListener(null);
        fail("Should throw exception");
    } catch (final Exception e) {
        assertTrue(e instanceof NullPointerException);
    }
    // registering listener on closed shard access should fail with IllegalStateEx
    final LeaderLocationListener listener2 = mock(LeaderLocationListener.class);
    shardAccess.close();
    try {
        shardAccess.registerLeaderLocationListener(listener2);
        fail("Should throw exception");
    } catch (final Exception ex) {
        assertTrue(ex instanceof IllegalStateException);
    }
}