### Question:
MessageEventService { public void fireEvent( final Message event ) throws MessageEventFireEventException { if ( event != null ) { if ( containsHandlerFor( event ) ) { final Collection<MessageEventHandler> handlers = getHandlersFor( event ); if ( handlers != null && handlers.size() > 0 ) { MessageEventFireEventException messageEventFireEventException = null; for ( final MessageEventHandler handler : handlers ) { try { handler.execute( event ); } catch ( final Exception e ) { if ( messageEventFireEventException == null ) { messageEventFireEventException = new MessageEventFireEventException( "Unable to execute some handler." ); } messageEventFireEventException.addHandlerException( e ); } } if ( messageEventFireEventException != null ) { throw messageEventFireEventException; } } } } else { throw new MessageEventFireEventException( "Unable to fire a null event" ); } } MessageEventService(); void fireEvent( final Message event ); final void addHandler( final Message eventType, final MessageEventHandler handler ); final boolean hasHandlers( final Message eventType ); List<MessageEventHandler> getHandlersFor( final Message eventType );  }### Answer:
@Test( expected = MessageEventFireEventException.class ) public void testFireEventNull() throws KettleException { messageEventService.fireEvent( null ); }
@Test public void testOperationFireEvent() throws KettleException { addHandlers( operationMessageEvent, messageEventHandler, messageEventHandler2 ); LogEvent logEvent = new LogEvent<>( new RemoteSource( ModelType.OPERATION, "Operation_ID" ), logEntry ); messageEventService.fireEvent( logEvent ); verify( messageEventHandler ).execute( logEvent ); verify( messageEventHandler2 ).execute( logEvent ); }
@Test( expected = MessageEventFireEventException.class ) public void testOperationFireEventThrowException() throws KettleException { addHandlers( operationMessageEvent, messageEventHandler, messageEventHandler2 ); doThrow( new RuntimeException( "Test" ) ).when( messageEventHandler ).execute( any( Message.class ) ); LogEvent logEvent = new LogEvent<>( new RemoteSource( ModelType.OPERATION, "Operation_ID" ), logEntry ); messageEventService.fireEvent( logEvent ); verify( messageEventHandler, never() ).execute( logEvent ); verify( messageEventHandler2 ).execute( logEvent ); }
@Test public void testStopMessageFireEvent() throws KettleException { addHandlers( new StopMessage( "" ), messageEventHandler, messageEventHandler2 ); StopMessage msg = new StopMessage( "User request" ); messageEventService.fireEvent( msg ); verify( messageEventHandler ).execute( msg ); verify( messageEventHandler2 ).execute( msg ); }
@Test public void testTransformationFireEvent() throws Exception { addHandlers( transformationMessageEvent, messageEventHandler, messageEventHandler2 ); LogEvent logEvent = new LogEvent<>( new RemoteSource( ModelType.TRANSFORMATION, "Operation_ID" ), logEntry ); messageEventService.fireEvent( logEvent ); verify( messageEventHandler ).execute( logEvent ); verify( messageEventHandler2 ).execute( logEvent ); }