public static Object enrich(final Object instance) { for (final TestEnricher enricher : TEST_ENRICHERS) { try { enricher.enrich(instance); } catch (final Exception e) { // no-op: don't make all enrichment fail because of one enricher } } return instance; }
private void enrichContainerObjectBeforeCube() { for (TestEnricher enricher : enrichers) { boolean requiresDockerInstanceCreated = enricher instanceof HostPortTestEnricher || enricher instanceof CubeIpTestEnricher; if (!requiresDockerInstanceCreated) { enricher.enrich(containerObjectInstance); } } }
private void enrichContainerObjectBeforeCube() { for (TestEnricher enricher : enrichers) { boolean requiresDockerInstanceCreated = enricher instanceof HostPortTestEnricher || enricher instanceof CubeIpTestEnricher; if (!requiresDockerInstanceCreated) { enricher.enrich(containerObjectInstance); } } }
@Test public void when_WebElement_is_injected_then_it_is_first_evaluated_at_first_interaction() { WebElement element = mock(WebElement.class); when(browser.findElement(any(By.class))).thenReturn(element); TPageFragment fragment = new TPageFragment(); getGrapheneEnricher().enrich(fragment); verifyZeroInteractions(browser, element); fragment.getElement().click(); fragment.getElement().click(); // the search for element should be done for every invocation verify(browser, times(2)).findElement(any(By.class)); verify(element, times(2)).click(); verifyNoMoreInteractions(browser, element); }
@Before public void prepare() { rootElement = mock(WebElement.class, new StaleElementAnswer()); webElement = mock(WebElement.class, new StaleElementAnswer()); when(browser.findElement(any(By.class))).thenReturn(rootElement); when(rootElement.findElement(any(By.class))).thenReturn(webElement); page = new Page(); getGrapheneEnricher().enrich(page); }
@Test public void shouldCallAllEnrichers() throws Exception { Mockito.when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(enricher, enricher)); bind(SuiteScoped.class, ServiceLoader.class, serviceLoader); fire(new Before(this, getClass().getMethod("shouldCallAllEnrichers"))); Mockito.verify(enricher, Mockito.times(2)).enrich(this); assertEventFired(BeforeEnrichment.class, 1); assertEventFired(AfterEnrichment.class, 1); } }
@Test public void testMissingNoArgConstructor() { NoArgConstructorTest target = new NoArgConstructorTest(); getGrapheneEnricher().enrich(target); Assert.assertNull(target.pageFragment); }
@Test(expected = PageFragmentInitializationException.class) public void testAbstractType() { AbstractTypeTest target = new AbstractTypeTest(); getGrapheneEnricher().enrich(target); Assert.assertNotNull(target.pageFragment); }
@Test public void shouldCallAllEnrichers() throws Exception { Mockito.when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(enricher, enricher)); bind(SuiteScoped.class, ServiceLoader.class, serviceLoader); fire(new Before(this, getClass().getMethod("shouldCallAllEnrichers"))); Mockito.verify(enricher, Mockito.times(2)).enrich(this); assertEventFired(BeforeEnrichment.class, 1); assertEventFired(AfterEnrichment.class, 1); } }
public void enrichInstances(List<Object> toEnrich) { Collection<TestEnricher> testEnrichers = serviceLoader.get().all(TestEnricher.class); for (Object instance : toEnrich) { enrichmentEvent.fire(new BeforeEnrichment(instance)); for (TestEnricher enricher : testEnrichers) { enricher.enrich(instance); } enrichmentEvent.fire(new AfterEnrichment(instance)); } }
protected <X, T> X execute(Class<X> enrichType, Class<T> contextualType, T type) throws Exception { bind(ApplicationScoped.class, contextualType, type); TestEnricher enricher = new ArquillianResourceTestEnricher(); injector.get().inject(enricher); X test = enrichType.cast(enrichType.newInstance()); enricher.enrich(test); return test; }
public void enrichInstances(List<Object> toEnrich) { Collection<TestEnricher> testEnrichers = serviceLoader.get().all(TestEnricher.class); for (Object instance : toEnrich) { enrichmentEvent.fire(new BeforeEnrichment(instance)); for (TestEnricher enricher : testEnrichers) { enricher.enrich(instance); } enrichmentEvent.fire(new AfterEnrichment(instance)); } }
protected <X, T> X execute(Class<X> enrichType, Class<T> contextualType, T type) throws Exception { bind(ApplicationScoped.class, contextualType, type); TestEnricher enricher = new ArquillianResourceTestEnricher(); injector.get().inject(enricher); X test = enrichType.cast(enrichType.newInstance()); enricher.enrich(test); return test; }
@Test public void generated_webelement_implements_WrapsElement_interface() { TestPage page = new TestPage(); getGrapheneEnricher().enrich(page); assertTrue(page.element instanceof WrapsElement); GrapheneContext.setContextFor(new GrapheneConfiguration(), driver, Default.class); when(driver.findElement(Mockito.any(By.class))).thenReturn(element); WebElement wrappedElement = ((WrapsElement) page.element).getWrappedElement(); GrapheneContext.removeContextFor(Default.class); assertThat(wrappedElement, is(instanceOf(GrapheneElement.class))); assertEquals(element, ((GrapheneElement)wrappedElement).getWrappedElement()); }
public void enrich(@Observes Before event) throws Exception { Object instance = event.getTestInstance(); Method method = event.getTestMethod(); enrichmentEvent.fire(new BeforeEnrichment(instance, method)); Collection<TestEnricher> testEnrichers = serviceLoader.get().all(TestEnricher.class); for (TestEnricher enricher : testEnrichers) { enricher.enrich(instance); } enrichmentEvent.fire(new AfterEnrichment(instance, method)); } }
@Test public void testNoArgConstructor() { thrown.expect(PageObjectInitializationException.class); getGrapheneEnricher().enrich(new NoArgConstructorTest()); }
@Test public void testAbstractType() { thrown.expect(PageObjectInitializationException.class); getGrapheneEnricher().enrich(new AbstractTypeTest()); }
@Test public void testTooManyRoots() { thrown.expect(PageFragmentInitializationException.class); getGrapheneEnricher().enrich(new TooManyRootsTest()); }
@Test public void shouldBeAbleToInjectBaseContext() throws Exception { Mockito.when(resourceProvider.lookup( (ArquillianResource) Mockito.any(), Mockito.argThat(new ClassInjectionAnnotationMatcher()))) .thenReturn(resource); TestEnricher enricher = new ArquillianResourceTestEnricher(); injector.get().inject(enricher); ObjectClass test = new ObjectClass(); enricher.enrich(test); Assert.assertEquals(resource, test.resource); }
@Test public void shouldBeAbleToInjectBaseContext() throws Exception { Mockito.when(resourceProvider.lookup( (ArquillianResource) Mockito.any(), Mockito.argThat(new ClassInjectionAnnotationMatcher()))) .thenReturn(resource); TestEnricher enricher = new ArquillianResourceTestEnricher(); injector.get().inject(enricher); ObjectClass test = new ObjectClass(); enricher.enrich(test); Assert.assertEquals(resource, test.resource); }