### Question:
TemporalGraph2DRenderer { static TimeInterval aggregateTimeInterval(TimeInterval dataTimeInterval, TimeInterval aggregatedTimeInterval) { if (aggregatedTimeInterval == null) { return dataTimeInterval; } else { if (aggregatedTimeInterval.contains(dataTimeInterval.getEnd()) && aggregatedTimeInterval.contains(dataTimeInterval.getStart())) { return aggregatedTimeInterval; } if (dataTimeInterval.contains(aggregatedTimeInterval.getEnd()) && dataTimeInterval.contains(aggregatedTimeInterval.getStart())) { return dataTimeInterval; } Instant start; Instant end; if (dataTimeInterval.getStart().compareTo(aggregatedTimeInterval.getStart()) > 0) { start = aggregatedTimeInterval.getStart(); } else { start = dataTimeInterval.getStart(); } if (dataTimeInterval.getEnd().compareTo(aggregatedTimeInterval.getEnd()) < 0) { end = aggregatedTimeInterval.getEnd(); } else { end = dataTimeInterval.getEnd(); } return TimeInterval.between(start, end); } } TemporalGraph2DRenderer(int graphWidth, int graphHeight); int getImageHeight(); int getImageWidth(); AxisRange getAxisRange(); TimeAxisRange getTimeAxisRange(); Range getAggregatedRange(); TimeInterval getAggregatedTimeInterval(); Range getPlotRange(); TimeInterval getPlotTimeInterval(); void update(T update); abstract T newUpdate();  }### Answer:
@Test public void aggregateTimeInterval1() { Instant time = Instant.now(); TimeInterval interval1 = TimeInterval.after(Duration.ofSeconds(1), time); TimeInterval interval2 = TimeInterval.after(Duration.ofSeconds(2), time); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval1, interval2), sameInstance(interval2)); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval2, interval1), sameInstance(interval2)); }
@Test public void aggregateTimeInterval2() { Instant time = Instant.now(); TimeInterval interval1 = TimeInterval.after(Duration.ofSeconds(1), time); TimeInterval interval2 = TimeInterval.around(Duration.ofSeconds(4), time); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval1, interval2), sameInstance(interval2)); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval2, interval1), sameInstance(interval2)); }
@Test public void aggregateTimeInterval4() { Instant time = Instant.now(); TimeInterval interval1 = TimeInterval.around(Duration.ofSeconds(1), time); TimeInterval interval2 = TimeInterval.after(Duration.ofSeconds(1), time); TimeInterval total = TimeInterval.between(interval1.getStart(), interval2.getEnd()); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval1, interval2), equalTo(total)); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval2, interval1), equalTo(total)); }
@Test public void aggregateTimeInterval3() { Instant time = Instant.now(); TimeInterval interval1 = TimeInterval.before(Duration.ofSeconds(1), time); TimeInterval interval2 = TimeInterval.after(Duration.ofSeconds(1), time.plus(Duration.ofSeconds(1))); TimeInterval total = TimeInterval.between(interval1.getStart(), interval2.getEnd()); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval1, interval2), equalTo(total)); assertThat(TemporalGraph2DRenderer.aggregateTimeInterval(interval2, interval1), equalTo(total)); }