Services { @JsonProperty public Set<Service> getServices() { return services; } Services(String environment, Set<Service> services); @JsonProperty String getEnvironment(); @JsonProperty Set<Service> getServices(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void testCreatesDefensiveCopyOfServices() { Set<Service> set = Sets.newHashSet(); set.add(new Service(Id.<Service>random(), Id.<Node>random(), "blue", "pool", "/location", ImmutableMap.of("key", "value"))); Services services = new Services("testing", set); assertEquals(services.getServices(), set); set.add(new Service(Id.<Service>random(), Id.<Node>random(), "red", "pool", "/location", ImmutableMap.of("key", "value"))); assertNotEquals(services.getServices(), set); }
@Test public void testServicesSetIsImmutable() { Service blue = new Service(Id.<Service>random(), Id.<Node>random(), "blue", "pool", "/location", ImmutableMap.of("key", "value")); Services services = new Services("testing", Sets.newHashSet(blue)); try { services.getServices().add(new Service(Id.<Service>random(), Id.<Node>random(), "red", "pool", "/location", ImmutableMap.of("key", "value"))); assertEquals(services.getServices(), ImmutableSet.of(blue)); } catch (UnsupportedOperationException e) { } }