Beispiel #1
0
  @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());
  }
Beispiel #2
0
  @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());
  }
Beispiel #3
0
  @Test
  public void getTargetNotBoundFails() {
    LazyModel<String> model = model(from(String.class));

    try {
      model.getObject();

      fail();
    } catch (Exception ex) {
    }
  }
Beispiel #4
0
  @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());
  }
Beispiel #5
0
  @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());
  }
Beispiel #6
0
  @Test
  public void noBindFails() {
    LazyModel<B> model = model(from(A.class).getB());

    try {
      model.getObject();

      fail();
    } catch (Exception ex) {
    }
  }
Beispiel #7
0
  @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());
  }
Beispiel #8
0
  @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());
  }
Beispiel #9
0
  @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());
  }
Beispiel #10
0
  @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());
  }
Beispiel #11
0
  @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());
  }
Beispiel #12
0
  @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());
  }
Beispiel #13
0
  @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());
  }
Beispiel #14
0
  @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());
  }
Beispiel #15
0
  @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());
  }
Beispiel #16
0
  @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());
  }
Beispiel #17
0
  @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());
  }
Beispiel #18
0
  @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());
  }
Beispiel #19
0
  @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());
  }
Beispiel #20
0
  @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());
  }
Beispiel #21
0
  @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());
  }
Beispiel #22
0
  @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());
  }