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