TopicAccessManager { boolean checkAccessTopicFromJsTopicAccessControllers(UserContext ctx, String topic, Iterable<JsTopicAccessController> controllers) throws IllegalAccessException { logger.debug("Looking for accessController for topic '{}' from JsTopicAccessControllers", topic); for (JsTopicAccessController jsTopicAccessController : controllers) { if(checkAccessTopicFromController(ctx, topic, jsTopicAccessController)) { return true; } } return false; }  void checkAccessTopic(UserContext ctx, String topic);  }
@Test(expected = IllegalAccessException.class) public void checkAccessTopicFromJsTopicAccessControllersTest() throws IllegalAccessException { System.out.println("checkAccessTopicFromJsTopicAccessControllers"); Collection<JsTopicAccessController> controllers = new ArrayList<>(); JsTopicAccessController jtac0 = mock(JsTopicAccessController.class); JsTopicAccessController jtac1 = mock(JsTopicAccessController.class); JsTopicAccessController jtac2 = mock(JsTopicAccessController.class); UserContext userContext = mock(UserContext.class); doReturn(Boolean.FALSE).when(instance).checkAccessTopicFromController(eq(userContext), eq(TOPIC1), eq(jtac0)); doReturn(Boolean.TRUE).doThrow(IllegalAccessException.class).when(instance).checkAccessTopicFromController(eq(userContext), eq(TOPIC1), eq(jtac1)); boolean result = instance.checkAccessTopicFromJsTopicAccessControllers(userContext, TOPIC1, controllers); assertThat(result).isFalse(); controllers.add(jtac0); controllers.add(jtac1); controllers.add(jtac2); instance.checkAccessTopicFromJsTopicAccessControllers(userContext, TOPIC1, controllers); instance.checkAccessTopicFromJsTopicAccessControllers(userContext, TOPIC1, controllers); }