package com.rw.test;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import com.rw.config.Utils;

/**
 * Unit tests for Utils
 * 
 * @author amdelamar
 * @since 1.0.0
 */
@RunWith(JUnit4.class)
public class UtilsTests {

    @Test
    public void test() {

        String time = Utils.formatTime(System.currentTimeMillis());

        assertNotNull(time);
    }

    @Test
    public void formatLong() {

        long[] numbers = {0, 5, 999, 1_000, -5_821, 10_500, -101_800, 2_000_000, -7_800_000,
                92_150_000, 123_200_000, 9_999_999, 999_999_999_999_999_999L,
                1_230_000_000_000_000L, Long.MIN_VALUE, Long.MAX_VALUE};
        String[] expected = {"0", "5", "999", "1k", "-5.8k", "10k", "-101k", "2M", "-7.8M", "92M",
                "123M", "9.9M", "999P", "1.2P", "-9.2E", "9.2E"};
        for (int i = 0; i < numbers.length; i++) {
            long n = numbers[i];
            String formatted = Utils.formatLong(n);
            System.out.println(n + " => " + formatted);
            if (!formatted.equals(expected[i]))
                throw new AssertionError("Expected: " + expected[i] + " but found: " + formatted);
        }

    }
    
    @Test
    public void emailFormat() {
        assertTrue(Utils.isValidEmail("jdoe@gmail.com"));
        assertTrue(Utils.isValidEmail("jdoe@yahoo.com"));
        assertTrue(Utils.isValidEmail("jdoe@us.example.com"));
        assertTrue(Utils.isValidEmail("j.doe@gmail.com"));
        
        assertTrue(!Utils.isValidEmail("jdoe@@gmail.com"));
        assertTrue(!Utils.isValidEmail("@gmail.com"));
        assertTrue(!Utils.isValidEmail("jdoe@"));
        assertTrue(!Utils.isValidEmail("jdoe@gmail."));
        assertTrue(!Utils.isValidEmail(""));
    }
}

@@ -15,16 +15,61 @@
 .test;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -106,16 +106,16 @@
 otNull;%0A
-
 import s
@@ -496,17 +496,115 @@
 lis());%0A
+        assertNotNull(time);%0A        %0A        time = Utils.formatLong(System.currentTimeMillis());
 %0A
-
         
@@ -1151,16 +1151,17 @@
   long n
+m
  = numbe
@@ -1216,16 +1216,17 @@
 atLong(n
+m
 );%0A     
@@ -1252,16 +1252,17 @@
 rintln(n
+m
  + %22 =%3E 
@@ -1324,16 +1324,18 @@
 ted%5Bi%5D))
+ %7B
 %0A       
@@ -1418,32 +1418,46 @@
 %22 + formatted);%0A
+            %7D%0A
         %7D%0A%0A    %7D
@@ -1457,21 +1457,17 @@
 %0A%0A    %7D%0A
-    
 %0A
+
     @Tes
@@ -1738,25 +1738,17 @@
 com%22));%0A
-        
 %0A
+
         
@@ -1956,24 +1956,24 @@
 @gmail.%22));%0A
-
         asse
@@ -2010,11 +2010,811 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void dateTests() %7B%0A%0A        String td = %22June 27 2017%22;%0A        java.util.Date date = Utils.convertStringToDate(td);%0A        %0A        assertNotNull(date);%0A        assertNotNull(Utils.getDate());%0A        assertNotNull(Utils.formatReadableDate(date));%0A        assertNotNull(Utils.formatReadableDateTime(date));%0A        assertNotNull(Utils.formatMySQLDate(date));%0A        assertNotNull(Utils.formatSQLServerDate(date));        %0A    %7D%0A    %0A    @Test%0A    public void stringTests() %7B%0A        %0A        String temp = %22  t e st  %22;%0A        assertEquals(Utils.removeAllSpaces(temp),%22test%22);%0A        %0A        temp = %22/t@e's?t%22;%0A        assertEquals(Utils.removeBadChars(temp),%22test%22);%0A        %0A        temp = %22te%5Cr%5Cnst%22;%0A        assertEquals(Utils.removeNonAsciiChars(temp),%22test%22);%0A    %7D
 %0A%7D%0A

Add more unit tests