@Test public void bindToObject() { final A a = new A(); a.b = new B(); LazyModel<B> model = model(from(A.class).getB()).bind(a); assertEquals(B.class, model.getObjectClass()); assertEquals("b", model.getPath()); assertEquals(a.b, model.getObject()); }
@Test public void getTarget() { A a = new A(); LazyModel<A> model = model(from(a)); assertEquals(A.class, model.getObjectClass()); assertEquals("", model.getPath()); assertEquals(a, model.getObject()); }
@Test public void getTargetNotBoundFails() { LazyModel<String> model = model(from(String.class)); try { model.getObject(); fail(); } catch (Exception ex) { } }
@Test public void getOutOfBoundsFromGenericList() { B b = new B(); LazyModel<C> model = model(from(b).getCs().get(0)); assertEquals(C.class, model.getObjectClass()); assertEquals("cs.get(i)", model.getPath()); assertEquals(null, model.getObject()); }
@Test public void getIntFromNull() { A a = new A(); LazyModel<Character> model = model(from(a).getB().getCharacter()); assertEquals(Character.TYPE, model.getObjectClass()); assertEquals("b.character", model.getPath()); assertEquals(null, model.getObject()); }
@Test public void noBindFails() { LazyModel<B> model = model(from(A.class).getB()); try { model.getObject(); fail(); } catch (Exception ex) { } }
@Test public void getFromPrivateConstructor() { final A a = new A(); a.p = P.P1; LazyModel<String> model = model(from(a).getP().getString()); assertEquals(String.class, model.getObjectClass()); assertEquals("p.string", model.getPath()); assertEquals(a.p.getString(), model.getObject()); }
@Test public void getFinal() { final A a = new A(); a.f = new F(); LazyModel<F> model = model(from(a).getF()); assertEquals(F.class, model.getObjectClass()); assertEquals("f", model.getPath()); assertEquals(a.f, model.getObject()); }
@Test public void getRawList() { B b = new B(); b.cs.add(new C()); LazyModel<Object> model = model(from(b).getRs().get(0)); assertEquals(Object.class, model.getObjectClass()); assertEquals("rs.get(i)", model.getPath()); assertEquals(b.cs.get(0), model.getObject()); }
@Test public void getEnum() { final A a = new A(); a.e = E.E1; LazyModel<E> model = model(from(a).getE()); assertEquals(E.class, model.getObjectClass()); assertEquals("e", model.getPath()); assertEquals(a.e, model.getObject()); }
@Test public void getInherited() { final A a = new A(); a.b = new B(); a.b.d = new D(); LazyModel<String> model = model(from(a).getB().getD().getString()); assertEquals(String.class, model.getObjectClass()); assertEquals("b.d.string", model.getPath()); assertEquals(a.b.d.string, model.getObject()); }
@Test public void getBoolean() { A a = new A(); a.bool = true; LazyModel<Boolean> model = model(from(a).isBool()); assertEquals(Boolean.TYPE, model.getObjectClass()); assertEquals("bool", model.getPath()); assertEquals(Boolean.TRUE, model.getObject()); }
@Test public void getObject() { A a = new A(); a.b = new B(); LazyModel<B> model = model(from(a).getB()); assertEquals(B.class, model.getObjectClass()); assertEquals("b", model.getPath()); assertEquals(a.b, model.getObject()); }
@Test public void getInt() { A a = new A(); a.integer = 42; LazyModel<Integer> model = model(from(a).getInteger()); assertEquals(Integer.TYPE, model.getObjectClass()); assertEquals("integer", model.getPath()); assertEquals(Integer.valueOf(42), model.getObject()); }
@Test public void getValueFromGenericMap() { A a = new A(); a.b = new B(); a.b.strings.put("key", "value"); LazyModel<String> model = model(from(a).getB().getStrings().get("key")); assertEquals(String.class, model.getObjectClass()); assertEquals("b.strings.get(O)", model.getPath()); assertEquals("value", model.getObject()); }
@Test public void getWithNestedLazyModel() { A a = new A(); a.integer = 0; B b = new B(); C c = new C(); b.cs.add(c); LazyModel<C> model = model(from(b).getC(from(a).getInteger())); assertEquals(C.class, model.getObjectClass()); assertEquals("getC(i)", model.getPath()); assertEquals(c, model.getObject()); }
@Test public void getObjectFromGenericList() { A a = new A(); a.b = new B(); C c = new C(); a.b.cs.add(c); c.string = "string"; LazyModel<C> model = model(from(a).getB().getCs().get(0)); assertEquals(C.class, model.getObjectClass()); assertEquals("b.cs.get(i)", model.getPath()); assertEquals(c, model.getObject()); }
@Test public void getObjectFromEntryFromGenericList() { A a = new A(); a.b = new B(); C c = new C(); a.b.cs.add(c); c.string = "string"; LazyModel<String> model = model(from(a).getB().getC(0).getString()); assertEquals(String.class, model.getObjectClass()); assertEquals("b.getC(i).string", model.getPath()); assertEquals("string", model.getObject()); }
@Test public void getObjectFromObjectClassAwareModel() { A a = new A(); a.b = new B(); C c = new C(); a.b.cs.add(c); PropertyModel<B> target = new PropertyModel<B>(a, "b"); LazyModel<C> model = model(from(target).getC(0)); assertEquals(C.class, model.getObjectClass()); assertEquals("getC(i)", model.getPath()); assertEquals(a.b.cs.get(0), model.getObject()); }
@Test public void bindToGenericModel() { final A a = new A(); a.b = new B(); LazyModel<B> model = model(from(A.class).getB()) .bind( new AbstractReadOnlyModel<A>() { @Override public A getObject() { return a; } }); assertEquals(B.class, model.getObjectClass()); assertEquals("b", model.getPath()); assertEquals(a.b, model.getObject()); }
@Test public void getEntryFromGenericList() { final List<C> cs = new ArrayList<C>(); C c = new C(); cs.add(c); IModel<List<C>> target = new AbstractReadOnlyModel<List<C>>() { @Override public List<C> getObject() { return cs; } }; LazyModel<C> model = model(from(target).get(0)); assertEquals(C.class, model.getObjectClass()); assertEquals("get(i)", model.getPath()); assertEquals(c, model.getObject()); }
@Test public void getObjectFromGenericModel() { final A a = new A(); a.b = new B(); C c = new C(); a.b.cs.add(c); IModel<A> target = new AbstractReadOnlyModel<A>() { @Override public A getObject() { return a; } }; LazyModel<C> model = model(from(target).getB().getC(0)); assertEquals(C.class, model.getObjectClass()); assertEquals("b.getC(i)", model.getPath()); assertEquals(a.b.cs.get(0), model.getObject()); }