MessageControllerManager { JsTopicMessageController getJsTopicMessageControllerFromIterable(String topic, Iterable<JsTopicMessageController<?>> controllers) { if(null == controllers || null == topic) { return null; } for (JsTopicMessageController<?> jsTopicMessageController : controllers) { JsTopicControls jsTopicControls = jsTopicControlsTools.getJsTopicControlsFromProxyClass(jsTopicMessageController.getClass()); if(null != jsTopicControls) { JsTopicControl[] jsTopicControlList = jsTopicControls.value(); for (JsTopicControl jsTopicControl : jsTopicControlList) { if(topic.equals(jsTopicControl.value())) { logger.debug("Found messageController for topic '{}' from JsTopicControls annotation", topic); return jsTopicMessageController; } } } } return null; }  JsTopicMessageController getJsTopicMessageController(String topic);  }
@Test public void getJsTopicMessageControllerFromIterableTest() { System.out.println("getJsTopicMessageControllerFromIterable"); Collection<JsTopicMessageController<?>> controllers = new ArrayList<>(); JsTopicMessageController<?> jtmc = mock(JsTopicMessageController.class); JsTopicControls jtcs = mock(JsTopicControls.class); doReturn(jtcs).when(jsTopicControlsTools).getJsTopicControlsFromProxyClass(eq(jtmc.getClass())); when(jtcs.value()).thenReturn(new JsTopicControl[]{}) .thenReturn(new JsTopicControl[]{new JsTopicCtrlAnnotationLiteral("FOO")}) .thenReturn(new JsTopicControl[]{new JsTopicCtrlAnnotationLiteral(TOPIC)}); JsTopicMessageController result = instance.getJsTopicMessageControllerFromIterable(TOPIC, null); assertThat(result).isNull(); result = instance.getJsTopicMessageControllerFromIterable(null, mock(Iterable.class)); assertThat(result).isNull(); result = instance.getJsTopicMessageControllerFromIterable(TOPIC, controllers); assertThat(result).isNull(); controllers.add(jtmc); result = instance.getJsTopicMessageControllerFromIterable(TOPIC, controllers); assertThat(result).isNull(); result = instance.getJsTopicMessageControllerFromIterable(TOPIC, controllers); assertThat(result).isNull(); result = instance.getJsTopicMessageControllerFromIterable(TOPIC, controllers); assertThat(result).isEqualTo(jtmc); }