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

import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

/**
 * Test AlarmClockDayTime.
 *
 *
 * @author Tony Wardell
 * Date: 11/04/2017
 * Time: 15:07
 * Created with IntelliJ IDEA.
 */
@RunWith(MockitoJUnitRunner.class)
public class AlarmClockDayTimeTest {

    LocalDateTime input;
    DayTime startDayTime;
    DayTime endDayTime;

    @Before
    public void setup(){
       input = LocalDateTime.of(2017, 5, 17, 12, 00);   //WED
       startDayTime = new DayTime(DayOfWeek.MONDAY, LocalTime.of(12, 00));
       endDayTime = new DayTime(DayOfWeek.FRIDAY, LocalTime.of(11, 59));
    }

    @Test
    public void secondsLeftWhenComparingStartTimeAndEndTimeWithFixedTime(){
        AlarmClockDayTime alarmClock = new AlarmClockDayTime(startDayTime, endDayTime);

        long timeLeft = alarmClock.remainingTime(input).getSeconds();
        assertThat(timeLeft, is(172740L));
    }

    @Test
    public void durationZeroWhenInputAfterEndTime(){
        input = input.withDayOfMonth(19);

        AlarmClockDayTime alarmClock = new AlarmClockDayTime(startDayTime, endDayTime);

        assertThat(alarmClock.remainingTime(input), is(Duration.ZERO));
    }

    @Test
    public void durationZeroWhenInputBeforeStartTime(){
        input = input.withDayOfMonth(15);
        input = input.withHour(11);
        input = input.withMinute(59);

        AlarmClockDayTime alarmClock = new AlarmClockDayTime(startDayTime, endDayTime);

        assertThat(alarmClock.remainingTime(input), is(Duration.ZERO));
    }

    @Test(expected = IllegalArgumentException.class)
    public void exceptionIfStartIsNull(){
        new AlarmClockDayTime(null, endDayTime);
    }

    @Test(expected = IllegalArgumentException.class)
    public void exceptionIfEndIsNull(){
        new AlarmClockDayTime(startDayTime, null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void exceptionIfStartAndEndIsNull(){
        new AlarmClockDayTime(null, null);
    }
}

@@ -578,16 +578,24 @@
  %7B%0A%0A    
+private 
 LocalDat
@@ -607,24 +607,32 @@
  input;%0A    
+private 
 DayTime star
@@ -645,16 +645,24 @@
 me;%0A    
+private 
 DayTime 
@@ -672,16 +672,58 @@
 DayTime;
+%0A    private AlarmClockDayTime alarmClock;
 %0A%0A    @B
@@ -959,24 +959,92 @@
 f(11, 59));%0A
+      alarmClock = new AlarmClockDayTime(startDayTime, endDayTime);%0A
     %7D%0A%0A    @
@@ -1128,97 +1128,8 @@
 ()%7B%0A
-        AlarmClockDayTime alarmClock = new AlarmClockDayTime(startDayTime, endDayTime);%0A%0A
     
@@ -1194,16 +1194,17 @@
 onds();%0A
+%0A
         
@@ -1359,33 +1359,46 @@
         
-AlarmClockDay
+final Duration remaining
 Time
+ =
  alarmCl
@@ -1404,57 +1404,28 @@
 lock
- = new AlarmClockDayTime(startDayTime, endDayTime
+.remainingTime(input
 );%0A%0A
@@ -1439,35 +1439,24 @@
  assertThat(
-alarmClock.
 remainingTim
@@ -1448,39 +1448,32 @@
 at(remainingTime
-(input)
 , is(Duration.ZE
@@ -1676,33 +1676,46 @@
         
-AlarmClockDay
+final Duration remaining
 Time
+ =
  alarmCl
@@ -1721,57 +1721,28 @@
 lock
- = new AlarmClockDayTime(startDayTime, endDayTime
+.remainingTime(input
 );%0A%0A
@@ -1760,27 +1760,16 @@
 ertThat(
-alarmClock.
 remainin
@@ -1773,23 +1773,16 @@
 ningTime
-(input)
 , is(Dur

Simplify tests.