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

import java.util.Optional;

import org.junit.Test;


import static org.hamcrest.Matchers.equalTo;


import static org.hamcrest.MatcherAssert.assertThat;


/**
 * Test the methods that PeriodParser implements.
 * @author Tony Wardell
 * Date: 26/04/2017
 * Time: 09:26
 * Created with IntelliJ IDEA.
 */
public class PeriodParserTest {

    private static final DateModifier DATE_MODIFIER = target -> null;
    private final PeriodParser periodParser = getPeriodParser();

    @Test
    public void parseValidInputString() throws Exception {
        AlarmClock testAlarmClock = new AlarmClockImpl(DATE_MODIFIER, DATE_MODIFIER);

        Optional<AlarmClock> alarmClock = periodParser.parse("START-END");

        assertThat(alarmClock.get(), equalTo(testAlarmClock));
    }

    @Test
    public void nullInputStringReturnsEmptyOptional(){
        Optional<AlarmClock> alarmClock = periodParser.parse(null);

        assertThat(alarmClock, equalTo(Optional.empty()));
    }

    @Test
    public void zeroLengthInputStringReturnsEmptyOptional(){
        Optional<AlarmClock> alarmClock = periodParser.parse("");

        assertThat(alarmClock, equalTo(Optional.empty()));
    }

    @Test
    public void tooManyToSymbolsReturnsEmptyOptional(){
        Optional<AlarmClock> alarmClock = periodParser.parse("YA-BOO-SUCKS");

        assertThat(alarmClock, equalTo(Optional.empty()));
    }

    @Test
    public void toDateModifierReturnsEmptyOptional() throws Exception {
        PeriodParser periodParser = getPeriodParserToDateModifierReturnsEmptyOptional();

        Optional<AlarmClock> alarmClock = periodParser.parse("START-END");

        assertThat(alarmClock, equalTo(Optional.empty()));
    }

    private PeriodParser getPeriodParser() {
        return new PeriodParser() {
            @Override protected Optional<DateModifier> toDateModifier(String input) {
                return Optional.of(DATE_MODIFIER);
            }
        };
    }

    private PeriodParser getPeriodParserToDateModifierReturnsEmptyOptional() {
        return new PeriodParser() {
            @Override protected Optional<DateModifier> toDateModifier(String input) {
                return Optional.empty();
            }
        };
    }
}

@@ -85,16 +85,66 @@
 .Test;%0A%0A
+import static junit.framework.TestCase.assertTrue;
 %0Aimport 
@@ -448,34 +448,30 @@
 nal 
-DateModifier DATE_MODIFIER
+AlarmClock ALARM_CLOCK
  = t
@@ -624,95 +624,8 @@
 n %7B%0A
-        AlarmClock testAlarmClock = new AlarmClockImpl(DATE_MODIFIER, DATE_MODIFIER);%0A%0A
     
@@ -703,35 +703,35 @@
 %0A        assertT
-hat
+rue
 (alarmClock.get(
@@ -730,37 +730,18 @@
 ock.
-get(), equalTo(testAlarmClock
+isPresent(
 ));%0A
@@ -1155,219 +1155,8 @@
  %7D%0A%0A
-    @Test%0A    public void tooManyToSymbolsReturnsEmptyOptional()%7B%0A        Optional%3CAlarmClock%3E alarmClock = periodParser.parse(%22YA-BOO-SUCKS%22);%0A%0A        assertThat(alarmClock, equalTo(Optional.empty()));%0A    %7D%0A%0A
     
@@ -1282,36 +1282,34 @@
 riodParserTo
-DateModifier
+AlarmClock
 ReturnsEmpty
@@ -1589,36 +1589,29 @@
 nal%3C
-DateModifier%3E toDateModifier
+AlarmClock%3E getPeriod
 (Str
@@ -1662,21 +1662,19 @@
 .of(
-DATE_MODIFIER
+ALARM_CLOCK
 );%0A 
@@ -1746,28 +1746,26 @@
 ParserTo
-DateModifier
+AlarmClock
 ReturnsE
@@ -1862,36 +1862,29 @@
 nal%3C
-DateModifier%3E toDateModifier
+AlarmClock%3E getPeriod
 (Str

Remove un-required test. Remove reference to DateModifier.