Hi All,
Could you please let me know how to write junit for the below method generating randomId in sling model.
public String getRandomId() {
int n=8;
byte[] array = new byte[256];
new Random().nextBytes(array);
String randomString = new String(array, Charset.forName("UTF-8"));
StringBuffer r = new StringBuffer();
for (int k = 0; k < randomString.length(); k++) {
char ch = randomString.charAt(k);
if (((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))&& (n > 0)) {
r.append(ch);
n--;
}
}
return "_"+r.toString();
}
Thanks in Advance!