java/sql-dk/test/info/globalcode/sql/dk/FunctionsTest.java
author František Kučera <franta-hg@frantovo.cz>
Tue, 24 Dec 2013 14:23:22 +0100
branchv_0
changeset 53 eb30ad93ca8b
parent 51 6730214fab41
child 213 39d154429f7a
permissions -rw-r--r--
more functions unit tests

/**
 * 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 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");
	}
}