OcelotServices { public String getUsername() { logger.debug("Receive getUsername call from client."); return ocelotContext.getPrincipal().getName(); }  void initCore(Options options, HttpSession httpSession); @JsCacheRemove(cls = OcelotServices.class, methodName = "getLocale", keys = {}, userScope = true) void setLocale(@JsonUnmarshaller(LocaleMarshaller.class) Locale locale); @JsCacheResult(year = 1) @JsonMarshaller(LocaleMarshaller.class) Locale getLocale(); String getUsername(); Collection<String> getOutDatedCache(Map<String, Long> states); @JsTopic @WsDataService Integer subscribe(@JsTopicName(prefix = Constants.Topic.SUBSCRIBERS) String topic, Session session); @JsTopic @WsDataService Integer unsubscribe(@JsTopicName(prefix = Constants.Topic.SUBSCRIBERS) String topic, Session session); Integer getNumberSubscribers(String topic); String getVersion();  }
@Test public void testGetUsername() { System.out.println("getUsername"); Principal p1 = mock(Principal.class); Principal p2 = mock(Principal.class); String u1 = Constants.ANONYMOUS; String u2 = "username"; when(p1.getName()).thenReturn(u1); when(p2.getName()).thenReturn(u2); when(ocelotContext.getPrincipal()).thenReturn(p1).thenReturn(p2); assertThat(instance.getUsername()).isEqualTo(u1); assertThat(instance.getUsername()).isEqualTo(u2); }