### Question:
StringUtils { public static String repeat(final String str, final int repeat) { if (str == null) { return null; } if (repeat <= 0) { return EMPTY; } final int inputLength = str.length(); if (repeat == 1 || inputLength == 0) { return str; } if (inputLength == 1 && repeat <= PAD_LIMIT) { return repeat(str.charAt(0), repeat); } final int outputLength = inputLength * repeat; switch (inputLength) { case 1 : return repeat(str.charAt(0), repeat); case 2 : final char ch0 = str.charAt(0); final char ch1 = str.charAt(1); final char[] output2 = new char[outputLength]; for (int i = repeat * 2 - 2; i >= 0; i--, i--) { output2[i] = ch0; output2[i + 1] = ch1; } return new String(output2); default : final StringBuilder buf = new StringBuilder(outputLength); for (int i = 0; i < repeat; i++) { buf.append(str); } return buf.toString(); } } private  StringUtils(); static int length(final CharSequence cs); static String repeat(final String str, final int repeat); static String repeat(final String str, final String separator, final int repeat); static String removeEnd(final String str, final String remove); static String repeat(final char ch, final int repeat); static String stripEnd(final String str, final String stripChars); static String replace(final String text, final String searchString, final String replacement); static String replace(final String text, final String searchString, final String replacement, int max); static boolean isBlank(String str); static boolean isEmpty(String str); static boolean isNoneEmpty(final String... ss); static boolean isAnyEmpty(final String... ss); static boolean isNotEmpty(String str); static boolean isEquals(String s1, String s2); static boolean isInteger(String str); static int parseInteger(String str); static boolean isJavaIdentifier(String s); static boolean isContains(String values, String value); static boolean isContains(String[] values, String value); static boolean isNumeric(String str); static String toString(Throwable e); static String toString(String msg, Throwable e); static String translate(String src, String from, String to); static String[] split(String str, char ch); static String join(String[] array); static String join(String[] array, char split); static String join(String[] array, String split); static String join(Collection<String> coll, String split); static String getQueryStringValue(String qs, String key); static Map<String, String> parseQueryString(String qs); static String getServiceKey(Map<String, String> ps); static String toQueryString(Map<String, String> ps); static String camelToSplitName(String camelName, String split); static String toArgumentString(Object[] args); static final String EMPTY; static final int INDEX_NOT_FOUND; static final String[] EMPTY_STRING_ARRAY; }### Answer:
@Test public void testRepeat() throws Exception { assertThat(StringUtils.repeat(null, 2), nullValue()); assertThat(StringUtils.repeat("", 0), equalTo("")); assertThat(StringUtils.repeat("", 2), equalTo("")); assertThat(StringUtils.repeat("a", 3), equalTo("aaa")); assertThat(StringUtils.repeat("ab", 2), equalTo("abab")); assertThat(StringUtils.repeat("a", -2), equalTo("")); assertThat(StringUtils.repeat(null, null, 2), nullValue()); assertThat(StringUtils.repeat(null, "x", 2), nullValue()); assertThat(StringUtils.repeat("", null, 0), equalTo("")); assertThat(StringUtils.repeat("", "", 2), equalTo("")); assertThat(StringUtils.repeat("", "x", 3), equalTo("xx")); assertThat(StringUtils.repeat("?", ", ", 3), equalTo("?, ?, ?")); assertThat(StringUtils.repeat('e', 0), equalTo("")); assertThat(StringUtils.repeat('e', 3), equalTo("eee")); }