GuidedTourCustomSelectorPositionProvider { public Rect getPosition(final String querySelector) { final String[] querySelectorParts = getQuerySelectorParts(querySelector); final boolean isValidQuerySelector = querySelectorParts.length == 2; if (isValidQuerySelector) { final String type = querySelectorParts[0]; final String selector = querySelectorParts[1]; final Optional<PositionProviderFunction> positionProvider = Optional.ofNullable(providers.get(type)); if (positionProvider.isPresent()) { return positionProvider.get().call(selector); } else { DomGlobal.console.warn("[Guided Tour - Position Provider] The position provider could not be found: " + type); } } else { DomGlobal.console.warn("[Guided Tour - Position Provider] Invalid custom query selector: " + querySelector); } return none(); } private  GuidedTourCustomSelectorPositionProvider(); static GuidedTourCustomSelectorPositionProvider getInstance(); Rect getPosition(final String querySelector); void registerPositionProvider(final String type,
                                         final PositionProviderFunction positionProviderFunction);  }
@Test public void testGetPosition() { final Rect rect1 = makeRect(1); final Rect rect2 = makeRect(2); positionProvider.registerPositionProvider("TEST_PROVIDER_1", name -> Objects.equals(name, "OBJECT-1") ? rect1 : rect2); assertEquals(rect1, positionProvider.getPosition("TEST_PROVIDER_1:::OBJECT-1")); assertEquals(rect2, positionProvider.getPosition("TEST_PROVIDER_1:::OBJECT-2")); }
@Test public void testGetPositionWhenNoSelectorIsRegistered() { final Rect position = positionProvider.getPosition("TEST_PROVIDER_3:::OBJECT-1"); verify(console).warn("[Guided Tour - Position Provider] The position provider could not be found: TEST_PROVIDER_3"); assertEquals(none, position); }
@Test public void testGetPositionWhenSelectorIsNull() { final Rect position = positionProvider.getPosition(null); verify(console).warn("[Guided Tour - Position Provider] Invalid custom query selector: null"); assertEquals(none, position); }