EndpointManager { public synchronized void setDefaultEndpoint(Endpoint newEndpoint) { if (null == newEndpoint) { throw new NullPointerException("endpoint required!"); } URI uri = newEndpoint.getUri(); if (null == uri) { throw new IllegalArgumentException("Endpoint protocol not supported!"); } String uriScheme = uri.getScheme(); if (!CoAP.isSupportedScheme(uriScheme)) { throw new IllegalArgumentException("URI scheme " + uriScheme + " not supported!"); } Endpoint oldEndpoint = endpoints.put(uriScheme, newEndpoint); if (null != oldEndpoint) { oldEndpoint.destroy(); } if (!newEndpoint.isStarted()) { try { newEndpoint.start(); } catch (IOException e) { LOGGER.error("could not start new {} endpoint", uriScheme, e); } } }  static EndpointManager getEndpointManager(); synchronized Endpoint getDefaultEndpoint(String uriScheme); synchronized void setDefaultEndpoint(Endpoint newEndpoint); Endpoint getDefaultEndpoint(); @Deprecated Collection<InetAddress> getNetworkInterfaces(); static void clear(); static void reset();  }
@Test public void testSetDefaultEndpoint() throws Exception { Endpoint oldEndpoint = EndpointManager.getEndpointManager().getDefaultEndpoint(); Endpoint endpoint = new CoapEndpoint.Builder().build(); EndpointManager.getEndpointManager().setDefaultEndpoint(endpoint); assertThat(EndpointManager.getEndpointManager().getDefaultEndpoint(), is(sameInstance(endpoint))); assertThat(oldEndpoint.isStarted(), is(false)); }