### Question:
TextUtils { public static String replaceFirst( String string, final String regex, final String replacement, final int occurrences ) { StringBuffer sb = new StringBuffer(); Matcher matcher = Pattern.compile( regex ).matcher( string ); int c = 0; while ( matcher.find() && c < occurrences ) { matcher.appendReplacement( sb, replacement ); c++; } return appendTail( matcher, sb ); }  static String htmlify( String text ); static String htmlLinks( String text ); static String htmlNewline( String text ); static List<String> getTokens( String string ); static String subString( String string, int beginIndex, int length ); static String removeLastOr( String string ); static String removeLastAnd( String string ); static String removeLastComma( String string ); static String removeLast( String string, String remove ); static String removeNewlines( String string ); static String trimEnd( String value, int length ); static String getString( String string, boolean emptyString ); static String join( List<T> list, String separator, T nullReplacement ); @SafeVarargs static String joinHyphen( T... elements ); static String getCommaDelimitedString( Collection<?> elements ); static String getCommaDelimitedString( Collection<?> elements, boolean delimitPrefix, boolean delimitSuffix ); static String getQuotedCommaDelimitedString( Collection<? extends Object> elements ); static boolean equalsNullSafe( String s1, String s2 ); static String valueOf( Boolean value ); static Boolean valueOf( String value ); static String lower( String string ); static String toString( String[] array, String separator ); static String toString( Object object ); static String emptyIfEqual( String string, String test ); static String emptyIfFalse( String string, boolean test ); static String appendTail( Matcher matcher, StringBuffer sb ); static String getPrettyClassName( Class<?> clazz ); static String getPrettyEnumName( Enum<?> enumeration ); static String getPrettyPropertyName( String property ); static String splitSafe( String string, String separator, int index ); static boolean containsAnyIgnoreCase( String string, Collection<String> searchStrings ); static Set<String> splitToArray( String value, String separator ); static String replaceFirst( String string, final String regex, final String replacement, final int occurrences ); static String replace( String string, String... symbolReplacementPairs ); static List<String> getOptions( String param ); static String createRegexFromGlob( String glob ); static final TextUtils INSTANCE; static final String EMPTY; static final String SPACE; static final String SEP; static final String LN; static final String SEMICOLON; }### Answer:
@Test public void testReplaceFirst() { assertEquals( "green;red;blue,orange", TextUtils.replaceFirst( "green,red,blue,orange", ",", ";", 2 ) ); assertEquals( "green.red.blue-orange", TextUtils.replaceFirst( "green-red-blue-orange", "-", ".", 2 ) ); assertEquals( "llland", TextUtils.replaceFirst( "lalaland", "a", "", 2 ) ); assertEquals( "mamamand", TextUtils.replaceFirst( "lalaland", "la", "ma", 3 ) ); assertEquals( "lalaland", TextUtils.replaceFirst( "lalaland", "la", "ma", 0 ) ); }