Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to verify contents of JTree that user sees (issue 217) #107

Open
croesch opened this issue Feb 8, 2014 · 1 comment
Open

Way to verify contents of JTree that user sees (issue 217) #107

croesch opened this issue Feb 8, 2014 · 1 comment

Comments

@croesch
Copy link
Collaborator

croesch commented Feb 8, 2014

Issue by Alex Ruiz from Thu, 5 Mar 2009 13:26:20 -0600
Originally opened as http://jira.codehaus.org/browse/FEST-41


From aaronvan80:

Currently there is no way on a JTree to create assertions on the user visible contents of a JTree.

Suggest an enhancement to have a way to verify the user viewable contents of a JTree much like the method, requireContents, with JTables.


Original report: Issue 217 (Google Code)


votes (original issue): 0
watches (original issue): 0

@croesch
Copy link
Collaborator Author

croesch commented Feb 8, 2014

Comment by carcassi from Tue, 16 Jun 2009 14:54:09 -0500


For my own purpouses, I have created for myself the following utility methods:

/**

  • Returns the String representation of the elements currently visible in
  • this fixture's JTree.
  • @param treeFix
  • @return
    */
    public static String[] displayedNodes(JTreeFixture treeFix)
    Unknown macro: { String[] contents = new String[treeFix.component().getRowCount()]; for (int nRow = 0; nRow < treeFix.component().getRowCount(); nRow++) { contents[nRow] = treeFix.component().getPathForRow(nRow).getLastPathComponent().toString(); } return contents; }

/**

  • Returns the String representation of the paths of the elements currently visible in
  • this fixture's JTree.
  • @param treeFix
  • @return
    */
    public static String[] displayedPaths(JTreeFixture treeFix) {
    String[] contents = new String[treeFix.component().getRowCount()];
    for (int nRow = 0; nRow < treeFix.component().getRowCount(); nRow++) {
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Object node : treeFix.component().getPathForRow(nRow).getPath())
    Unknown macro: { if (first) { // Add the first node to the path if and only // the root of the Jtree is visible if (treeFix.component().isRootVisible()) sb.append(node); first = false; } else { sb.append(treeFix.separator()).append(node); } }

    contents[nRow] = sb.toString();
    }
    return contents;
    }

This gives similar functionality as the JListFixture.contents() method. Is this something we could add directly to the JTreeFixture?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant