package com.atexpose;

import org.junit.Test;

import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author schinzel
 */
public class MiscTest {


    @Test
    public void testEcho() {
        Misc misc = new Misc();
        String result = misc.echo("monkey");
        assertEquals("monkey", result);
    }


    @Test
    public void testPing() {
        Misc misc = new Misc();
        String result = misc.ping();
        assertEquals("pong", result);
    }


    @Test
    public void testTime() {
        String regex = "20[0-9][0-9]-[01][0-9]-[0-3][0-9] [012][0-9]:[0-5][0-9]:[0-5][0-9].[0-9]{3}";
        Pattern pattern = Pattern.compile(regex);
        Misc misc = new Misc();
        String result = misc.time();
        boolean matches = pattern.matcher(result).matches();
        assertTrue(matches);
    }


    @Test
    public void snooze_snooze20ms_shouldSnoozeBetween20And30ms() {
        long start = System.nanoTime();
        new Misc().snooze(20);
        //Calc the time to do all iterations
        long executionTimeInMS = (System.nanoTime() - start) / 1000000;
        assertThat(executionTimeInMS).isBetween(20L, 30L);
    }


    @Test
    public void testThrowError() {
        assertThatExceptionOfType(RuntimeException.class)
                .isThrownBy(() -> new Misc().throwError())
                .withMessageStartingWith("Requested error thrown");
    }

}

@@ -293,16 +293,17 @@
 tTrue;%0A%0A
+%0A
 /**%0A * @
@@ -346,16 +346,161 @@
 cTest %7B%0A
+    Pattern DATE_TIME_PATTERN = Pattern.compile(%2220%5B0-9%5D%5B0-9%5D-%5B01%5D%5B0-9%5D-%5B0-3%5D%5B0-9%5D %22 +%0A            %22%5B012%5D%5B0-9%5D:%5B0-5%5D%5B0-9%5D:%5B0-5%5D%5B0-9%5D.%5B0-9%5D%7B3%7D%22);%0A
 %0A%0A    @T
@@ -871,91 +871,32 @@
 g re
-gex = %2220%5B0-9%5D%5B0-9%5D-%5B01%5D%5B0-9%5D-%5B0-3%5D%5B0-9%5D %5B012%5D%5B0-9%5D:%5B0-5%5D%5B0-9%5D:%5B0-5%5D%5B0-9%5D.%5B0-9%5D%7B3%7D%22
+sult = new Misc().time()
 ;%0A  
@@ -905,81 +905,180 @@
     
-Pattern pattern = Pattern.compile(regex);%0A        Misc misc = new Misc();
+boolean matches = DATE_TIME_PATTERN.matcher(result).matches();%0A        assertTrue(matches);%0A    %7D%0A%0A%0A    @Test%0A    public void startTime_NormalCase_CorrectDateTimeFormat() %7B
 %0A   
@@ -1102,14 +1102,25 @@
 t = 
-misc.t
+new Misc().startT
 ime(
@@ -1152,15 +1152,25 @@
 s = 
-pattern
+DATE_TIME_PATTERN
 .mat

Test added