Update of /cvsroot/mockobjects/no-stone-unturned/src/nostone/tests
In directory usw-pr-cvs1:/tmp/cvs-serv27702/src/nostone/tests
Added Files:
TestHelper.java SearcherTest.java
Log Message:
--- NEW FILE: TestHelper.java ---
package nostone.tests;
import java.awt.*;
public class TestHelper {
public Component depthFirst(Container container, ComponentVisitor visitor) {
Component[] components = container.getComponents();
for (int i = 0; i < components.length; i++) {
Component component = components[i];
Component applied = visitor.apply(component);
if (null != applied) {
return applied;
}
if (component instanceof Container) {
applied = depthFirst((Container) component, visitor);
if (null != applied) {
return applied;
}
}
}
return null;
}
public interface ComponentVisitor {
public Component apply(Component aComponent);
}
}
--- NEW FILE: SearcherTest.java ---
package nostone.tests;
import junit.framework.TestCase;
import nostone.tests.TestHelper;
import nostone.gui.Searcher;
import javax.swing.*;
import java.awt.*;
public class SearcherTest extends TestCase {
public SearcherTest(String name) {
super(name);
}
public void testNoMatchesFound() {
Searcher searcher = new Searcher();
((JButton)findNamedComponent(searcher, "search button")).doClick();
assertEquals("Should be status",
"No entries found",
((JLabel)findNamedComponent(searcher, "status")).getText());
}
private Component findNamedComponent(final Container container, final String name) {
return new TestHelper().depthFirst(container, new TestHelper.ComponentVisitor() {
public Component apply(Component aComponent) {
return name.equals(aComponent.getName()) ? aComponent : null;
}
});
}
}
|