TomcatXmppWebSocketServlet extends WebSocketServlet { @Override public void init() throws ServletException { super.init(); if (serverRuntimeContext == null) { serverRuntimeContext = (ServerRuntimeContext) getServletContext() .getAttribute(SERVER_RUNTIME_CONTEXT_ATTRIBUTE); if (serverRuntimeContext == null) { throw new RuntimeException("Failed to get Vysper ServerRuntimeContext from servlet context attribute \"" + SERVER_RUNTIME_CONTEXT_ATTRIBUTE + "\""); } } if (stanzaProcessor == null) { stanzaProcessor = (StanzaProcessor) getServletContext() .getAttribute(StanzaProcessor.class.getCanonicalName()); if (stanzaProcessor == null) { throw new RuntimeException("Failed to get Vysper StanzaProcessor from servlet context attribute \"" + StanzaProcessor.class.getCanonicalName() + "\""); } } } TomcatXmppWebSocketServlet();  TomcatXmppWebSocketServlet(ServerRuntimeContext serverRuntimeContext, StanzaProcessor stanzaProcessor); @Override void init(); static final String SERVER_RUNTIME_CONTEXT_ATTRIBUTE; }
@Test(expected=RuntimeException.class) public void doWebSocketConnectMissingAttribute() throws ServletException { ServletContext servletContext = Mockito.mock(ServletContext.class); ServletConfig servletConfig = Mockito.mock(ServletConfig.class); Mockito.when(servletConfig.getServletContext()).thenReturn(servletContext); JettyXmppWebSocketServlet servlet = new JettyXmppWebSocketServlet(); servlet.init(servletConfig); }