public void testNoGetterSetterType() throws Exception {

    AndroidMetawidget metawidget = new AndroidMetawidget(null);
    metawidget.setInspector(
        new PropertyTypeInspector(
            new BaseObjectInspectorConfig()
                .setPropertyStyle(
                    new JavaBeanPropertyStyle(
                        new JavaBeanPropertyStyleConfig().setSupportPublicFields(true)))));
    metawidget.setToInspect(new NoGetSetFoo());

    try {
      metawidget.getChildAt(0);
      fail();
    } catch (Exception e) {
      assertTrue(e.getCause().getMessage().startsWith("Unable to get 'bar'"));
    }
  }
  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 testTableLayout() {

    AndroidMetawidget androidMetawidget = new AndroidMetawidget(null);

    Stub stub = new Stub(null);
    stub.setTag("stubMe");
    androidMetawidget.addView(stub);

    Facet buttonsFacet = new Facet(null);
    buttonsFacet.setName("buttons");
    androidMetawidget.addView(buttonsFacet);

    Foo foo = new Foo();
    foo.nestedFoo = new Foo();
    androidMetawidget.setToInspect(foo);

    android.widget.TableLayout tableLayout =
        (android.widget.TableLayout) androidMetawidget.getChildAt(0);
    TableRow tableRow = (TableRow) tableLayout.getChildAt(0);
    assertEquals("Bar: ", ((TextView) tableRow.getChildAt(0)).getText());
    assertTrue(tableRow.getChildAt(1) instanceof EditText);
    tableRow = (TableRow) tableLayout.getChildAt(1);
    assertEquals("Baz: ", ((TextView) tableRow.getChildAt(0)).getText());
    assertTrue(tableRow.getChildAt(1) instanceof CheckBox);

    tableRow = (TableRow) tableLayout.getChildAt(2);
    assertEquals("Foo Section", ((TextView) tableRow.getChildAt(0)).getText());
    tableRow = (TableRow) tableLayout.getChildAt(3);
    android.widget.LinearLayout linearLayout = (android.widget.LinearLayout) tableRow.getChildAt(0);
    tableLayout = (android.widget.TableLayout) linearLayout.getChildAt(0);
    tableRow = (TableRow) tableLayout.getChildAt(0);
    assertEquals("Abc: ", ((TextView) tableRow.getChildAt(0)).getText());
    assertTrue(tableRow.getChildAt(1) instanceof Spinner);
    tableRow = (TableRow) tableLayout.getChildAt(1);
    assertEquals("Nested foo: ", ((TextView) tableRow.getChildAt(0)).getText());
    assertTrue(buttonsFacet == androidMetawidget.getChildAt(1));
    assertTrue(2 == androidMetawidget.getChildCount());

    // nestedFoo

    AndroidMetawidget nestedMetawidget = (AndroidMetawidget) tableRow.getChildAt(1);
    tableLayout = (android.widget.TableLayout) nestedMetawidget.getChildAt(0);
    tableRow = (TableRow) tableLayout.getChildAt(0);
    assertEquals("Bar: ", ((TextView) tableRow.getChildAt(0)).getText());
    assertTrue(tableRow.getChildAt(1) instanceof EditText);
    tableRow = (TableRow) tableLayout.getChildAt(1);
    assertEquals("Baz: ", ((TextView) tableRow.getChildAt(0)).getText());
    assertTrue(tableRow.getChildAt(1) instanceof CheckBox);

    tableRow = (TableRow) tableLayout.getChildAt(2);
    assertEquals("Foo Section", ((TextView) tableRow.getChildAt(0)).getText());
    tableRow = (TableRow) tableLayout.getChildAt(3);
    linearLayout = (android.widget.LinearLayout) tableRow.getChildAt(0);
    tableLayout = (android.widget.TableLayout) linearLayout.getChildAt(0);
    tableRow = (TableRow) tableLayout.getChildAt(0);
    assertEquals("Abc: ", ((TextView) tableRow.getChildAt(0)).getText());
    AdapterView<?> adapterView = (Spinner) tableRow.getChildAt(1);
    assertTrue(tableRow.getChildAt(1) instanceof Spinner);
    tableRow = (TableRow) tableLayout.getChildAt(1);
    assertEquals("Stub me: ", ((TextView) tableRow.getChildAt(0)).getText());
    assertTrue(tableRow.getChildAt(1) instanceof EditText);
    tableRow = (TableRow) tableLayout.getChildAt(2);
    assertEquals("Nested foo: ", ((TextView) tableRow.getChildAt(0)).getText());
    assertTrue(tableRow.getChildAt(1) instanceof AndroidMetawidget);
    assertTrue(3 == tableLayout.getChildCount());

    AndroidMetawidget nestedNestedMetawidget = (AndroidMetawidget) tableRow.getChildAt(1);
    assertTrue(1 == nestedNestedMetawidget.getChildCount());

    // (spacer)

    assertTrue(null == ((TextView) nestedNestedMetawidget.getChildAt(0)).getText());
    assertTrue(1 == nestedNestedMetawidget.getChildCount());

    // Get/set nested value

    assertTrue(null == adapterView.getSelectedItem());
    assertTrue(null == adapterView.getAdapter().getItem(0));
    assertEquals("one", adapterView.getAdapter().getItem(1));
    assertEquals("two", adapterView.getAdapter().getItem(2));
    assertEquals("three", adapterView.getAdapter().getItem(3));
    androidMetawidget.setValue("two", "nestedFoo", "abc");
    assertEquals("two", adapterView.getSelectedItem());
    assertEquals("two", androidMetawidget.getValue("nestedFoo", "abc"));
  }