### Question:
FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private  FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value );  }### Answer:
@Test public void testFormatWithNoPlaceholdersAndCorrectArgumentCount() { assertEquals( "(cn=foo)", FilterEncoder.format( "(cn=foo)", (String[])null ) ); assertEquals( "(cn=foo)", FilterEncoder.format( "(cn=foo)", ZERO ) ); }
@Test public void testFormatWithNoPlaceholdersAndTooManyArguments() { assertThrows( IllegalArgumentException.class, () -> { FilterEncoder.format( "(cn=foo)", ONE ); } ); }
@Test public void testFormatWithPlaceholdersAndTooFewArguments() { assertThrows( IllegalArgumentException.class, () -> { FilterEncoder.format( "(cn={0})", ZERO ); } ); }
@Test public void testFormatWithPlaceholdersAndCorrectArgumentCount() { assertEquals( "(cn=foo)", FilterEncoder.format( "(cn={0})", ONE ) ); assertEquals( "(&(cn=foo)(uid=bar))", FilterEncoder.format( "(&(cn={0})(uid={1}))", TWO ) ); }
@Test public void testFormatWithPlaceholdersAndTooManyArguments() { assertThrows( IllegalArgumentException.class, () -> { FilterEncoder.format( "(cn={0})", TWO ); } ); }
@Test public void testFormatWithPlaceholdersAndSpecialChars() { assertEquals( "(cn=\\28\\5C\\2A\\00\\29)", FilterEncoder.format( "(cn={0})", SPECIAL_CHARS ) ); }
@Test public void testExceptionMessage() { try { FilterEncoder.format( "(&(cn={0})(uid={1}))", ONE ); fail( "IllegalArgumentException expected" ); } catch ( IllegalArgumentException e ) { String message = e.getMessage(); assertTrue( message.contains( " (&(cn={0})(uid={1})) " ) ); assertTrue( message.contains( " 2 " ) ); assertTrue( message.contains( " 1 " ) ); } }