Exemplo n.º 1
0
  @Test
  public void shouldDemonstrateDeeplyNestedMapProperties() {
    HashMap<String, String> map = new HashMap<String, String>();
    MetaObject metaMap = SystemMetaObject.forObject(map);

    assertTrue(metaMap.hasSetter("id"));
    assertTrue(metaMap.hasSetter("name.first"));
    assertTrue(metaMap.hasSetter("address.street"));

    assertFalse(metaMap.hasGetter("id"));
    assertFalse(metaMap.hasGetter("name.first"));
    assertFalse(metaMap.hasGetter("address.street"));

    metaMap.setValue("id", "100");
    metaMap.setValue("name.first", "Clinton");
    metaMap.setValue("name.last", "Begin");
    metaMap.setValue("address.street", "1 Some Street");
    metaMap.setValue("address.city", "This City");
    metaMap.setValue("address.province", "A Province");
    metaMap.setValue("address.postal_code", "1A3 4B6");

    assertTrue(metaMap.hasGetter("id"));
    assertTrue(metaMap.hasGetter("name.first"));
    assertTrue(metaMap.hasGetter("address.street"));

    assertEquals(3, metaMap.getGetterNames().length);
    assertEquals(3, metaMap.getSetterNames().length);

    Map<String, String> name = (Map<String, String>) metaMap.getValue("name");
    Map<String, String> address = (Map<String, String>) metaMap.getValue("address");

    assertEquals("Clinton", name.get("first"));
    assertEquals("1 Some Street", address.get("street"));
  }
Exemplo n.º 2
0
 @Test
 public void shouldVerifyHasWriteablePropertiesReturnedByGetWriteablePropertyNames() {
   MetaObject object = SystemMetaObject.forObject(new Author());
   for (String writeable : object.getSetterNames()) {
     assertTrue(object.hasSetter(writeable));
   }
 }
Exemplo n.º 3
0
 @Test
 public void shouldVerifyPropertyTypes() {
   MetaObject object = SystemMetaObject.forObject(new Author());
   assertEquals(6, object.getSetterNames().length);
   assertEquals(int.class, object.getGetterType("id"));
   assertEquals(String.class, object.getGetterType("username"));
   assertEquals(String.class, object.getGetterType("password"));
   assertEquals(String.class, object.getGetterType("email"));
   assertEquals(String.class, object.getGetterType("bio"));
   assertEquals(Section.class, object.getGetterType("favouriteSection"));
 }
Exemplo n.º 4
0
 @Test
 public void shouldGetWriteablePropertyNames() {
   RichType rich = new RichType();
   MetaObject meta = SystemMetaObject.forObject(rich);
   String[] writeables = meta.getSetterNames();
   assertEquals(5, writeables.length);
   for (String writeable : writeables) {
     assertTrue(meta.hasSetter(writeable));
     assertTrue(meta.hasSetter("richType." + writeable));
   }
   assertTrue(meta.hasSetter("richType"));
 }