How to use matcher with JTableDriver.hasRow()

44 views
Skip to first unread message

niels

unread,
Jul 23, 2010, 11:19:00 AM7/23/10
to windowlicker-users
Hello!

How can I test, if a checkbox is checked in a cell?

I have a row with the content ---> Boolean.false | "LABEL1" |
"LABEL2"

The following check passes:

JTableDriver table = new JTableDriver(this, JTable.class,
named(fieldName));
table.hasRow(IterableComponentsMatcher.matching(any(JCheckBox.class),

withLabelText("LABEL1"),

withLabelText("LABEL2")));

But how do I test the state of the checkbox?

Thanks
Niels

niels

unread,
Sep 20, 2010, 6:28:01 AM9/20/10
to windowlicker-users
I solved my problem by creating a CheckBoxSelectionMatcher (Thanks to
Dovile):


public class CheckBoxSelectionMatcher extends
TypeSafeMatcher<JCheckBox> {
private final boolean shouldBeSelected;

public CheckBoxSelectionMatcher(final boolean expectedState) {
shouldBeSelected = expectedState;
}

public boolean matchesSafely(final JCheckBox item) {
return item.isSelected() == shouldBeSelected;
}

@Override
public void describeTo(final Description description) {
description.appendText("selected");
}

public static CheckBoxSelectionMatcher withSelectState(boolean
state) {
return new CheckBoxSelectionMatcher(state);
}
}




and performing the test:


table.hasRow(IterableComponentsMatcher.matching(withSelectState(group.isSelected()),
withLabelText(group.getName()),
withLabelText(group.getDescription())));


thanks
Niels
Reply all
Reply to author
Forward
0 new messages