@Test public void utilShouldReturnCorrectLengthString() { int one = 1; int length = 3; int otherLength = 10; String oneStr = StringUtils.generateRandom(one); String str = StringUtils.generateRandom(length); String otherStr = StringUtils.generateRandom(otherLength); assertThat(oneStr.length(), is(one)); assertThat(str.length(), is(length)); assertThat(otherStr.length(), is(otherLength)); }
public static String generateRandom(int length) { String generatedStr = null; if (length < 0) { return generatedStr; } if (length == 0) { return ""; } char[] generatedChar = new char[length]; int charsLength = chars.length; Random random = new SecureRandom(); for(int i = 0; i < length; ++i) { int index = random.nextInt(charsLength); generatedChar[i] = (char) chars[index]; } generatedStr = String.valueOf(generatedChar); return generatedStr; }
StringUtils { public static String generateRandom(int length) { String generatedStr = null; if (length < 0) { return generatedStr; } if (length == 0) { return ""; } char[] generatedChar = new char[length]; int charsLength = chars.length; Random random = new SecureRandom(); for(int i = 0; i < length; ++i) { int index = random.nextInt(charsLength); generatedChar[i] = (char) chars[index]; } generatedStr = String.valueOf(generatedChar); return generatedStr; } }
StringUtils { public static String generateRandom(int length) { String generatedStr = null; if (length < 0) { return generatedStr; } if (length == 0) { return ""; } char[] generatedChar = new char[length]; int charsLength = chars.length; Random random = new SecureRandom(); for(int i = 0; i < length; ++i) { int index = random.nextInt(charsLength); generatedChar[i] = (char) chars[index]; } generatedStr = String.valueOf(generatedChar); return generatedStr; }  }
StringUtils { public static String generateRandom(int length) { String generatedStr = null; if (length < 0) { return generatedStr; } if (length == 0) { return ""; } char[] generatedChar = new char[length]; int charsLength = chars.length; Random random = new SecureRandom(); for(int i = 0; i < length; ++i) { int index = random.nextInt(charsLength); generatedChar[i] = (char) chars[index]; } generatedStr = String.valueOf(generatedChar); return generatedStr; }  static String generateRandom(int length); static boolean isEmpty(String str); }
StringUtils { public static String generateRandom(int length) { String generatedStr = null; if (length < 0) { return generatedStr; } if (length == 0) { return ""; } char[] generatedChar = new char[length]; int charsLength = chars.length; Random random = new SecureRandom(); for(int i = 0; i < length; ++i) { int index = random.nextInt(charsLength); generatedChar[i] = (char) chars[index]; } generatedStr = String.valueOf(generatedChar); return generatedStr; }  static String generateRandom(int length); static boolean isEmpty(String str);  }