Strings { public static String getSafeVariableName(String name, String... existingVariableNames) { return getSafeVariableName( name, Arrays.asList( existingVariableNames ) ); } private  Strings(); static String capitalize(String string); static String decapitalize(String string); static String join(Iterable<?> iterable, String separator); static String join(Iterable<T> iterable, String separator, Extractor<T, String> extractor); static String joinAndCamelize(Iterable<?> iterable); static boolean isEmpty(String string); static boolean isNotEmpty(String string); static String getSafeVariableName(String name, String... existingVariableNames); static String getSafeVariableName(String name, Collection<String> existingVariableNames); static String sanitizeIdentifierName(String identifier); static String stubPropertyName(String fullyQualifiedName); static String getMostSimilarWord(String word, Collection<String> similarWords);  }
@Test public void testGetSaveVariableNameWithArrayExistingVariables() { assertThat( Strings.getSafeVariableName( "int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.getSafeVariableName( "Extends" ) ).isEqualTo( "extends1" ); assertThat( Strings.getSafeVariableName( "class" ) ).isEqualTo( "class1" ); assertThat( Strings.getSafeVariableName( "Class" ) ).isEqualTo( "class1" ); assertThat( Strings.getSafeVariableName( "Case" ) ).isEqualTo( "case1" ); assertThat( Strings.getSafeVariableName( "Synchronized" ) ).isEqualTo( "synchronized1" ); assertThat( Strings.getSafeVariableName( "prop", "prop", "prop_" ) ).isEqualTo( "prop1" ); assertThat( Strings.getSafeVariableName( "_Test" ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "__Test" ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "_0Test" ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "_0123Test" ) ).isEqualTo( "test" ); }
@Test public void testGetSaveVariableNameVariablesEndingOnNumberVariables() { assertThat( Strings.getSafeVariableName( "prop1", "prop1" ) ).isEqualTo( "prop1_1" ); assertThat( Strings.getSafeVariableName( "prop1", "prop1", "prop1_1" ) ).isEqualTo( "prop1_2" ); }
@Test public void testGetSaveVariableNameWithCollection() { assertThat( Strings.getSafeVariableName( "int[]", new ArrayList<>() ) ).isEqualTo( "intArray" ); assertThat( Strings.getSafeVariableName( "Extends", new ArrayList<>() ) ).isEqualTo( "extends1" ); assertThat( Strings.getSafeVariableName( "prop", Arrays.asList( "prop", "prop1" ) ) ).isEqualTo( "prop2" ); assertThat( Strings.getSafeVariableName( "prop.font", Arrays.asList( "propFont", "propFont_" ) ) ) .isEqualTo( "propFont1" ); assertThat( Strings.getSafeVariableName( "_Test", new ArrayList<>() ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "__Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); assertThat( Strings.getSafeVariableName( "___", new ArrayList<>() ) ).isEqualTo( "___" ); assertThat( Strings.getSafeVariableName( "_0Test", new ArrayList<>() ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "__0Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); assertThat( Strings.getSafeVariableName( "___0", new ArrayList<>() ) ).isEqualTo( "___0" ); assertThat( Strings.getSafeVariableName( "__0123456789Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); }