### Question:
EnvironmentImpl implements Environment { @Override public Component findComponentWithName(String componentName) { return findFirstResult(groups, g -> g.findComponentWithName(componentName)) .orElseGet(() -> componentFactory.createComponent(componentName, componentName, name)); }  @Override List<ComponentGroup> findGroupsWithIp(String ip); @Override ComponentGroup getGroupWithName(String groupName); @Override Optional<ComponentGroup> findGroupWithComponent(String componentName); @Override Components getAllComponents(); @Override Component getComponentWithName(String componentName); @Override Components findComponentsFrom(List<String> groups, List<String> componentNames); @Override Component findComponentWithName(String componentName); @Override String toString();  }### Answer:
@Test void getOrCreateComponentWithName() { when(group1.findComponentWithName("two")).thenReturn(of(two)); assertEquals(two, env.findComponentWithName("two")); Component four = mock(Component.class); when(factory.createComponent("four", "four", env.getName())).thenReturn(four); assertEquals(four, env.findComponentWithName("four")); }