package com.capgemini.framework.common;

import junit.framework.Assert;
import org.junit.Test;

public class StringHelperTest {

    @Test
    public void testTruncate() {
        Assert.assertEquals("Truncated value", "12345", StringHelper.truncate("1234567890", 5));
        Assert.assertEquals("Equals to length value", "12345", StringHelper.truncate("12345", 5));
        Assert.assertEquals("Too small value", "1", StringHelper.truncate("1", 5));
        Assert.assertEquals("Null value", null, StringHelper.truncate(null, 5));
    }

    @Test
    public void testSplitWithoutDelim() {
        String value = "2015-11";
        String expected = "2015";

        String delimiter = StringHelper.DASH;
        String[] tokens = StringHelper.splitWithoutDelim(delimiter, value);
        Assert.assertEquals("Expected the first range [" + expected + "] of value:" + value + " with delimiter [" + delimiter + "]", expected, tokens[0]);
    }
}
