### Question:
DateRange implements Serializable, Comparable<DateRange> { @Nonnull public Optional<DateRange> getOverlap(@Nonnull DateRange otherRange) { if (this.getGueltigAb().isAfter(otherRange.getGueltigBis()) || this.getGueltigBis().isBefore(otherRange.getGueltigAb())) { return Optional.empty(); } LocalDate ab = otherRange.getGueltigAb().isAfter(this.getGueltigAb()) ? otherRange.getGueltigAb() : this.getGueltigAb(); LocalDate bis = otherRange.getGueltigBis().isBefore(this.getGueltigBis()) ? otherRange.getGueltigBis() : this.getGueltigBis(); return Optional.of(new DateRange(ab, bis)); } DateRange(@Nonnull LocalDate gueltigAb, @Nonnull LocalDate gueltigBis);  DateRange();  DateRange(@Nonnull LocalDate stichtag);  DateRange(@Nonnull DateRange gueltigkeit);  DateRange(@Nonnull Integer jahr); boolean contains(@Nonnull DateRange other); boolean contains(@Nonnull ChronoLocalDate date); boolean isBefore(@Nonnull ChronoLocalDate date); boolean isAfter(@Nonnull ChronoLocalDate date); boolean startsDayAfter(@Nonnull ChronoLocalDate date); boolean startsDayAfter(@Nonnull DateRange other); boolean startsBefore(@Nonnull DateRange other); boolean startsAfter(@Nonnull ChronoLocalDate date); boolean startsSameDay(@Nonnull DateRange other); boolean startsSameDay(@Nonnull ChronoLocalDate date); boolean endsAfter(@Nonnull DateRange other); boolean endsDayBefore(@Nonnull ChronoLocalDate date); boolean endsDayBefore(@Nonnull DateRange other); boolean endsBefore(@Nonnull DateRange other); boolean endsBefore(@Nonnull ChronoLocalDate date); boolean endsSameDay(@Nonnull DateRange other); boolean endsSameDay(@Nonnull ChronoLocalDate date); boolean isStichtag(); void endOnDayBefore(@Nonnull DateRange other); void startOnDayAfter(@Nonnull DateRange other); @Nonnull DateRange withFullWeeks(); @Nonnull List<DateRange> toFullWeekRanges(); @Nonnull DateRange withFullMonths(); @Nonnull DateRange withFullYears(); @Nonnull Optional<DateRange> getOverlap(@Nonnull DateRange otherRange); LocalDate calculateEndOfPreviousYear(); boolean intersects(@Nonnull DateRange other); long getDays(); @Nonnull LocalDate getGueltigAb(); void setGueltigAb(@Nonnull LocalDate gueltigAb); @Nonnull LocalDate getGueltigBis(); void setGueltigBis(@Nonnull LocalDate gueltigBis); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override @Nonnull String toString(); String toRangeString(); @Override int compareTo(@Nonnull DateRange o); @Nonnull Stream<LocalDate> stream(); @Nonnull Stream<LocalDate> streamStichtage();  }### Answer:
@Test public void testGetOverlap_shouldBeEqualForIdenticalRanges() { assertEquals(year2015, year2015.getOverlap(new DateRange(year2015)).get()); }
@Test public void testGetOverlap_schnittpunktIstStartOderEnde() { LocalDate schnittpunkt = LocalDate.of(1976, 11, 19); DateRange schnittpunktRange = new DateRange(schnittpunkt, schnittpunkt); DateRange a = new DateRange(schnittpunkt.minusYears(1), schnittpunkt); DateRange b = new DateRange(schnittpunkt, schnittpunkt.plusYears(1)); Optional<DateRange> overlap = a.getOverlap(b); assertEquals(schnittpunktRange, overlap.get()); Optional<DateRange> overlapInverse = b.getOverlap(a); assertEquals(schnittpunktRange, overlapInverse.get()); }
@Test public void testGetOverlap_shouldBeEmptyWhenNoOverlap() { assertFalse(year2015.getOverlap(new DateRange(LocalDate.of(2014, 1, 1), LocalDate.of(2014, 12, 31))).isPresent()); }