WSController implements IWSController { void setContext(HandshakeRequest request) { HttpSession httpSession = (HttpSession) request.getHttpSession(); ThreadLocalContextHolder.put(Constants.HTTPSESSION, httpSession); if(null == httpSession.getAttribute(Constants.LOCALE)) { httpSession.setAttribute(Constants.LOCALE, getLocale(request)); } }  @Override void handleOpenConnexion(Session session, EndpointConfig config); @Override void onError(Session session, Throwable t); @Override void handleClosedConnexion(Session session, CloseReason closeReason); @Override void receiveCommandMessage(Session client, String json);  }
@Test public void setContextTest() { System.out.println("setContext"); ThreadLocalContextHolder.cleanupThread(); HandshakeRequest request = mock(HandshakeRequest.class); HttpSession httpSession = mock(HttpSession.class); when(request.getHttpSession()).thenReturn(httpSession); when(httpSession.getAttribute(eq(Constants.LOCALE))).thenReturn(null).thenReturn(Locale.CHINA); doReturn(Locale.CANADA).when(instance).getLocale(eq(request)); instance.setContext(request); Object result = ThreadLocalContextHolder.get(Constants.HTTPSESSION); verify(httpSession).setAttribute(eq(Constants.LOCALE), eq(Locale.CANADA)); assertThat(result).isEqualTo(httpSession); }