@Test public void shouldNotifyLifecycleListener() throws Exception { beginMonitoring(requestSpecFor( getSocketAddress("0.0.0.0", 20048), getSocketAddress("0.0.0.0", 56150))); monitor.poll(recordingUdpSocketStatisticsHandler); endMonitoring(requestSpecFor(getSocketAddress("0.0.0.0", 56150))); monitor.poll(recordingUdpSocketStatisticsHandler); final List<InetSocketAddress> monitoringStartedList = lifecycleListener.getMonitoringStartedList(); assertThat(monitoringStartedList.size(), is(2)); assertThat(monitoringStartedList.get(0), is(getSocketAddress("0.0.0.0", 20048))); assertThat(monitoringStartedList.get(1), is(getSocketAddress("0.0.0.0", 56150))); final List<InetSocketAddress> monitoringStoppedList = lifecycleListener.getMonitoringStoppedList(); assertThat(monitoringStoppedList.size(), is(1)); assertThat(monitoringStoppedList.get(0), is(getSocketAddress("0.0.0.0", 56150))); }