TopicAccessManager { boolean checkAccessTopicFromJsTopicControl(UserContext ctx, String topic) throws IllegalAccessException { logger.debug("Looking for accessController for topic '{}' from JsTopicControl annotation", topic); Iterable<JsTopicAccessController> accessControls = topicAccessController.select(new JsTopicCtrlAnnotationLiteral(topic)); return checkAccessTopicFromControllers(ctx, topic, accessControls); }  void checkAccessTopic(UserContext ctx, String topic);  }
@Test(expected = IllegalAccessException.class) public void checkAccessTopicFromJsTopicControlTest() throws IllegalAccessException { System.out.println("checkAccessTopicFromJsTopicControl"); UserContext userContext = mock(UserContext.class); Instance instances = mock(Instance.class); when(topicAccessController.select(eq(new JsTopicCtrlAnnotationLiteral(TOPIC1)))).thenReturn(instances); doReturn(Boolean.FALSE).doReturn(Boolean.TRUE).doThrow(IllegalAccessException.class).when(instance).checkAccessTopicFromControllers(eq(userContext), eq(TOPIC1), eq(instances)); boolean result = instance.checkAccessTopicFromJsTopicControl(userContext, TOPIC1); assertThat(result).isFalse(); result = instance.checkAccessTopicFromJsTopicControl(userContext, TOPIC1); assertThat(result).isTrue(); instance.checkAccessTopicFromJsTopicControl(userContext, TOPIC1); }