FileDocCategorySizeDatePackage
TestPersonEditorPanel.javaAPI DocExample2872Sat Aug 24 11:24:16 BST 2002com.oreilly.javaxp.junit

TestPersonEditorPanel

public class TestPersonEditorPanel extends SwingTestCase

Fields Summary
private PersonEditorPanel
emptyPanel
private PersonEditorPanel
tannerPanel
private Person
tanner
Constructors Summary
public TestPersonEditorPanel(String name)

        super(name);
    
Methods Summary
protected voidsetUp()

        this.emptyPanel = new PersonEditorPanel();

        this.tanner = new Person("Tanner", "Burke");
        this.tannerPanel = new PersonEditorPanel();
        this.tannerPanel.setPerson(this.tanner);

        getTestFrame().getContentPane().add(this.tannerPanel, BorderLayout.CENTER);
        getTestFrame().pack();
        getTestFrame().show();
    
public static junit.framework.Testsuite()

        return new RepeatedTest(new TestSuite(TestPersonEditorPanel.class), 1000);
    
public voidtestEnabledStateAfterSettingPerson()

        assertTrue("First name field should be enabled",
                this.tannerPanel.getFirstNameField().isEnabled());
        assertTrue("Last name field should be enabled",
                this.tannerPanel.getLastNameField().isEnabled());
    
public voidtestFirstName()

        assertEquals("First name", "",
                this.emptyPanel.getFirstNameField().getText());
        assertEquals("First name", this.tanner.getFirstName(),
                this.tannerPanel.getFirstNameField().getText());
    
public voidtestLastName()

        assertEquals("Last name", "",
                this.emptyPanel.getLastNameField().getText());
        assertEquals("Last name", this.tanner.getLastName(),
                this.tannerPanel.getLastNameField().getText());
    
public voidtestTabOrder()

        JTextField firstNameField = this.tannerPanel.getFirstNameField();

        // make sure the first name field has focus
        while (!firstNameField.hasFocus()) {
            getTestFrame().toFront();
            firstNameField.requestFocusInWindow();
        }

        // simulate the user hitting tab
        firstNameField.transferFocus();

        // wait until the transferFocus() method is processed
        waitForSwing();

        // ensure that the last name field now has focus
        JTextField lastNameField = this.tannerPanel.getLastNameField();
        assertTrue("Expected last name field to have focus",
                lastNameField.hasFocus());
    
public voidtestTextFieldsAreInitiallyDisabled()

        assertTrue("First name field should be disabled",
                !this.emptyPanel.getFirstNameField().isEnabled());
        assertTrue("Last name field should be disabled",
                !this.emptyPanel.getLastNameField().isEnabled());