75 lines
2.5 KiB
Java
75 lines
2.5 KiB
Java
package de.srsoftware.widerhall;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import java.util.Map;
|
|
import java.util.TreeMap;
|
|
import static de.srsoftware.widerhall.Util.*;
|
|
|
|
public class UtilTest extends TestCase {
|
|
|
|
public void testUrlEncode() {
|
|
TreeMap<String,Object> map = new TreeMap<>();
|
|
map.put("a",1);
|
|
map.put("b",2);
|
|
map.put("c","&");
|
|
map.put("d","=");
|
|
assertEquals("a=1&b=2&c=%26&d=%3D",Util.urlEncode(map));
|
|
}
|
|
|
|
public void testHex(){
|
|
assertEquals("00",hex(0));
|
|
assertEquals("09",hex(9));
|
|
assertEquals("0A",hex(10));
|
|
assertEquals("0F",hex(15));
|
|
assertEquals("10",hex(16));
|
|
assertEquals("19",hex(25));
|
|
assertEquals("FF",hex(255));
|
|
}
|
|
|
|
public void testSha256() {
|
|
assertEquals("9F722959A023C02A3BA0FAFDBA81ADED642D6610EFF5DCA32DCE35132E16B6C5",sha256("Dies ist ein Test"));
|
|
}
|
|
|
|
public void testTranslate() {
|
|
assertEquals("Dies ist ein Test",Util.t("{} {} {} {}","Dies","ist","ein","Test"));
|
|
}
|
|
|
|
public void testIsEmail() {
|
|
assertFalse(isEmail("Test"));
|
|
assertFalse(isEmail("Test@"));
|
|
assertFalse(isEmail("@Test"));
|
|
assertTrue(isEmail("Test@Domain"));
|
|
assertFalse(isEmail("Test@Domain@Test"));
|
|
}
|
|
|
|
public void testSimplePassword() {
|
|
assertTrue(simplePassword("$@%€#")); // too short
|
|
assertTrue(simplePassword("test123")); // no special chars
|
|
assertFalse(simplePassword("test$23")); // contains special chars
|
|
assertTrue(simplePassword("skgjafdsg")); // chars only
|
|
assertTrue(simplePassword("986535465")); // digits only
|
|
assertFalse(simplePassword("test9523")); // mixed digits and chars
|
|
assertFalse(simplePassword("8986546054")); // digits only, but long enough
|
|
assertFalse(simplePassword("salgksdjbw")); // chars only, but long enough
|
|
}
|
|
|
|
public void testUnsetFlags(){
|
|
assertEquals(0,unset(31,1,2,4,8,16));
|
|
assertEquals(1,unset(31,2,4,8,16));
|
|
assertEquals(2,unset(31,1,4,8,16));
|
|
assertEquals(4,unset(31,1,2,8,16));
|
|
assertEquals(8,unset(31,1,2,4,16));
|
|
assertEquals(16,unset(31,1,2,4,8));
|
|
}
|
|
|
|
public void testBoundedChar(){
|
|
assertEquals('0',boundedChar(0));
|
|
assertEquals('9',boundedChar(9));
|
|
assertEquals('A',boundedChar(10));
|
|
assertEquals('Z',boundedChar(35));
|
|
assertEquals('a',boundedChar(36));
|
|
assertEquals('z',boundedChar(61));
|
|
assertEquals('0',boundedChar(62));
|
|
}
|
|
} |