### Question:
LocatorRegistry { public By getLocator(String key) { if (!registry.containsKey(key)) throw new LocatorException("Cannot find the locator with key [" + key + "]"); return registry.get(key); } @Inject  LocatorRegistry();   LocatorRegistry(Properties properties, File... files); By getLocator(String key);  }### Answer:
@Test public void shouldRegisterWhenFlattenedLocatorFileIsLoaded() throws URISyntaxException { File locatorFile = new File(LocatorRegistryTest.class.getResource("/conf/flattened/locator.yml").toURI()); LocatorRegistry locatorRegistry = new LocatorRegistry(new Properties(), locatorFile); assertTrue(locatorRegistry.getLocator("my-button") instanceof ByCssSelector); assertTrue(locatorRegistry.getLocator("my-input") instanceof ByXPath); assertTrue(locatorRegistry.getLocator("my-frame") instanceof ById); assertEquals(new ByCssSelector("#mypage .mybutton"), locatorRegistry.getLocator("my-button")); assertEquals(new ByXPath(" assertEquals(new ById("myframe"), locatorRegistry.getLocator("my-frame")); }
@Test public void shouldRegisterDefaultProfileWhenLocatorPropertyIsNotSet() throws URISyntaxException { File locatorFile = new File(LocatorRegistryTest.class.getResource("/conf/hierarchical/locator.yml").toURI()); LocatorRegistry locatorRegistry = new LocatorRegistry(new Properties(), locatorFile); assertTrue(locatorRegistry.getLocator("my-button") instanceof ByCssSelector); assertTrue(locatorRegistry.getLocator("my-input") instanceof ByXPath); assertTrue(locatorRegistry.getLocator("my-frame") instanceof ById); assertEquals(new ByCssSelector("#mypage .mybutton"), locatorRegistry.getLocator("my-button")); assertEquals(new ByXPath(" assertEquals(new ById("myframe"), locatorRegistry.getLocator("my-frame")); }
@Test public void shouldRegisterUserSpecifiedProfileWhenLocatorPropertyIsSet() throws URISyntaxException { Properties properties = new Properties(); properties.setProperty("locator", "override"); File locatorFile = new File(LocatorRegistryTest.class.getResource("/conf/hierarchical/locator.yml").toURI()); LocatorRegistry locatorRegistry = new LocatorRegistry(properties, locatorFile); assertTrue(locatorRegistry.getLocator("my-button") instanceof ByCssSelector); assertTrue(locatorRegistry.getLocator("my-input") instanceof ByXPath); assertTrue(locatorRegistry.getLocator("my-frame") instanceof ById); assertEquals(new ByCssSelector("#overridepage .overridebutton"), locatorRegistry.getLocator("my-button")); assertEquals(new ByXPath(" assertEquals(new ById("myframe"), locatorRegistry.getLocator("my-frame")); }