blob: 93b41727922d124aa57c37b6cd424b9427d978b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package org.apache.qpid.server.util;
import org.apache.qpid.server.util.StringUtil;
import org.apache.qpid.test.utils.QpidTestCase;
public class StringUtilTest extends QpidTestCase
{
private StringUtil _util;
@Override
public void setUp() throws Exception
{
super.setUp();
_util = new StringUtil();
}
public void testRandomAlphaNumericStringInt()
{
String password = _util.randomAlphaNumericString(10);
assertEquals("Unexpected password string length", 10, password.length());
assertCharacters(password);
}
private void assertCharacters(String password)
{
String numbers = "0123456789";
String letters = "abcdefghijklmnopqrstuvwxwy";
String others = "_-";
String expectedCharacters = (numbers + letters + letters.toUpperCase() + others);
char[] chars = password.toCharArray();
for (int i = 0; i < chars.length; i++)
{
char ch = chars[i];
assertTrue("Unexpected character " + ch, expectedCharacters.indexOf(ch) != -1);
}
}
}
|