java/sql-dk/src/test/java/info/globalcode/sql/dk/FunctionsTest.java
branchv_0
changeset 238 4a1864c3e867
parent 213 39d154429f7a
child 241 f332033ed66c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/test/java/info/globalcode/sql/dk/FunctionsTest.java	Mon Mar 04 20:15:24 2019 +0100
@@ -0,0 +1,96 @@
+/**
+ * SQL-DK
+ * Copyright © 2013 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package info.globalcode.sql.dk;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import static org.testng.Assert.*;
+import org.testng.annotations.*;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class FunctionsTest {
+
+	@Test
+	public void testNotNull() {
+		Collection<String> c = null;
+		for (String s : Functions.notNull(c)) {
+			fail("Should not iterate through null collection");
+		}
+
+		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");
+	}
+
+	@Test
+	public void testLpad() {
+		String original = "abc";
+		String padded;
+
+		padded = Functions.lpad(original, 5);
+		assertEquals(padded, "  abc");
+
+		padded = Functions.lpad(original, 2);
+		assertEquals(padded, original);
+	}
+
+	@Test
+	public void testRpad() {
+		String original = "abc";
+		String padded;
+
+		padded = Functions.rpad(original, 5);
+		assertEquals(padded, "abc  ");
+
+		padded = Functions.rpad(original, 2);
+		assertEquals(padded, original);
+	}
+
+	@Test
+	public void testRepeat() {
+		assertEquals(Functions.repeat('f', 0), "");
+		assertEquals(Functions.repeat('f', 3), "fff");
+	}
+
+	@Test
+	public void testGetClassHierarchy() {
+		List<Class<? extends HierarchyMockClass2>> hierarchy = Functions.getClassHierarchy(HierarchyMockClass0.class, HierarchyMockClass2.class);
+		assertEquals(hierarchy.size(), 3, "invalid number of classes in the hierarchy");
+		assertEquals(hierarchy.get(0), HierarchyMockClass0.class);
+		assertEquals(hierarchy.get(1), HierarchyMockClass1.class);
+		assertEquals(hierarchy.get(2), HierarchyMockClass2.class);
+	}
+
+	private static class HierarchyMockClass0 extends HierarchyMockClass1 {
+	}
+
+	private static class HierarchyMockClass1 extends HierarchyMockClass2 {
+	}
+
+	private static class HierarchyMockClass2 {
+	}
+}