ErrorMessageFactory { public static String create( Context context, Exception exception ) { String message = context.getString( R.string.exception_message_generic ); if( exception instanceof NetworkConnectionException ) { message = context.getString( R.string.exception_message_no_connection ); } else if( exception instanceof ProgramNotFoundException ) { message = context.getString( R.string.exception_message_program_not_found ); } return message; } private  ErrorMessageFactory(); static String create( Context context, Exception exception );  }
@Test public void testNetworkConnectionErrorMessage() { String expectedMessage = context.getString( R.string.exception_message_no_connection ); String actualMessage = ErrorMessageFactory.create( context, new NetworkConnectionException() ); assertThat( actualMessage, is( equalTo( expectedMessage ) ) ); }
@Test public void testProgramNotFoundErrorMessage() { String expectedMessage = context.getString(R.string.exception_message_program_not_found); String actualMessage = ErrorMessageFactory.create( context, new ProgramNotFoundException() ); assertThat( actualMessage, is( equalTo( expectedMessage ) ) ); }