java/sql-dk/src/test/java/info/globalcode/sql/dk/FunctionsTest.java
branchv_0
changeset 238 4a1864c3e867
parent 213 39d154429f7a
child 241 f332033ed66c
equal deleted inserted replaced
237:7e08730da258 238:4a1864c3e867
       
     1 /**
       
     2  * SQL-DK
       
     3  * Copyright © 2013 František Kučera (frantovo.cz)
       
     4  *
       
     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.
       
     9  *
       
    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.
       
    14  *
       
    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/>.
       
    17  */
       
    18 package info.globalcode.sql.dk;
       
    19 
       
    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.*;
       
    25 
       
    26 /**
       
    27  *
       
    28  * @author Ing. František Kučera (frantovo.cz)
       
    29  */
       
    30 public class FunctionsTest {
       
    31 
       
    32 	@Test
       
    33 	public void testNotNull() {
       
    34 		Collection<String> c = null;
       
    35 		for (String s : Functions.notNull(c)) {
       
    36 			fail("Should not iterate through null collection");
       
    37 		}
       
    38 
       
    39 		c = new ArrayList<>();
       
    40 		c.add("ahoj");
       
    41 		int count = 0;
       
    42 		for (String s : Functions.notNull(c)) {
       
    43 			assertEquals(s, "ahoj", "Wrong item in collection");
       
    44 			count++;
       
    45 		}
       
    46 		assertEquals(count, 1, "Wrong number of iterations");
       
    47 	}
       
    48 
       
    49 	@Test
       
    50 	public void testLpad() {
       
    51 		String original = "abc";
       
    52 		String padded;
       
    53 
       
    54 		padded = Functions.lpad(original, 5);
       
    55 		assertEquals(padded, "  abc");
       
    56 
       
    57 		padded = Functions.lpad(original, 2);
       
    58 		assertEquals(padded, original);
       
    59 	}
       
    60 
       
    61 	@Test
       
    62 	public void testRpad() {
       
    63 		String original = "abc";
       
    64 		String padded;
       
    65 
       
    66 		padded = Functions.rpad(original, 5);
       
    67 		assertEquals(padded, "abc  ");
       
    68 
       
    69 		padded = Functions.rpad(original, 2);
       
    70 		assertEquals(padded, original);
       
    71 	}
       
    72 
       
    73 	@Test
       
    74 	public void testRepeat() {
       
    75 		assertEquals(Functions.repeat('f', 0), "");
       
    76 		assertEquals(Functions.repeat('f', 3), "fff");
       
    77 	}
       
    78 
       
    79 	@Test
       
    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);
       
    86 	}
       
    87 
       
    88 	private static class HierarchyMockClass0 extends HierarchyMockClass1 {
       
    89 	}
       
    90 
       
    91 	private static class HierarchyMockClass1 extends HierarchyMockClass2 {
       
    92 	}
       
    93 
       
    94 	private static class HierarchyMockClass2 {
       
    95 	}
       
    96 }