Route { public List<Location> visits() { return Collections.unmodifiableList(visits); } Route(Vehicle vehicle, Location depot, List<Location> visits); Vehicle vehicle(); Location depot(); List<Location> visits(); @Override String toString();  }
@Test void cannot_modify_visits_externally() { ArrayList<Location> visits = new ArrayList<>(); visits.add(visit1); List<Location> routeVisits = new Route(vehicle, depot, visits).visits(); assertThatExceptionOfType(UnsupportedOperationException.class) .isThrownBy(routeVisits::clear); }