Strings { public static String truncate( String value, int maxLength ) { if ( value == null ) { return null; } if ( value.length() < maxLength ) { return value; } return value.substring( 0, maxLength ); }  static String diff( String original, String revised ); static int count( String source, String regex ); static boolean nonEmpty(String value); static boolean empty( String value ); static boolean emptyWithTrimming( String value ); static String truncate( String value, int maxLength ); static String repeat( String value , int iterations ); static List<String> split( String string, String regex ); static String[] toArray( List<String> input ); @Deprecated static List<String> toList( String[] strings ); static ImmutableList<String> toStrings(Object... objects); static List<String> toLines( String data ); static String padding( char c , int length ); static int lengthNullSafe( String value ); static Integer toInteger(T value ); static InputStream toInputStream(String text); static InputStream toInputStream(String text, Charset charset);  }
@Test public void testTruncate() throws Exception { assertEquals( "", Strings.truncate( "", 3 ) ); assertEquals( "1", Strings.truncate( "1", 3 ) ); assertEquals( "12", Strings.truncate( "12", 3 ) ); assertEquals( "123", Strings.truncate( "123", 3 ) ); assertEquals( "123", Strings.truncate( "1234", 3 ) ); }