ComponentChildLocator { public final Optional<LicketComponent<?>> findByCompositeId(CompositeId compositeId) { ChildrenTraverse traverse = new ChildrenTraverse(compositeId); startingComponent.traverseDown(traverse); return traverse.getFound(); } ComponentChildLocator(LicketComponent<?> startingComponent); final Optional<LicketComponent<?>> findByCompositeId(CompositeId compositeId);  }
@Test public void shouldFindChildAtNthLevelWhenCompositeIdMatchesComponentTree() { ComponentChildLocator locator = childLocator(); CompositeId compositeId = fromStringValue("2:3:4:5"); Optional<? extends LicketComponent<?>> rootComponent = locator.findByCompositeId(compositeId); assertThat(rootComponent.isPresent()).isTrue(); }
@Test public void shouldFindChildAtNthLevelWhenCompositeIdIsShorterThanComponentTreeButMatches() { ComponentChildLocator locator = childLocator(); CompositeId compositeId = fromStringValue("2:3"); Optional<? extends LicketComponent<?>> rootComponent = locator.findByCompositeId(compositeId); assertThat(rootComponent.isPresent()).isTrue(); }
@Test public void shouldNotFindChildAtNthLevelWhenCompositeIdIsLongerThanComponentTree() { ComponentChildLocator locator = childLocator(); CompositeId compositeId = fromStringValue("2:3:4:5:6:7:8"); Optional<? extends LicketComponent<?>> rootComponent = locator.findByCompositeId(compositeId); assertThat(rootComponent.isPresent()).isFalse(); }
@Test public void shouldNotFindChildAtNthLevelWhenCompositeIdDoesNotMatchAtAll() { ComponentChildLocator locator = childLocator(); CompositeId compositeId = fromStringValue("6:3:1:3"); Optional<? extends LicketComponent<?>> rootComponent = locator.findByCompositeId(compositeId); assertThat(rootComponent.isPresent()).isFalse(); }