var Qux = function() { return { thing: function() { console.log('I am a thing!'); }, stuff: function() { console.log('Yikes! That\'s a bunch of stuff'); } }; }; var foo = new Qux(); var bar = new Qux(); var myfunc = function(foo, bar) { if (foo instanceof Qux) foo.thing(); if (bar instanceof Qux) bar.stuff(); }; myfunc(foo,bar);
@Produces @Amazing public String produceString() { return "ok"; }
@Produces public Baz<Baz<Qux>> produceBazBazQux() { return new Baz<Baz<Qux>>(); }
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER) @SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "g") public void testObserver(Foo foo) throws Exception { assertNotNull(foo); getCurrentManager().fireEvent(new Qux(null)); assertNotNull(foo.getT1BazEvent()); assertEquals(foo.getT1ObserverInjectionPoint(), "ok"); }
@SuppressWarnings("serial") @Test @SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "g") public void testObserverResolution() throws Exception { Set<ObserverMethod<? super Qux>> observerMethods = getCurrentManager().resolveObserverMethods(new Qux(null)); assertEquals(observerMethods.size(), 1); ObserverMethod<? super Qux> observerMethod = observerMethods.iterator().next(); assertEquals(observerMethod.getBeanClass(), Foo.class); assertEquals(observerMethod.getObservedType(), new TypeLiteral<Baz<String>>() { }.getType()); }
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER) @SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "f") public void testInjectionPoint(Foo foo) throws Exception { assertNotNull(foo); assertNotNull(foo.getBaz()); assertNotNull(foo.getT1Array()); assertNotNull(foo.getT2BazList()); }
@SuppressWarnings("serial") @Test @SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "f") public void testInjectionPointDefinition() throws Exception { Bean<Foo> fooBean = getUniqueBean(Foo.class); Set<InjectionPoint> injectionPoints = fooBean.getInjectionPoints(); // Baz<T1> baz, T1 t1, Baz<List<T2>> t2BazList, T1[] t1Array assertEquals(injectionPoints.size(), 4); for (InjectionPoint injectionPoint : injectionPoints) { if ("baz".equals(injectionPoint.getMember().getName())) { assertEquals(injectionPoint.getType(), new TypeLiteral<Baz<String>>() { }.getType()); } else if ("t1".equals(injectionPoint.getMember().getName())) { assertEquals(injectionPoint.getType(), String.class); } else if ("t2BazList".equals(injectionPoint.getMember().getName())) { assertEquals(injectionPoint.getType(), new TypeLiteral<Baz<List<Qux>>>() { }.getType()); } else if ("setT1Array".equals(injectionPoint.getMember().getName())) { // Initializer IP assertEquals(injectionPoint.getType(), String[].class); } else { fail("Unexpected injection point"); } } }
case 0: return new Foo(); case 1: return new Bar(); case 2: return new Qux();
public void observeBaz(@Observes Baz<T1> baz, @Amazing T1 t1) { t1BazEvent = baz; t1ObserverInjectionPoint = t1; }
@Test public void testMyTest() { // ... Foo<Bar> mockFooBar = mockFoo(); when(mockFooBar.getValue).thenReturn(new Bar()); Foo<Baz> mockFooBaz = mockFoo(); when(mockFooBaz.getValue).thenReturn(new Baz()); Foo<Qux> mockFooQux = mockFoo(); when(mockFooQux.getValue).thenReturn(new Qux()); // ... } @SuppressWarnings("unchecked") // still needed :( but just once :) private <T> Foo<T> mockFoo() { return mock(Foo.class); }
@Amazing private T1 t1;