private void _followPath(TreeModel model, int[] path) {
   model.setRowKey(null);
   int lastIndex = path.length - 1;
   for (int i = 0; i < lastIndex; i++) {
     model.setRowIndex(path[i]);
     model.enterContainer();
   }
   model.setRowIndex(path[lastIndex]);
 }
  public void testGetContainerRowKey() throws IntrospectionException {
    TreeModel model = createModel();
    int[] testPath1 = {0, 1};
    _followPath(model, testPath1);
    Object path1 = model.getRowKey();

    int[] testPath2 = {0, 1, 1};
    _followPath(model, testPath2);
    Object path2 = model.getRowKey();

    model.setRowKey(null);
    assertEquals("getContainerRowKey(key)", path1, model.getContainerRowKey(path2));
  }
  public void testGetSetRowKey() throws IntrospectionException {
    TreeModel model = createModel();

    Bean root = _ROOTS.get(0);
    Bean sub = root.getKids().get(1);

    int[] testPath = {0, 1};
    _followPath(model, testPath);
    Object key = model.getRowKey();
    model.setRowKey(null);
    _testTree(model, _ROOTS);

    model.setRowKey(key);
    _testTree(model, sub);
  }
  /**
   * Tests getRowData, isContainer, enterContainer, exitContainer, getRowCount, setRowIndex,
   * getRowIndex, getContainerRowKey
   */
  private void _testTree(TreeModel model, Bean bean) {
    assertEquals("rowData", bean, model.getRowData());

    List<Bean> kids = bean.getKids();
    boolean hasChildren = (kids != null);
    assertEquals("isContainer", hasChildren, model.isContainer());

    if (hasChildren) {
      Object parentKey = model.getRowKey();
      model.enterContainer();
      assertEquals("getContainerRowKey", parentKey, model.getContainerRowKey());

      _testTree(model, kids);
      model.exitContainer();
      assertEquals("rowData after exit", bean, model.getRowData());
      assertEquals("isContainer after exit", hasChildren, model.isContainer());
    }
  }
  /**
   * Tests getRowData, isContainer, enterContainer, exitContainer, getRowCount, setRowIndex,
   * getRowIndex, getContainerRowKey
   */
  private void _testTree(TreeModel model, List<Bean> data) {
    int sz = data.size();
    assertEquals("rowCount", sz, model.getRowCount());
    assertEquals("initial rowIndex", -1, model.getRowIndex());

    if (sz > 0) {
      int oldIndex = model.getRowIndex();
      for (int i = 0; i < sz; i++) {
        Bean child = data.get(i);
        model.setRowIndex(i);
        assertEquals("rowIndex before enterContainer", i, model.getRowIndex());
        _testTree(model, child);
        assertEquals("rowIndex after exitContainer", i, model.getRowIndex());
      }
      model.setRowIndex(oldIndex);
    }
  }