hs.hsadmin/hsarback/test/de/hsadmin/validate/PacNameTest.java
2016-01-11 12:37:36 +01:00

37 lines
1017 B
Java

package de.hsadmin.validate;
import java.util.regex.Pattern;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class PacNameTest {
private Pattern pattern;
@Before
public void setUp() throws Exception {
pattern = Pattern.compile("[a-z0-9]{5}(-[a-z0-9\\.\\_]{1,})?");
}
@After
public void tearDown() throws Exception {
pattern = null;
}
@Test
public void test() {
Assert.assertTrue("xyz00-a.b", pattern.matcher("xyz00-a.b").matches());
Assert.assertFalse("xyz00-a-b", pattern.matcher("xyz00-a-b").matches());
Assert.assertFalse("xyz00-a.B", pattern.matcher("xyz00-a.B").matches());
Assert.assertFalse("xyz00-", pattern.matcher("xyz00-").matches());
Assert.assertTrue("xyz00", pattern.matcher("xyz00").matches());
Assert.assertFalse("xyz0", pattern.matcher("xyz0").matches());
Assert.assertFalse("xyz00_a", pattern.matcher("xyz00_a").matches());
Assert.assertFalse("xyz00-a.b:c", pattern.matcher("xyz00-a.b:c").matches());
}
}