public void testCircularDependency() { Injector injector = Guice.createInjector( new AbstractModule() { @Override protected void configure() {} @Provides Foo newFoo(final Bar bar) { return new Foo() { @Override public Bar getBar() { return bar; } @Override public int getI() { return 5; } }; } @Provides Bar newBar(final Foo foo) { return new Bar() { @Override public Foo getFoo() { return foo; } @Override public int getI() { return 10; } }; } }); Foo foo = injector.getInstance(Foo.class); assertEquals(5, foo.getI()); assertEquals(10, foo.getBar().getI()); assertEquals(5, foo.getBar().getFoo().getI()); }
@Test @SpecAssertions({ @SpecAssertion(section = DECLARING_ALTERNATIVE, id = "aa"), @SpecAssertion(section = DECLARING_SELECTED_ALTERNATIVES_BEAN_ARCHIVE, id = "ba"), @SpecAssertion(section = INITIALIZATION, id = "b") }) public void testAlternative() { Assert.assertEquals("barAlternative", foo.getBar().ping()); }
/** issue #1265 */ @Test public void testUnsharedJavaSerialization() { SerializationService ss = new DefaultSerializationServiceBuilder().setEnableSharedObject(false).build(); Data data = ss.toData(new Foo()); Foo foo = ss.toObject(data); Assert.assertFalse("Objects should not be identical!", foo == foo.getBar().getFoo()); }
/** issue #1265 */ @Test public void testSharedJavaSerialization() { SerializationService ss = new DefaultSerializationServiceBuilder().setEnableSharedObject(true).build(); Data data = ss.toData(new Foo()); Foo foo = (Foo) ss.toObject(data); assertTrue("Objects are not identical!", foo == foo.getBar().getFoo()); }
public static void main(String[] args) throws InterruptedException { Foo foo = new Foo(); System.out.println(foo.getBar().getCount()); // 1 System.out.println(foo.getBar().getCount()); // 1 System.out.println(foo.getBaz().getCount()); // 1 System.out.println(foo.getBaz().getCount()); // 1 System.out.println(foo.getBaz().getCount()); // 1 System.out.println(foo.getQux().getCount()); // 1 System.out.println(foo.getQux().getCount()); // 1 System.out.println(foo.getQux().getCount()); // 1 }
public void testSingleComponentBinding() throws Exception { // Model Foo foo = new Foo(); foo.setBar(42); // Inspect AndroidMetawidget metawidget = new AndroidMetawidget(null); metawidget.setToInspect(foo); metawidget.setLayout(new SimpleLayout()); metawidget.setPath(Foo.class.getName() + "/bar"); EditText view = (EditText) metawidget.getChildAt(0); assertEquals("42", view.getText()); view.setText("43"); assertEquals(42, foo.getBar()); metawidget.getWidgetProcessor(SimpleBindingProcessor.class).save(metawidget); assertEquals(43, foo.getBar()); }
public void testBinding() throws Exception { // Model Foo foo = new Foo(); foo.setBar(42); // Inspect AndroidMetawidget metawidget = new AndroidMetawidget(null); metawidget.setToInspect(foo); // Load and save EditText view = metawidget.findViewWithTags("bar"); assertEquals("42", view.getText()); view.setText("43"); assertEquals(42, foo.getBar()); metawidget.getWidgetProcessor(SimpleBindingProcessor.class).save(metawidget); assertEquals(43, foo.getBar()); }
public void testDeepSetting() { Foo foo = new Foo(); foo.setBar(new Bar()); Map<String, Object> context = Ognl.createDefaultContext(foo); Map<String, Object> props = new HashMap(); props.put("bar.title", "i am barbaz"); ognlUtil.setProperties(props, foo, context); assertEquals(foo.getBar().getTitle(), "i am barbaz"); }
public void testFieldCoercion1() { ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("bar", Bar.class); Serializable s = compileSetExpression("bar.assignTest", ctx); Foo foo = new Foo(); executeSetExpression(s, foo, 12); assertEquals("12", foo.getBar().getAssignTest()); foo = new Foo(); executeSetExpression(s, foo, 13); assertEquals("13", foo.getBar().getAssignTest()); OptimizerFactory.setDefaultOptimizer("ASM"); ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("bar", Bar.class); s = compileSetExpression("bar.assignTest", ctx); foo = new Foo(); executeSetExpression(s, foo, 12); assertEquals("12", foo.getBar().getAssignTest()); executeSetExpression(s, foo, 13); assertEquals("13", foo.getBar().getAssignTest()); }
public void testListCoercion() { ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("bar", Bar.class); Serializable s = compileSetExpression("bar.testList[0]", ctx); Foo foo = new Foo(); foo.getBar().getTestList().add(new Integer(-1)); executeSetExpression(s, foo, "12"); assertEquals(12, foo.getBar().getTestList().get(0).intValue()); foo = new Foo(); foo.getBar().getTestList().add(new Integer(-1)); executeSetExpression(s, foo, "13"); assertEquals(13, foo.getBar().getTestList().get(0).intValue()); OptimizerFactory.setDefaultOptimizer("ASM"); ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("bar", Bar.class); s = compileSetExpression("bar.testList[0]", ctx); foo = new Foo(); foo.getBar().getTestList().add(new Integer(-1)); executeSetExpression(s, foo, "12"); assertEquals(12, foo.getBar().getTestList().get(0).intValue()); executeSetExpression(s, foo, "13"); assertEquals(13, foo.getBar().getTestList().get(0).intValue()); }