190 lines
9.0 KiB
Java
Executable File
190 lines
9.0 KiB
Java
Executable File
package com.plannaplan.entities;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
import java.sql.Date;
|
|
|
|
import com.plannaplan.models.TourData;
|
|
import com.plannaplan.types.AppState;
|
|
|
|
import org.junit.Test;
|
|
|
|
public class AppConfigTest {
|
|
|
|
private static long ONE_DAY = 86400000;
|
|
|
|
@Test
|
|
public void shouldReturnNoTourDueToTooEarly() {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() + ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY);
|
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnFirstTourDueToStart() throws InterruptedException {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis());
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY);
|
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
Thread.sleep(1000);
|
|
assertTrue(config.getCurrentState() == AppState.FIRST_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnFirstTourDueToInBetween() {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY);
|
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getCurrentState() == AppState.FIRST_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnNoTourInLastDay() throws InterruptedException {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis());
|
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
Thread.sleep(1000);
|
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnNoTourInBetween() {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - ONE_DAY);
|
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnSecondTourInStart() throws InterruptedException {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - ONE_DAY);
|
|
final Date secondTourStart = new Date(System.currentTimeMillis());
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
Thread.sleep(1000);
|
|
assertTrue(config.getCurrentState() == AppState.SECOND_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnSecondTourInBetween() {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 3 * ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
|
final Date secondTourStart = new Date(System.currentTimeMillis() - ONE_DAY);
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getCurrentState() == AppState.SECOND_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnNoTourDueToEndSecond() throws InterruptedException {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 3 * ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
|
final Date secondTourStart = new Date(System.currentTimeMillis() - ONE_DAY);
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis());
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
Thread.sleep(1000);
|
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnNoTourAfterSecondEnd() {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 4 * ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - 3 * ONE_DAY);
|
|
final Date secondTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() - ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnSecondTourWhereThereIsABrake() throws InterruptedException {
|
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 4 * ONE_DAY);
|
|
final Date firtstTourEnd = new Date(System.currentTimeMillis());
|
|
final Date secondTourStart = new Date(System.currentTimeMillis());
|
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + ONE_DAY);
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
Thread.sleep(1000);
|
|
assertTrue(config.getCurrentState() == AppState.SECOND_TOUR);
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnFirstStartDatesCorns() {
|
|
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
|
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
|
final Date secondTourStart = Date.valueOf("2020-11-14");
|
|
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getFirstTourStartCron().getExpression().equals("0 0 0 12 11 ?"));
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnSecondStartDatesCorns() {
|
|
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
|
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
|
final Date secondTourStart = Date.valueOf("2020-11-14");
|
|
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getSecondTourStartCron().getExpression().equals("0 0 0 14 11 ?"));
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnFirstEndDatesCorns() {
|
|
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
|
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
|
final Date secondTourStart = Date.valueOf("2020-11-14");
|
|
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getFirstTourEndCron().getExpression().equals("0 0 0 13 11 ?"));
|
|
}
|
|
|
|
@Test
|
|
public void shouldReturnSecondEndDatesCorns() {
|
|
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
|
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
|
final Date secondTourStart = Date.valueOf("2020-11-14");
|
|
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
|
|
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
|
new TourData(secondTourStart, secondTourEnd));
|
|
assertTrue(config.getSecondTourEndCron().getExpression().equals("0 0 0 15 11 ?"));
|
|
}
|
|
|
|
}
|