@Test public void addAccessIntervalThrowsExceptionWhenNotBelongingToUser() { User user = new User("user"); User otherUser = new User("other-user"); given(accessIntervalMock.getUser()).willReturn(otherUser); assertThatThrownBy(() -> user.addAccessInterval(accessIntervalMock)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Interval instance belongs to a different or no user!"); }
public void addAccessInterval(AccessInterval interval) throws IllegalArgumentException { Objects.requireNonNull(interval); if(!this.equals(interval.getUser())) { throw new IllegalArgumentException("Interval instance belongs to a different or no user!"); } accessIntervals.add(interval); }
User { public void addAccessInterval(AccessInterval interval) throws IllegalArgumentException { Objects.requireNonNull(interval); if(!this.equals(interval.getUser())) { throw new IllegalArgumentException("Interval instance belongs to a different or no user!"); } accessIntervals.add(interval); } }
User { public void addAccessInterval(AccessInterval interval) throws IllegalArgumentException { Objects.requireNonNull(interval); if(!this.equals(interval.getUser())) { throw new IllegalArgumentException("Interval instance belongs to a different or no user!"); } accessIntervals.add(interval); } User(String userId); protected  User(); }
User { public void addAccessInterval(AccessInterval interval) throws IllegalArgumentException { Objects.requireNonNull(interval); if(!this.equals(interval.getUser())) { throw new IllegalArgumentException("Interval instance belongs to a different or no user!"); } accessIntervals.add(interval); } 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 void addAccessInterval(AccessInterval interval) throws IllegalArgumentException { Objects.requireNonNull(interval); if(!this.equals(interval.getUser())) { throw new IllegalArgumentException("Interval instance belongs to a different or no user!"); } accessIntervals.add(interval); } 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);  }