RandomIdGenerator { public static String rotate_ID( String originalID ) { StringBuffer sb = new StringBuffer( originalID.length() ); for ( int i = 0; i < originalID.length(); ++i ) { char c = originalID.charAt( i ); if ( c >= 'a' && c <= 'z' ) { sb.append( random( 1, 'a', 'z', true, true ) ); } else if ( c >= 'A' && c <= 'Z' ) { sb.append( random( 1, 'A', 'Z', true, true ) ); } else if ( c >= '0' && c <= '9' ) { sb.append( random( 1, '0', '9', true, true ) ); } else { sb.append( c ); } } return sb.toString(); } private  RandomIdGenerator(); static String generate_8_4_4_12_ID(); static String generate_8_4_4_4_12_ID(); static String generate_32_ID(); static String generate_ID( int length ); static String rotate_ID( String originalID );  }
@Test public void testRotate_ID() { String originalID, generatedID; originalID = "abcmnxyz"; for ( int i = 0; i < 100; ++i ) { generatedID = RandomIdGenerator.rotate_ID( originalID ); assertEquals( originalID.length(), generatedID.length() ); assertTrue( String.format( "Error: '%s' ==> '%s'", originalID, generatedID ), generatedID.matches( "[a-z]{8}" ) ); assertFalse( String.format( "Error: Strings are equal '%s'", originalID ), originalID.equals( generatedID ) ); } originalID = "ABCMNXYZ"; for ( int i = 0; i < 100; ++i ) { generatedID = RandomIdGenerator.rotate_ID( originalID ); assertEquals( originalID.length(), generatedID.length() ); assertTrue( String.format( "Error: '%s' ==> '%s'", originalID, generatedID ), generatedID.matches( "[A-Z]{8}" ) ); assertFalse( String.format( "Error: Strings are equal '%s'", originalID ), originalID.equals( generatedID ) ); } originalID = "0123456789"; for ( int i = 0; i < 100; ++i ) { generatedID = RandomIdGenerator.rotate_ID( originalID ); assertEquals( originalID.length(), generatedID.length() ); assertTrue( String.format( "Error: '%s' ==> '%s'", originalID, generatedID ), generatedID.matches( "[0-9]{10}" ) ); assertFalse( String.format( "Error: Strings are equal '%s'", originalID ), originalID.equals( generatedID ) ); } originalID = "_ab-12.XY"; for ( int i = 0; i < 100; ++i ) { generatedID = RandomIdGenerator.rotate_ID( originalID ); assertEquals( originalID.length(), generatedID.length() ); assertTrue( String.format( "Error: '%s' ==> '%s'", originalID, generatedID ), generatedID.matches( "_[a-z]{2}-[0-9]{2}.[A-Z]{2}" ) ); assertFalse( String.format( "Error: Strings are equal '%s'", originalID ), originalID.equals( generatedID ) ); } }