[Minor] Fix broken DateRangeTest

This commit is contained in:
Robert von Burg 2020-03-27 09:54:42 +01:00
parent d9e27cbaab
commit ce8402117c
2 changed files with 26 additions and 2 deletions

View File

@ -104,26 +104,38 @@ public class DateRange {
}
public ZonedDateTime getFromDateZdt() {
if (this.fromDate == null)
throw new IllegalStateException("fromDate is unbounded, check with isFromBounded()");
return this.fromDate;
}
public ZonedDateTime getToDateZdt() {
if (this.toDate == null)
throw new IllegalStateException("toDate is unbounded, check with isToBounded()");
return this.toDate;
}
public LocalDateTime getFromDateLdt() {
if (this.fromDate == null)
throw new IllegalStateException("fromDate is unbounded, check with isFromBounded()");
return this.fromDate.toLocalDateTime();
}
public LocalDateTime getToDateLdt() {
if (this.toDate == null)
throw new IllegalStateException("toDate is unbounded, check with isToBounded()");
return this.toDate.toLocalDateTime();
}
public Date getFromDate() {
if (this.fromDate == null)
throw new IllegalStateException("fromDate is unbounded, check with isFromBounded()");
return Date.from(this.fromDate.toInstant());
}
public Date getToDate() {
if (this.toDate == null)
throw new IllegalStateException("toDate is unbounded, check with isToBounded()");
return Date.from(this.toDate.toInstant());
}

View File

@ -35,7 +35,13 @@ public class DateRangeTest {
DateRange dateRange = new DateRange();
dateRange.from(now, true);
assertEquals(now, dateRange.getFromDate());
assertNull(dateRange.getToDate());
try {
dateRange.getToDate();
fail("Should fail, as toDate is not set!");
} catch (IllegalStateException e) {
if (!e.getMessage().equals("toDate is unbounded, check with isToBounded()"))
fail("Should fail with different exception message, as toDate is not set!");
}
assertFalse(dateRange.isUnbounded());
assertFalse(dateRange.isBounded());
}
@ -49,7 +55,13 @@ public class DateRangeTest {
DateRange dateRange = new DateRange();
dateRange.to(now, true);
assertEquals(now, dateRange.getToDate());
assertNull(dateRange.getFromDate());
try {
dateRange.getFromDate();
fail("Should fail, as fromDate is not set!");
} catch (IllegalStateException e) {
if (!e.getMessage().equals("fromDate is unbounded, check with isFromBounded()"))
fail("Should fail with different exception message, as fromDate is not set!");
}
assertFalse(dateRange.isUnbounded());
assertFalse(dateRange.isBounded());
}