--- a/java/sql-dk/test/info/globalcode/sql/dk/FunctionsTest.java Tue Dec 24 12:05:05 2013 +0100
+++ b/java/sql-dk/test/info/globalcode/sql/dk/FunctionsTest.java Tue Dec 24 14:23:22 2013 +0100
@@ -17,10 +17,10 @@
*/
package info.globalcode.sql.dk;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.Collection;
import static org.testng.Assert.*;
+import org.testng.annotations.*;
/**
*
@@ -29,31 +29,49 @@
public class FunctionsTest {
@Test
- public void testEscapeRegEx() {
- for (String original : new String[]{"abcd", "1234", "xxx", "\\Eescape\\Q", "\\Qescape\\E", "abc\\Eescape\\Qdef.", ".", ""}) {
- String patternString = Pattern.quote(original);
- System.out.println(original + " → " + patternString);
+ public void testNotNull() {
+ Collection<String> c = null;
+ for (String s : Functions.notNull(c)) {
+ fail("Should not iterate through null collection");
+ }
- Pattern pattern = Pattern.compile(patternString);
+ c = new ArrayList<>();
+ c.add("ahoj");
+ int count = 0;
+ for (String s : Functions.notNull(c)) {
+ assertEquals(s, "ahoj", "Wrong item in collection");
+ count++;
+ }
+ assertEquals(count, 1, "Wrong number of iterations");
+ }
- String testString;
- Matcher m;
+ @Test
+ public void testLpad() {
+ String original = "abc";
+ String padded;
- testString = original;
- m = pattern.matcher(testString);
- assertTrue(m.matches(), "Pattern does not match original string: " + testString);
+ padded = Functions.lpad(original, 5);
+ assertEquals(padded, " abc");
- testString = original + "x";
- m = pattern.matcher(testString);
- assertFalse(m.matches(), "Pattern matches wrong string: " + testString);
+ padded = Functions.lpad(original, 2);
+ assertEquals(padded, original);
+ }
+
+ @Test
+ public void testRpad() {
+ String original = "abc";
+ String padded;
- testString = "x" + original;
- m = pattern.matcher(testString);
- assertFalse(m.matches(), "Pattern matches wrong string: " + testString);
+ padded = Functions.rpad(original, 5);
+ assertEquals(padded, "abc ");
- testString = (original + "ab").substring(1);
- m = pattern.matcher(testString);
- assertFalse(m.matches(), "Pattern matches wrong string: " + testString);
- }
+ padded = Functions.rpad(original, 2);
+ assertEquals(padded, original);
+ }
+
+ @Test
+ public void testRepeat() {
+ assertEquals(Functions.repeat('f', 0), "");
+ assertEquals(Functions.repeat('f', 3), "fff");
}
}