Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@hashrock
CreatedOctober 2, 2020 10:05
    • Star(0)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist

    Select an option

    Save hashrock/26afb842db35eb03699acf735a692f2e to your computer and use it in GitHub Desktop.
    AssertJ-Swing wait example
    packagehashrock.study.swing;
    importorg.assertj.swing.core.GenericTypeMatcher;
    importorg.assertj.swing.edt.GuiActionRunner;
    importorg.assertj.swing.fixture.FrameFixture;
    importorg.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase;
    importorg.assertj.swing.timing.Condition;
    importorg.junit.Test;
    importstaticorg.assertj.swing.timing.Pause.pause;
    importstaticorg.assertj.swing.timing.Timeout.timeout;
    importjavax.swing.*;
    publicclassMainTestextendsAssertJSwingJUnitTestCase {
    privateFrameFixturewindow;
    @Override
    protectedvoidonSetUp()throwsException {
    MainFrameframe =GuiActionRunner.execute(() ->newMainFrame());
    window =newFrameFixture(robot(),frame);
    window.show();
    }
    @Test
    publicvoidshouldTestSwing()throwsInterruptedException {
    window.label("output").requireText("TODO");
    GenericTypeMatcher<JButton>textMatcher =newGenericTypeMatcher<JButton>(JButton.class,false) {
    @OverrideprotectedbooleanisMatching(JButtonbutton) {
    return"ok".equals(button.getName());
    }
    };
    JButtontarget =window.button(textMatcher).target();
    pause(newCondition("OK button to be enabled") {
    publicbooleantest() {
    returntarget.isVisible();
    }
    },timeout(10000));
    window.button("ok").click();
    pause(newCondition("Label Timeout") {
    publicbooleantest() {
    returnwindow.label("output").text().equals("Pressed");
    }
    },timeout(10000));
    window.label("output").requireText("Pressed");
    }
    }
    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp