Route { @Override public String toString() { return "Route{" + "vehicle=" + vehicle + ", depot=" + depot.id() + ", visits=" + visits.stream().map(Location::id).collect(toList()) + '}'; } Route(Vehicle vehicle, Location depot, List<Location> visits); Vehicle vehicle(); Location depot(); List<Location> visits(); @Override String toString();  }
@Test void visits_should_not_contain_depot() { assertThatIllegalArgumentException() .isThrownBy(() -> new Route(vehicle, depot, Arrays.asList(depot, visit1))) .withMessageContaining(depot.toString()); assertThatIllegalArgumentException() .isThrownBy(() -> new Route(vehicle, depot, Arrays.asList(visit1, depot, visit2))) .withMessageContaining(depot.toString()); }