package seedu.todo.commons.util;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import seedu.todo.commons.util.StringUtil;

import java.io.FileNotFoundException;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class StringUtilTest {

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void isUnsignedPositiveInteger() {
        assertFalse(StringUtil.isUnsignedInteger(null));
        assertFalse(StringUtil.isUnsignedInteger(""));
        assertFalse(StringUtil.isUnsignedInteger("a"));
        assertFalse(StringUtil.isUnsignedInteger("aaa"));
        assertFalse(StringUtil.isUnsignedInteger("  "));
        assertFalse(StringUtil.isUnsignedInteger("-1"));
        assertFalse(StringUtil.isUnsignedInteger("0"));
        assertFalse(StringUtil.isUnsignedInteger("+1")); //should be unsigned
        assertFalse(StringUtil.isUnsignedInteger("-1")); //should be unsigned
        assertFalse(StringUtil.isUnsignedInteger(" 10")); //should not contain whitespaces
        assertFalse(StringUtil.isUnsignedInteger("10 ")); //should not contain whitespaces
        assertFalse(StringUtil.isUnsignedInteger("1 0")); //should not contain whitespaces

        assertTrue(StringUtil.isUnsignedInteger("1"));
        assertTrue(StringUtil.isUnsignedInteger("10"));
    }

    @Test
    public void getDetails_exceptionGiven(){
        assertThat(StringUtil.getDetails(new FileNotFoundException("file not found")),
                   containsString("java.io.FileNotFoundException: file not found"));
    }

    @Test
    public void getDetails_nullGiven_assertionError(){
        thrown.expect(AssertionError.class);
        StringUtil.getDetails(null);
    }

    @Test
    public void test_pluralizer_singular() {
        String singular = "apple";
        String plural = "apples";
        assertEquals(StringUtil.pluralizer(1, singular, plural), singular);
    }
    
    @Test
    public void test_pluralizer_plural() {
        String singular = "apple";
        String plural = "apples";
        assertEquals(StringUtil.pluralizer(0, singular, plural), plural);
        assertEquals(StringUtil.pluralizer(2, singular, plural), plural);
    }
    
    @Test
    public void test_replacenull_no_replace() {
        String first = "firstString";
        String last = "lastString";
        assertEquals(StringUtil.replaceNull(first, last), first);
    }
    
    @Test
    public void test_replacenull_replace() {
        String first = null;
        String last = "lastString";
        assertEquals(StringUtil.replaceNull(first, last), last);
    }
}

@@ -2590,36 +2590,37 @@
 ringUtil.replace
-Null
+Empty
 (first, last), f
@@ -2800,12 +2800,13 @@
 lace
-Null
+Empty
 (fir

Update StringUtil tests