3 * Copyright © 2013 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package info.globalcode.sql.dk;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 import static org.testng.Assert.*;
24 import org.testng.annotations.*;
28 * @author Ing. František Kučera (frantovo.cz)
30 public class FunctionsTest {
33 public void testNotNull() {
34 Collection<String> c = null;
35 for (String s : Functions.notNull(c)) {
36 fail("Should not iterate through null collection");
39 c = new ArrayList<>();
42 for (String s : Functions.notNull(c)) {
43 assertEquals(s, "ahoj", "Wrong item in collection");
46 assertEquals(count, 1, "Wrong number of iterations");
50 public void testLpad() {
51 String original = "abc";
54 padded = Functions.lpad(original, 5);
55 assertEquals(padded, " abc");
57 padded = Functions.lpad(original, 2);
58 assertEquals(padded, original);
62 public void testRpad() {
63 String original = "abc";
66 padded = Functions.rpad(original, 5);
67 assertEquals(padded, "abc ");
69 padded = Functions.rpad(original, 2);
70 assertEquals(padded, original);
74 public void testRepeat() {
75 assertEquals(Functions.repeat('f', 0), "");
76 assertEquals(Functions.repeat('f', 3), "fff");
80 public void testGetClassHierarchy() {
81 List<Class<? extends HierarchyMockClass2>> hierarchy = Functions.getClassHierarchy(HierarchyMockClass0.class, HierarchyMockClass2.class);
82 assertEquals(hierarchy.size(), 3, "invalid number of classes in the hierarchy");
83 assertEquals(hierarchy.get(0), HierarchyMockClass0.class);
84 assertEquals(hierarchy.get(1), HierarchyMockClass1.class);
85 assertEquals(hierarchy.get(2), HierarchyMockClass2.class);
88 private static class HierarchyMockClass0 extends HierarchyMockClass1 {
91 private static class HierarchyMockClass1 extends HierarchyMockClass2 {
94 private static class HierarchyMockClass2 {