franta-hg@46: /**
franta-hg@46: * SQL-DK
franta-hg@46: * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@46: *
franta-hg@46: * This program is free software: you can redistribute it and/or modify
franta-hg@46: * it under the terms of the GNU General Public License as published by
franta-hg@46: * the Free Software Foundation, either version 3 of the License, or
franta-hg@46: * (at your option) any later version.
franta-hg@46: *
franta-hg@46: * This program is distributed in the hope that it will be useful,
franta-hg@46: * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@46: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@46: * GNU General Public License for more details.
franta-hg@46: *
franta-hg@46: * You should have received a copy of the GNU General Public License
franta-hg@46: * along with this program. If not, see .
franta-hg@46: */
franta-hg@46: package info.globalcode.sql.dk;
franta-hg@46:
franta-hg@53: import java.util.ArrayList;
franta-hg@53: import java.util.Collection;
franta-hg@46: import static org.testng.Assert.*;
franta-hg@53: import org.testng.annotations.*;
franta-hg@46:
franta-hg@46: /**
franta-hg@46: *
franta-hg@46: * @author Ing. František Kučera (frantovo.cz)
franta-hg@46: */
franta-hg@46: public class FunctionsTest {
franta-hg@46:
franta-hg@46: @Test
franta-hg@53: public void testNotNull() {
franta-hg@53: Collection c = null;
franta-hg@53: for (String s : Functions.notNull(c)) {
franta-hg@53: fail("Should not iterate through null collection");
franta-hg@53: }
franta-hg@46:
franta-hg@53: c = new ArrayList<>();
franta-hg@53: c.add("ahoj");
franta-hg@53: int count = 0;
franta-hg@53: for (String s : Functions.notNull(c)) {
franta-hg@53: assertEquals(s, "ahoj", "Wrong item in collection");
franta-hg@53: count++;
franta-hg@53: }
franta-hg@53: assertEquals(count, 1, "Wrong number of iterations");
franta-hg@53: }
franta-hg@46:
franta-hg@53: @Test
franta-hg@53: public void testLpad() {
franta-hg@53: String original = "abc";
franta-hg@53: String padded;
franta-hg@46:
franta-hg@53: padded = Functions.lpad(original, 5);
franta-hg@53: assertEquals(padded, " abc");
franta-hg@46:
franta-hg@53: padded = Functions.lpad(original, 2);
franta-hg@53: assertEquals(padded, original);
franta-hg@53: }
franta-hg@46:
franta-hg@53: @Test
franta-hg@53: public void testRpad() {
franta-hg@53: String original = "abc";
franta-hg@53: String padded;
franta-hg@46:
franta-hg@53: padded = Functions.rpad(original, 5);
franta-hg@53: assertEquals(padded, "abc ");
franta-hg@53:
franta-hg@53: padded = Functions.rpad(original, 2);
franta-hg@53: assertEquals(padded, original);
franta-hg@53: }
franta-hg@53:
franta-hg@53: @Test
franta-hg@53: public void testRepeat() {
franta-hg@53: assertEquals(Functions.repeat('f', 0), "");
franta-hg@53: assertEquals(Functions.repeat('f', 3), "fff");
franta-hg@46: }
franta-hg@46: }