### Question:
WebSocketServiceImpl implements WebSocketService { @SuppressWarnings("unchecked") public static WebSocketContainer getWebSocketContainer() { String containerFactoryClassName = systemProperty(WEB_SOCKET_CONTAINER_FACTORY_PROPERTY, DEFAULT_WEB_SOCKET_CONTAINER_FACTORY); if (containerFactoryClassName == null || containerFactoryClassName.isEmpty()) { throw new RuntimeException(WEB_SOCKET_CONTAINER_FACTORY_PROPERTY + " property not set"); } try { Class<WebSocketContainerFactory> containerFactoryClass = (Class<WebSocketContainerFactory>) Class.forName(containerFactoryClassName); if (WebSocketContainerFactory.class.isAssignableFrom(containerFactoryClass)) { WebSocketContainerFactory containerFactory = containerFactoryClass.newInstance(); return containerFactory.getWebSocketContainer(); } throw new RuntimeException( containerFactoryClassName + " does not implement com.github.kklisura.cdt.services.factory.WebSocketContainerFactory interface."); } catch (ClassNotFoundException e) { throw new RuntimeException(containerFactoryClassName + " class not found.", e); } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException( "Could not create instance of " + containerFactoryClassName + " class"); } } WebSocketServiceImpl(Session session); private  WebSocketServiceImpl(); static WebSocketService create(URI uri); @Override void connect(URI uri); @Override void send(String message); @Override void addMessageHandler(Consumer<String> consumer); @Override void close(); @Override boolean closed(); @SuppressWarnings("unchecked") static WebSocketContainer getWebSocketContainer(); static final String WEB_SOCKET_CONTAINER_FACTORY_PROPERTY; }### Answer:
@Test public void testGetWebSocketContainerReturnsDefaultContainerFactory() { System.setProperty(WebSocketServiceImpl.WEB_SOCKET_CONTAINER_FACTORY_PROPERTY, ""); WebSocketContainer webSocketContainer; webSocketContainer = WebSocketServiceImpl.getWebSocketContainer(); assertTrue(webSocketContainer instanceof ClientManager); System.setProperty( WebSocketServiceImpl.WEB_SOCKET_CONTAINER_FACTORY_PROPERTY, CustomWebSocketContainerFactory.class.getName()); webSocketContainer = WebSocketServiceImpl.getWebSocketContainer(); assertNull(webSocketContainer); }
@Test(expected = RuntimeException.class) public void testGetWebSocketContainerFailsOnUnknownFactoryClass() { System.setProperty(WebSocketServiceImpl.WEB_SOCKET_CONTAINER_FACTORY_PROPERTY, "non-existing"); WebSocketServiceImpl.getWebSocketContainer(); }
@Test(expected = RuntimeException.class) public void testGetWebSocketContainerFailsOnNonImplementingFactoryClass() { System.setProperty( WebSocketServiceImpl.WEB_SOCKET_CONTAINER_FACTORY_PROPERTY, CustomNonImplementingWebSocketContainerFactory.class.getName()); WebSocketServiceImpl.getWebSocketContainer(); }