### Question:
StringUtil { public static String justifyCenter( String str, final int width, char padWithChar ) { str = str != null ? str.trim() : ""; int addChars = width - str.length(); if (addChars < 0) { return str.subSequence(0, width).toString(); } int prependNumber = addChars / 2; int appendNumber = prependNumber; if ((prependNumber + appendNumber) != addChars) { ++prependNumber; } final StringBuilder sb = new StringBuilder(); while (prependNumber > 0) { sb.append(padWithChar); --prependNumber; } sb.append(str); while (appendNumber > 0) { sb.append(padWithChar); --appendNumber; } return sb.toString(); } private  StringUtil(); static String combineLines( String[] lines ); static String combineLines( String[] lines,
                                       char separator ); static List<String> splitLines( final String content ); static String createString( String pattern,
                                       Object... parameters ); static String createString( final char charToRepeat,
                                       int numberOfRepeats ); static String setLength( String original,
                                    int length,
                                    char padChar ); static String justifyRight( String str,
                                       final int width,
                                       char padWithChar ); static String justifyLeft( String str,
                                      final int width,
                                      char padWithChar ); static String justifyCenter( String str,
                                        final int width,
                                        char padWithChar ); static String truncate( Object obj,
                                   int maxLength ); static String truncate( Object obj,
                                   int maxLength,
                                   String suffix ); static String read( Reader reader ); static String read( InputStream stream ); static void write( String content,
                              OutputStream stream ); static void write( String content,
                              Writer writer ); static String getStackTrace( Throwable throwable ); static String normalize( String text ); static String getHexString( byte[] bytes ); static byte[] fromHexString( String hexadecimal ); static final String[] EMPTY_STRING_ARRAY; }### Answer:
@Test public void justifyCenterShouldTruncateStringsThatAreTooLong() { assertEquals("This is the st", StringUtil.justifyCenter("This is the string", 14, ' ')); }
@Test public void justifyCenterShouldPrependAndAppendSameNumberOfCharacterForStringsThatAreTooShortButOfAnEvenLength() { assertEquals(" This ", StringUtil.justifyCenter("This", 10, ' ')); }
@Test public void justifyCenterShouldPrependOneMoreCharacterThanAppendingForStringsThatAreTooShortButOfAnOddLength() { assertEquals(" Thing ", StringUtil.justifyCenter("Thing", 10, ' ')); }
@Test public void justifyCenterShouldPrependCharacterForEmptyStrings() { assertEquals(" ", StringUtil.justifyCenter("", 10, ' ')); }
@Test public void justifyCenterShouldPrependCharacterForNullStrings() { assertEquals(" ", StringUtil.justifyCenter(null, 10, ' ')); }
@Test public void justifyCenterShouldReturnStringsThatAreTheDesiredLength() { assertEquals("This is the string", StringUtil.justifyCenter("This is the string", 18, ' ')); }