JndiChangeNotifier extends JndiAddressProvider implements AddressChangeNotifier, InitializingBean { public void check() { List<InetSocketAddress> newAddrs = getAddresses(); if (newAddrs != null && !newAddrs.equals(currentAddrs)) { if (addressChangeListener != null) { currentAddrs = newAddrs; addressChangeListener.changeAddresses(newAddrs); } else { LOGGER.error("Address change listener is null for JNDI key {}, cannot notify about new value {}", getJndiKey(), newAddrs); } } }  @Override void afterPropertiesSet(); void check();  }
@Test public void check() { @SuppressWarnings("unchecked") List<InetSocketAddress> list = Mockito.mock(List.class); JndiChangeNotifier spy = Mockito.spy(jndiChangeNotifier); Mockito.when(spy.getAddresses()).thenReturn(list); spy.check(); spy.check(); Mockito.verify(addressChangeListener, Mockito.only()).changeAddresses(list); }
@Test public void checkNullAdress() { JndiChangeNotifier spy = Mockito.spy(jndiChangeNotifier); Mockito.when(spy.getAddresses()).thenReturn(null); spy.check(); Mockito.verifyZeroInteractions(addressChangeListener); }