AlertNotifier implements Runnable { @Override public void run() { try { LOG.debug( String.format( "Alert listener '%s' notified about alert '%s'.", listener.getId(), alert.getResource().getId() ) ); listener.onAlert( alert ); } catch ( Exception e ) { LOG.error( String.format( "Error on notifying '%s' notified about alert '%s'.", listener.getId(), alert.getResource().getId() ), e ); } } AlertNotifier( final AlertEvent alert, final AlertListener listener ); @Override void run();  }
@Test public void testListenerShouldBeNotified() throws Exception { AlertNotifier alertNotifier = new AlertNotifier( alert, listener ); alertNotifier.run(); verify( listener ).onAlert( alert ); }
@Test public void testLogError() throws Exception { Logger logger = mock( Logger.class ); doThrow( new RuntimeException( "" ) ).when( listener ).onAlert( alert ); AlertNotifier alertNotifier = new AlertNotifier( alert, listener ); alertNotifier.LOG = logger; alertNotifier.run(); verify( logger ).error( anyString(), any( RuntimeException.class ) ); }