### Question:
InjectionAnnotations extends AbstractAnnotations implements FluentLabelProvider { @Override public By buildBy() { if (mobileElement) { return defaultElementByBuilder.buildBy(); } By fieldBy = fieldAnnotations.buildBy(); By classBy = classAnnotations.buildBy(); if (classBy != null && fieldBy instanceof ByIdOrName) { return classBy; } return fieldBy; } InjectionAnnotations(Field field, Capabilities capabilities); @Override By buildBy(); @Override boolean isLookupCached(); @Override String getLabel(); @Override String[] getLabelHints();  }### Answer:
@Test public void shouldInjectCssField() throws NoSuchFieldException { Field cssField = this.getClass().getDeclaredField("css"); InjectionAnnotations annotations = new InjectionAnnotations(cssField, null); By by = annotations.buildBy(); assertThat(by).isInstanceOf(By.ByCssSelector.class).isEqualTo(By.cssSelector("css")); }
@Test public void shouldInjectXpathField() throws NoSuchFieldException { Field xpathField = this.getClass().getDeclaredField("xpath"); InjectionAnnotations annotations = new InjectionAnnotations(xpathField, null); By by = annotations.buildBy(); assertThat(by).isInstanceOf(By.ByXPath.class).isEqualTo(By.xpath("xpath")); }
@Test public void shouldInjectIosAccessibilityIdField() throws NoSuchFieldException { Field accessibilityField = this.getClass().getDeclaredField("iosAccessibilityId"); InjectionAnnotations annotations = new InjectionAnnotations(accessibilityField, getIosCapablities()); By by = annotations.buildBy(); assertThat(by).isInstanceOf(ContentMappedBy.class) .isEqualTo(new ByChained(MobileBy.AccessibilityId("iosAccessibilityId"))); }
@Test public void shouldInjectIosFindAllField() throws NoSuchFieldException { Field iosFindAllField = this.getClass().getDeclaredField("iosFindBys"); InjectionAnnotations annotations = new InjectionAnnotations(iosFindAllField, getIosCapablities()); By by = annotations.buildBy(); assertThat(by).isInstanceOf(ContentMappedBy.class); ByChained expectedBy = new ByChained(new ByChained(MobileBy.id("oneline"), MobileBy.className("small"))); assertThat(by).isEqualTo(expectedBy); }
@Test public void shouldInjectAndroidAccessibilityIdField() throws NoSuchFieldException { Field uiAutomator = this.getClass().getDeclaredField("androidUiAutomator"); InjectionAnnotations annotations = new InjectionAnnotations(uiAutomator, getAndroidCapablities()); By by = annotations.buildBy(); assertThat(by).isInstanceOf(ContentMappedBy.class) .isEqualTo(new ByChained(MobileBy.AndroidUIAutomator("androidUiAutomator"))); }
@Test public void shouldInjectWindowsAutomationField() throws NoSuchFieldException { Field windowsField = this.getClass().getDeclaredField("windowsAutomation"); InjectionAnnotations annotations = new InjectionAnnotations(windowsField, getWindowsCapabilities()); By by = annotations.buildBy(); assertThat(by).isInstanceOf(ContentMappedBy.class) .isEqualTo(new ByChained(MobileBy.ByWindowsAutomation.windowsAutomation("windowsAutomation"))); }
@Test public void voidShouldPickCorrectSelectorWhenOnMultiplePlatform() throws NoSuchFieldException { Field field = this.getClass().getDeclaredField("multiPlatformElement"); By androidBy = new InjectionAnnotations(field, getAndroidCapablities()).buildBy(); assertThat(androidBy).isEqualTo(new ByChained(MobileBy.AccessibilityId("android"))); By iosBy = new InjectionAnnotations(field, getIosCapablities()).buildBy(); assertThat(iosBy).isEqualTo(new ByChained(MobileBy.tagName("ios"))); }