ServiceData { public boolean addEndpoint(final Endpoint endpoint) { if (endpoint == null) { throw new IllegalArgumentException("Endpoint can not be null"); } synchronized (syncObject) { if (endpoints.containsKey(endpoint.getName())) { return false; } endpoints.put(endpoint.getName(), endpoint); } return true; } ServiceData();   ServiceData(final List<Endpoint> endpointList); Endpoint getEndpoint(final String name); boolean addEndpoint(final Endpoint endpoint); boolean removeEndpoint(final Endpoint endpoint);  }
@Test public void uniqueNamesAreRequired() { final Endpoint endpointA = new Endpoint("foo", "bar", 80); final Endpoint endpointB = new Endpoint("foo", "baz", 82); final Endpoint endpointC = new Endpoint("foo", "localhost", 80); final Endpoint endpointD = new Endpoint("foobar", "localhost", 80); final ServiceData serviceData = new ServiceData(new ArrayList<Endpoint>()); assertThat(serviceData.addEndpoint(endpointA), is(true)); assertThat(serviceData.addEndpoint(endpointB), is(false)); assertThat(serviceData.addEndpoint(endpointC), is(false)); assertThat(serviceData.addEndpoint(endpointD), is(true)); }
@Test (expected = IllegalArgumentException.class) public void addNullEndpoint() { final ServiceData data = new ServiceData(); data.addEndpoint(null); }