java/sql-dk/test/info/globalcode/sql/dk/FunctionsTest.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 28 Dec 2013 16:45:04 +0100
branchv_0
changeset 89 98d18e9a357b
parent 53 eb30ad93ca8b
child 213 39d154429f7a
permissions -rw-r--r--
InfoLister (configuration listings) will use TabularPrefetchingFormatter as default
franta-hg@46
     1
/**
franta-hg@46
     2
 * SQL-DK
franta-hg@46
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@46
     4
 *
franta-hg@46
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@46
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@46
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@46
     8
 * (at your option) any later version.
franta-hg@46
     9
 *
franta-hg@46
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@46
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@46
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@46
    13
 * GNU General Public License for more details.
franta-hg@46
    14
 *
franta-hg@46
    15
 * You should have received a copy of the GNU General Public License
franta-hg@46
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@46
    17
 */
franta-hg@46
    18
package info.globalcode.sql.dk;
franta-hg@46
    19
franta-hg@53
    20
import java.util.ArrayList;
franta-hg@53
    21
import java.util.Collection;
franta-hg@46
    22
import static org.testng.Assert.*;
franta-hg@53
    23
import org.testng.annotations.*;
franta-hg@46
    24
franta-hg@46
    25
/**
franta-hg@46
    26
 *
franta-hg@46
    27
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@46
    28
 */
franta-hg@46
    29
public class FunctionsTest {
franta-hg@46
    30
franta-hg@46
    31
	@Test
franta-hg@53
    32
	public void testNotNull() {
franta-hg@53
    33
		Collection<String> c = null;
franta-hg@53
    34
		for (String s : Functions.notNull(c)) {
franta-hg@53
    35
			fail("Should not iterate through null collection");
franta-hg@53
    36
		}
franta-hg@46
    37
franta-hg@53
    38
		c = new ArrayList<>();
franta-hg@53
    39
		c.add("ahoj");
franta-hg@53
    40
		int count = 0;
franta-hg@53
    41
		for (String s : Functions.notNull(c)) {
franta-hg@53
    42
			assertEquals(s, "ahoj", "Wrong item in collection");
franta-hg@53
    43
			count++;
franta-hg@53
    44
		}
franta-hg@53
    45
		assertEquals(count, 1, "Wrong number of iterations");
franta-hg@53
    46
	}
franta-hg@46
    47
franta-hg@53
    48
	@Test
franta-hg@53
    49
	public void testLpad() {
franta-hg@53
    50
		String original = "abc";
franta-hg@53
    51
		String padded;
franta-hg@46
    52
franta-hg@53
    53
		padded = Functions.lpad(original, 5);
franta-hg@53
    54
		assertEquals(padded, "  abc");
franta-hg@46
    55
franta-hg@53
    56
		padded = Functions.lpad(original, 2);
franta-hg@53
    57
		assertEquals(padded, original);
franta-hg@53
    58
	}
franta-hg@46
    59
franta-hg@53
    60
	@Test
franta-hg@53
    61
	public void testRpad() {
franta-hg@53
    62
		String original = "abc";
franta-hg@53
    63
		String padded;
franta-hg@46
    64
franta-hg@53
    65
		padded = Functions.rpad(original, 5);
franta-hg@53
    66
		assertEquals(padded, "abc  ");
franta-hg@53
    67
franta-hg@53
    68
		padded = Functions.rpad(original, 2);
franta-hg@53
    69
		assertEquals(padded, original);
franta-hg@53
    70
	}
franta-hg@53
    71
franta-hg@53
    72
	@Test
franta-hg@53
    73
	public void testRepeat() {
franta-hg@53
    74
		assertEquals(Functions.repeat('f', 0), "");
franta-hg@53
    75
		assertEquals(Functions.repeat('f', 3), "fff");
franta-hg@46
    76
	}
franta-hg@46
    77
}