java/sql-dk/src/test/java/info/globalcode/sql/dk/FunctionsTest.java
branchv_0
changeset 238 4a1864c3e867
parent 213 39d154429f7a
child 241 f332033ed66c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/sql-dk/src/test/java/info/globalcode/sql/dk/FunctionsTest.java	Mon Mar 04 20:15:24 2019 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/**
     1.5 + * SQL-DK
     1.6 + * Copyright © 2013 František Kučera (frantovo.cz)
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, either version 3 of the License, or
    1.11 + * (at your option) any later version.
    1.12 + *
    1.13 + * This program is distributed in the hope that it will be useful,
    1.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.16 + * GNU General Public License for more details.
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License
    1.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.20 + */
    1.21 +package info.globalcode.sql.dk;
    1.22 +
    1.23 +import java.util.ArrayList;
    1.24 +import java.util.Collection;
    1.25 +import java.util.List;
    1.26 +import static org.testng.Assert.*;
    1.27 +import org.testng.annotations.*;
    1.28 +
    1.29 +/**
    1.30 + *
    1.31 + * @author Ing. František Kučera (frantovo.cz)
    1.32 + */
    1.33 +public class FunctionsTest {
    1.34 +
    1.35 +	@Test
    1.36 +	public void testNotNull() {
    1.37 +		Collection<String> c = null;
    1.38 +		for (String s : Functions.notNull(c)) {
    1.39 +			fail("Should not iterate through null collection");
    1.40 +		}
    1.41 +
    1.42 +		c = new ArrayList<>();
    1.43 +		c.add("ahoj");
    1.44 +		int count = 0;
    1.45 +		for (String s : Functions.notNull(c)) {
    1.46 +			assertEquals(s, "ahoj", "Wrong item in collection");
    1.47 +			count++;
    1.48 +		}
    1.49 +		assertEquals(count, 1, "Wrong number of iterations");
    1.50 +	}
    1.51 +
    1.52 +	@Test
    1.53 +	public void testLpad() {
    1.54 +		String original = "abc";
    1.55 +		String padded;
    1.56 +
    1.57 +		padded = Functions.lpad(original, 5);
    1.58 +		assertEquals(padded, "  abc");
    1.59 +
    1.60 +		padded = Functions.lpad(original, 2);
    1.61 +		assertEquals(padded, original);
    1.62 +	}
    1.63 +
    1.64 +	@Test
    1.65 +	public void testRpad() {
    1.66 +		String original = "abc";
    1.67 +		String padded;
    1.68 +
    1.69 +		padded = Functions.rpad(original, 5);
    1.70 +		assertEquals(padded, "abc  ");
    1.71 +
    1.72 +		padded = Functions.rpad(original, 2);
    1.73 +		assertEquals(padded, original);
    1.74 +	}
    1.75 +
    1.76 +	@Test
    1.77 +	public void testRepeat() {
    1.78 +		assertEquals(Functions.repeat('f', 0), "");
    1.79 +		assertEquals(Functions.repeat('f', 3), "fff");
    1.80 +	}
    1.81 +
    1.82 +	@Test
    1.83 +	public void testGetClassHierarchy() {
    1.84 +		List<Class<? extends HierarchyMockClass2>> hierarchy = Functions.getClassHierarchy(HierarchyMockClass0.class, HierarchyMockClass2.class);
    1.85 +		assertEquals(hierarchy.size(), 3, "invalid number of classes in the hierarchy");
    1.86 +		assertEquals(hierarchy.get(0), HierarchyMockClass0.class);
    1.87 +		assertEquals(hierarchy.get(1), HierarchyMockClass1.class);
    1.88 +		assertEquals(hierarchy.get(2), HierarchyMockClass2.class);
    1.89 +	}
    1.90 +
    1.91 +	private static class HierarchyMockClass0 extends HierarchyMockClass1 {
    1.92 +	}
    1.93 +
    1.94 +	private static class HierarchyMockClass1 extends HierarchyMockClass2 {
    1.95 +	}
    1.96 +
    1.97 +	private static class HierarchyMockClass2 {
    1.98 +	}
    1.99 +}