MessageControllerCache { public JsTopicMessageController loadFromCache(String topic) { if(null == topic) { return null; } if(messageControllers.containsKey(topic)) { Instance<? extends JsTopicMessageController> instances = getInstances(messageControllers.get(topic)); if(!instances.isUnsatisfied()) { return instances.get(); } } return null; }  void saveToCache(String topic, Class<? extends JsTopicMessageController> cls); JsTopicMessageController loadFromCache(String topic);  }
@Test public void testLoadFromCache() { System.out.println("loadFromCache"); String topic = "TOPIC"; instance.messageControllers.clear(); instance.messageControllers.put(topic, JsTopicMessageController.class); FakeCDI<JsTopicMessageController> instances = new FakeCDI<>(); doReturn(instances).when(instance).getInstances(any(Class.class)); JsTopicMessageController result = instance.loadFromCache(topic); assertThat(result).isNull(); instances.add(jtmc); result = instance.loadFromCache(topic); assertThat(result).isNotNull(); result = instance.loadFromCache(null); assertThat(result).isNull(); result = instance.loadFromCache("UNKNOWN"); assertThat(result).isNull(); }