### Question:
InputValidator { public boolean validate( final String input, final String label, final int type ) { if ( isBlank( input ) ) { return true; } final ResourceBundle rb = Preferences.getBundle( m_context, InternationalizationManager.CORE_BUNDLE ); final Matcher matcher; final boolean valid; switch( type ) { case STANDARD: matcher = UNSAFE_PATTERN.matcher( input ); valid = !matcher.find(); if ( !valid ) { final Object[] args = { label, "\'\"<>;&[]#\\@{}%$" }; m_session.addMessage( m_form, MessageFormat.format( rb.getString( "validate.unsafechars" ), args ) ); } return valid; case EMAIL: matcher = EMAIL_PATTERN.matcher( input ); valid = matcher.matches(); if ( !valid ) { final Object[] args = { label }; m_session.addMessage( m_form, MessageFormat.format( rb.getString( "validate.invalidemail" ), args ) ); } return valid; case ID: matcher = ID_PATTERN.matcher( input ); valid = !matcher.find(); if ( !valid ) { final Object[] args = { label, "\'\"<>;&{}" }; m_session.addMessage( m_form, MessageFormat.format( rb.getString( "validate.unsafechars" ), args ) ); } return valid; default: break; } throw new IllegalArgumentException( "Invalid input type." ); } InputValidator( final String form, final Context context ); boolean validateNotNull( final String input, final String label ); boolean validateNotNull( final String input, final String label, final int type ); boolean validate( final String input, final String label, final int type ); static boolean isBlank( final String input ); static final int STANDARD; static final int EMAIL; static final int ID; }### Answer:
@Test public void testValidate() { Assertions.assertTrue( val.validate( "Test string", "Name", InputValidator.STANDARD ) ); Assertions.assertFalse( val.validate( "Test $tring", "Name", InputValidator.STANDARD ) ); Assertions.assertFalse( val.validate( "Test <string>", "Name", InputValidator.STANDARD ) ); Assertions.assertFalse( val.validate( "Test & string", "Name", InputValidator.STANDARD ) ); Assertions.assertFalse( val.validate( "Test @ string", "Name", InputValidator.STANDARD ) ); Assertions.assertTrue( val.validate( "", "Name", InputValidator.STANDARD ) ); Assertions.assertTrue( val.validate( null, "Name", InputValidator.STANDARD ) ); }