[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() { public ZonedDateTime getFromDateZdt() {
if (this.fromDate == null)
throw new IllegalStateException("fromDate is unbounded, check with isFromBounded()");
return this.fromDate; return this.fromDate;
} }
public ZonedDateTime getToDateZdt() { public ZonedDateTime getToDateZdt() {
if (this.toDate == null)
throw new IllegalStateException("toDate is unbounded, check with isToBounded()");
return this.toDate; return this.toDate;
} }
public LocalDateTime getFromDateLdt() { public LocalDateTime getFromDateLdt() {
if (this.fromDate == null)
throw new IllegalStateException("fromDate is unbounded, check with isFromBounded()");
return this.fromDate.toLocalDateTime(); return this.fromDate.toLocalDateTime();
} }
public LocalDateTime getToDateLdt() { public LocalDateTime getToDateLdt() {
if (this.toDate == null)
throw new IllegalStateException("toDate is unbounded, check with isToBounded()");
return this.toDate.toLocalDateTime(); return this.toDate.toLocalDateTime();
} }
public Date getFromDate() { public Date getFromDate() {
if (this.fromDate == null)
throw new IllegalStateException("fromDate is unbounded, check with isFromBounded()");
return Date.from(this.fromDate.toInstant()); return Date.from(this.fromDate.toInstant());
} }
public Date getToDate() { public Date getToDate() {
if (this.toDate == null)
throw new IllegalStateException("toDate is unbounded, check with isToBounded()");
return Date.from(this.toDate.toInstant()); return Date.from(this.toDate.toInstant());
} }

View File

@ -35,7 +35,13 @@ public class DateRangeTest {
DateRange dateRange = new DateRange(); DateRange dateRange = new DateRange();
dateRange.from(now, true); dateRange.from(now, true);
assertEquals(now, dateRange.getFromDate()); 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.isUnbounded());
assertFalse(dateRange.isBounded()); assertFalse(dateRange.isBounded());
} }
@ -49,7 +55,13 @@ public class DateRangeTest {
DateRange dateRange = new DateRange(); DateRange dateRange = new DateRange();
dateRange.to(now, true); dateRange.to(now, true);
assertEquals(now, dateRange.getToDate()); 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.isUnbounded());
assertFalse(dateRange.isBounded()); assertFalse(dateRange.isBounded());
} }