TopicAccessManager { boolean checkAccessTopicFromController(UserContext ctx, String topic, JsTopicAccessController jsTopicAccessController) throws IllegalAccessException { logger.debug("Looking for accessController for topic '{}' from JsTopicAccessController {}", topic, jsTopicAccessController); JsTopicControls jsTopicControls = jsTopicControlsTools.getJsTopicControlsFromProxyClass(jsTopicAccessController.getClass()); logger.debug("Looking for accessController for topic '{}' from jsTopicControls {}", topic, jsTopicControls); if(null != jsTopicControls) { logger.debug("Looking for accessController for topic '{}' from jsTopicControls {}, {}", topic, jsTopicControls, jsTopicControls.value()); for (JsTopicControl jsTopicControl : jsTopicControls.value()) { if(topic.equals(jsTopicControl.value())) { logger.debug("Found accessController for topic '{}' from JsTopicControls annotation", topic); checkAccessTopicFromControllers(ctx, topic, Arrays.asList(jsTopicAccessController)); return true; } } } return false; }  void checkAccessTopic(UserContext ctx, String topic);  }
@Test(expected = IllegalAccessException.class) public void checkAccessTopicFromControllerTest() throws IllegalAccessException { System.out.println("checkAccessTopicFromController"); UserContext userContext = mock(UserContext.class); JsTopicAccessController jtac = mock(JsTopicAccessController.class); JsTopicControls jtcs = mock(JsTopicControls.class); JsTopicControl[] controls1 = new JsTopicControl[] {new JsTopicCtrlAnnotationLiteral(TOPIC2)}; JsTopicControl[] controls2 = new JsTopicControl[] {new JsTopicCtrlAnnotationLiteral(TOPIC2), new JsTopicCtrlAnnotationLiteral(TOPIC1)}; when(jtcs.value()).thenReturn(controls1); doReturn(jtcs).when(jsTopicControlsTools).getJsTopicControlsFromProxyClass(eq(jtac.getClass())); doReturn(Boolean.TRUE).doThrow(IllegalAccessException.class).when(instance).checkAccessTopicFromControllers(eq(userContext), eq(TOPIC1), any(Collection.class)); boolean result = instance.checkAccessTopicFromController(userContext, TOPIC1, jtac); assertThat(result).isFalse(); when(jtcs.value()).thenReturn(controls2); result = instance.checkAccessTopicFromController(userContext, TOPIC1, jtac); assertThat(result).isTrue(); instance.checkAccessTopicFromController(userContext, TOPIC1, jtac); }