package uk.ac.ebi.quickgo.rest.period;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.LocalTime;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;

/**
 * Test instantiation of the DayTime class.
 *
 * @author Tony Wardell
 * Date: 18/04/2017
 * Time: 10:43
 * Created with IntelliJ IDEA.
 */
public class DayTimeTest {

    @Test
    public void instantiateDayTimeWithValidValues(){
       DayTime validDayTime = new DayTime(DayOfWeek.FRIDAY, LocalTime.of(12, 37));

       assertThat(validDayTime, notNullValue());
    }

    @Test(expected = IllegalArgumentException.class)
    public void nullDayOfWeekCreatesException(){
        new DayTime(null, LocalTime.of(12, 37));
    }

    @Test(expected = IllegalArgumentException.class)
    public void nullLocalTimeCreatesException(){
        new DayTime(DayOfWeek.FRIDAY, null);
    }

    @Test
    public void modifySuccessfully(){
        DayTime dayTime = new DayTime(DayOfWeek.FRIDAY, LocalTime.of(12, 37));
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime compared = now.with(DayOfWeek.FRIDAY);
        LocalTime localTime = LocalTime.of(12, 37);
        compared = compared.with(localTime);

        LocalDateTime modified = dayTime.modify(now);

        assertThat(modified, equalTo(compared));
    }

    @Test(expected = IllegalArgumentException.class)
    public void modifyNullThrowsException(){
        DayTime dayTime = new DayTime(DayOfWeek.FRIDAY, LocalTime.of(12, 37));

        dayTime.modify(null);
    }
}

@@ -117,24 +117,49 @@
 .LocalTime;%0A
+import org.junit.Before;%0A
 import org.j
@@ -348,16 +348,41 @@
 tiation 
+and modification methods 
 of the D
@@ -520,16 +520,261 @@
 Test %7B%0A%0A
+    private DayTime dayTime;%0A    private LocalDateTime input;%0A%0A    @Before%0A    public void setup()%7B%0A        dayTime = new DayTime(DayOfWeek.FRIDAY, LocalTime.of(12, 37));%0A        input = LocalDateTime.of(2017, 5, 17, 18, 47); //is a WED%0A    %7D%0A%0A%0A
     @Tes
@@ -1324,16 +1324,22 @@
 essfully
+ToNext
 ()%7B%0A    
@@ -1346,69 +1346,50 @@
     
-DayTime dayTime = new DayTime(DayOfWeek.FRIDAY,
+LocalDateTime expected =
  Local
+Date
 Time.of(
 12, 
@@ -1380,33 +1380,46 @@
 DateTime.of(
+2017, 5, 19, 
 12, 37)
-)
 ;
+%0A
 %0A        Loc
@@ -1433,43 +1433,57 @@
 ime 
-now = LocalDateTime.now(
+modified = dayTime.modifyToNext(input
 );%0A
+%0A
         
 Loca
@@ -1482,155 +1482,183 @@
     
-LocalDateTime compared = now.with(DayOfWeek.FRIDAY
+assertThat(modified, equalTo(expected)
 );%0A    
+%7D%0A%0A
     
-LocalTime localTime = LocalTime.of(12, 37);%0A        compared = compared.with(localTime
+@Test%0A    public void modifySuccessfullyToPrevious()%7B%0A        LocalDateTime expected = LocalDateTime.of(2017, 5, 12, 12, 37
 );%0A%0A
@@ -1708,12 +1708,24 @@
 dify
-(now
+ToPrevious(input
 );%0A%0A
@@ -1765,14 +1765,14 @@
 lTo(
-compar
+expect
 ed))
@@ -1855,16 +1855,22 @@
 d modify
+ToNext
 NullThro
@@ -1896,79 +1896,146 @@
     
-D
+d
 ayTime
- dayTime = new DayTime(DayOfWeek.FRIDAY, LocalTime.of(12, 37));%0A
+.modifyToNext(null);%0A    %7D%0A%0A    @Test(expected = IllegalArgumentException.class)%0A    public void modifyToPreviousThrowsException()%7B
 %0A   
@@ -2053,16 +2053,26 @@
 e.modify
+ToPrevious
 (null);%0A

Simplify tests. Add tests for modifyToNext; modifyToPrevious