@Test public void getLatestAccessIntervalReturnsLastAddedWhenCollectionContainsMultipleElements() { AccessInterval expectedAccessIntervalMock = mock(AccessInterval.class); User user = new User("user"); user.accessIntervals.addAll(Arrays.asList(accessIntervalMock, expectedAccessIntervalMock)); AccessInterval actualAccessInterval = user.getLatestAccessInterval() .orElseThrow(() -> new IllegalStateException("No interval instance present!")); assertThat(actualAccessInterval).isEqualTo(expectedAccessIntervalMock); }
public Optional<AccessInterval> getLatestAccessInterval() { if(accessIntervals.size() > 0) { return Optional.of(accessIntervals.get(accessIntervals.size() - 1)); } return Optional.empty(); }
User { public Optional<AccessInterval> getLatestAccessInterval() { if(accessIntervals.size() > 0) { return Optional.of(accessIntervals.get(accessIntervals.size() - 1)); } return Optional.empty(); } }
User { public Optional<AccessInterval> getLatestAccessInterval() { if(accessIntervals.size() > 0) { return Optional.of(accessIntervals.get(accessIntervals.size() - 1)); } return Optional.empty(); } User(String userId); protected  User(); }
User { public Optional<AccessInterval> getLatestAccessInterval() { if(accessIntervals.size() > 0) { return Optional.of(accessIntervals.get(accessIntervals.size() - 1)); } return Optional.empty(); } User(String userId); protected  User(); void addBookmark(Project project); void removeBookmark(Project project); void addApplication(ProjectApplication application); void removeApplication(ProjectApplication application); Optional<AccessInterval> getLatestAccessInterval(); void addAccessInterval(AccessInterval interval); void removeAccessInterval(AccessInterval interval); }
User { public Optional<AccessInterval> getLatestAccessInterval() { if(accessIntervals.size() > 0) { return Optional.of(accessIntervals.get(accessIntervals.size() - 1)); } return Optional.empty(); } User(String userId); protected  User(); void addBookmark(Project project); void removeBookmark(Project project); void addApplication(ProjectApplication application); void removeApplication(ProjectApplication application); Optional<AccessInterval> getLatestAccessInterval(); void addAccessInterval(AccessInterval interval); void removeAccessInterval(AccessInterval interval);  }