summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorparentej <parentej@google.com>2017-01-20 15:15:17 +0000
committerparentej <parentej@google.com>2017-01-24 09:59:50 +0000
commit576b0a3571e0626ae66576d959ebc3dcc378130e (patch)
tree3235434207663d67f18f22f2f3456d5f7cc8eb13
parentf3df355d66432d24b466faf1ccc4cfd22f690fbc (diff)
downloadswing-testing-576b0a3571e0626ae66576d959ebc3dcc378130e.tar.gz
Fail unit test if it leaves windows open
After each test is run, check that all Frames were closed. If a frame is found, close it and fail the test Test: Run all unit tests. All tests modified on this CL were leaking a Window/Dialog Change-Id: I38c8f3856598776e1d002ddeea85a728e1a04399
-rwxr-xr-x[-rw-r--r--]fest-swing/src/test/java/org/fest/swing/core/ContainerFocusOwnerFinder_focusOwnerOf_Test.java11
-rwxr-xr-x[-rw-r--r--]fest-swing/src/test/java/org/fest/swing/core/matcher/DialogMatcher_matches_byTitleAndShowing_Test.java17
-rwxr-xr-x[-rw-r--r--]fest-swing/src/test/java/org/fest/swing/core/matcher/JButtonMatcher_matches_byTextAndShowing_Test.java25
-rwxr-xr-x[-rw-r--r--]fest-swing/src/test/java/org/fest/swing/core/matcher/JLabelMatcher_matches_byTextAndShowing_Test.java25
-rwxr-xr-x[-rw-r--r--]fest-swing/src/test/java/org/fest/swing/core/matcher/JTextComponentMatcher_matches_byTextAndShowing_Test.java26
-rwxr-xr-x[-rw-r--r--]fest-swing/src/test/java/org/fest/swing/driver/JComboBoxDropDownListFinder_findDropDownList_Test.java19
-rwxr-xr-x[-rw-r--r--]fest-swing/src/test/java/org/fest/swing/fixture/Bug279_firstCharInJComboBoxMissing_Test.java5
-rwxr-xr-xfest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withName_Test.java11
-rwxr-xr-x[-rw-r--r--]fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withRobotAndName_Test.java11
-rwxr-xr-xfest-swing/src/test/java/org/fest/swing/test/core/EDTSafeTestCase.java20
10 files changed, 113 insertions, 57 deletions
diff --git a/fest-swing/src/test/java/org/fest/swing/core/ContainerFocusOwnerFinder_focusOwnerOf_Test.java b/fest-swing/src/test/java/org/fest/swing/core/ContainerFocusOwnerFinder_focusOwnerOf_Test.java
index 21670edc..03a94f10 100644..100755
--- a/fest-swing/src/test/java/org/fest/swing/core/ContainerFocusOwnerFinder_focusOwnerOf_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/core/ContainerFocusOwnerFinder_focusOwnerOf_Test.java
@@ -85,9 +85,14 @@ public class ContainerFocusOwnerFinder_focusOwnerOf_Test extends SequentialEDTSa
public void should_return_null_if_top_window_or_owned_windows_do_not_have_focus_owner() {
window.display();
MyWindow window2 = MyWindow.createNew();
- window2.display();
- giveFocusAndWaitTillIsFocused(window2.textBox);
- assertThat(focusOwnerOf(window)).isNull();
+ try {
+ window2.display();
+ giveFocusAndWaitTillIsFocused(window2.textBox);
+ assertThat(focusOwnerOf(window)).isNull();
+ }
+ finally {
+ window2.destroy();
+ }
}
@RunsInEDT
diff --git a/fest-swing/src/test/java/org/fest/swing/core/matcher/DialogMatcher_matches_byTitleAndShowing_Test.java b/fest-swing/src/test/java/org/fest/swing/core/matcher/DialogMatcher_matches_byTitleAndShowing_Test.java
index 193c9c9e..a5a9e2a6 100644..100755
--- a/fest-swing/src/test/java/org/fest/swing/core/matcher/DialogMatcher_matches_byTitleAndShowing_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/core/matcher/DialogMatcher_matches_byTitleAndShowing_Test.java
@@ -31,10 +31,19 @@ import org.junit.Test;
* @author Yvonne Wang
*/
public class DialogMatcher_matches_byTitleAndShowing_Test extends SequentialEDTSafeTestCase {
+ private JDialog dialog;
+
+ @Override
+ protected void onTearDown() {
+ if (dialog != null) {
+ dialog.getOwner().dispose();
+ }
+ }
+
@Test
public void should_return_true_if_Dialog_is_showing_and_title_is_equal_to_expected() {
String title = "Hello";
- JDialog dialog = dialog().withTitle(title).createAndShow();
+ dialog = dialog().withTitle(title).createAndShow();
DialogMatcher matcher = DialogMatcher.withTitle(title).andShowing();
assertThat(matcher.matches(dialog)).isTrue();
}
@@ -43,14 +52,14 @@ public class DialogMatcher_matches_byTitleAndShowing_Test extends SequentialEDTS
public void should_return_false_if_Dialog_is_not_showing_and_title_is_equal_to_expected() {
String title = "Hello";
DialogMatcher matcher = DialogMatcher.withTitle(title).andShowing();
- JDialog dialog = dialog().withTitle(title).createNew();
+ dialog = dialog().withTitle(title).createNew();
assertThat(matcher.matches(dialog)).isFalse();
}
@Test
public void should_return_false_if_Dialog_is_showing_and_title_is_not_equal_to_expected() {
TestWindow window = TestWindow.createAndShowNewWindow(DialogMatcher.class);
- TestDialog dialog = TestDialog.createAndShowNewDialog(window);
+ dialog = TestDialog.createAndShowNewDialog(window);
DialogMatcher matcher = DialogMatcher.withTitle("Hello").andShowing();
assertThat(matcher.matches(dialog)).isFalse();
}
@@ -58,7 +67,7 @@ public class DialogMatcher_matches_byTitleAndShowing_Test extends SequentialEDTS
@Test
public void should_return_false_if_Dialog_is_not_showing_and_title_is_not_equal_to_expected() {
DialogMatcher matcher = DialogMatcher.withTitle("Hello").andShowing();
- JDialog dialog = dialog().withTitle("Bye").createNew();
+ dialog = dialog().withTitle("Bye").createNew();
assertThat(matcher.matches(dialog)).isFalse();
}
}
diff --git a/fest-swing/src/test/java/org/fest/swing/core/matcher/JButtonMatcher_matches_byTextAndShowing_Test.java b/fest-swing/src/test/java/org/fest/swing/core/matcher/JButtonMatcher_matches_byTextAndShowing_Test.java
index fffed5d2..699d14e8 100644..100755
--- a/fest-swing/src/test/java/org/fest/swing/core/matcher/JButtonMatcher_matches_byTextAndShowing_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/core/matcher/JButtonMatcher_matches_byTextAndShowing_Test.java
@@ -36,8 +36,13 @@ public class JButtonMatcher_matches_byTextAndShowing_Test extends SequentialEDTS
@Test
public void should_return_true_if_JButton_is_showing_and_text_is_equal_to_expected() {
MyWindow window = MyWindow.createAndShow();
- JButtonMatcher matcher = JButtonMatcher.withText("Hello").andShowing();
- assertThat(matcher.matches(window.button)).isTrue();
+ try {
+ JButtonMatcher matcher = JButtonMatcher.withText("Hello").andShowing();
+ assertThat(matcher.matches(window.button)).isTrue();
+ }
+ finally {
+ window.destroy();
+ }
}
@Test
@@ -50,8 +55,13 @@ public class JButtonMatcher_matches_byTextAndShowing_Test extends SequentialEDTS
@Test
public void should_return_false_if_JButton_is_showing_and_text_is_not_equal_to_expected() {
MyWindow window = MyWindow.createAndShow();
- JButtonMatcher matcher = JButtonMatcher.withText("Bye").andShowing();
- assertThat(matcher.matches(window.button)).isFalse();
+ try {
+ JButtonMatcher matcher = JButtonMatcher.withText("Bye").andShowing();
+ assertThat(matcher.matches(window.button)).isFalse();
+ }
+ finally {
+ window.destroy();
+ }
}
@Test
@@ -64,12 +74,7 @@ public class JButtonMatcher_matches_byTextAndShowing_Test extends SequentialEDTS
private static class MyWindow extends TestWindow {
@RunsInEDT
static MyWindow createAndShow() {
- return execute(new GuiQuery<MyWindow>() {
- @Override
- protected MyWindow executeInEDT() {
- return display(new MyWindow());
- }
- });
+ return GuiQuery.get(() -> display(new MyWindow()));
}
final JButton button = new JButton("Hello");
diff --git a/fest-swing/src/test/java/org/fest/swing/core/matcher/JLabelMatcher_matches_byTextAndShowing_Test.java b/fest-swing/src/test/java/org/fest/swing/core/matcher/JLabelMatcher_matches_byTextAndShowing_Test.java
index 9e8a2906..18d6a87a 100644..100755
--- a/fest-swing/src/test/java/org/fest/swing/core/matcher/JLabelMatcher_matches_byTextAndShowing_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/core/matcher/JLabelMatcher_matches_byTextAndShowing_Test.java
@@ -35,8 +35,13 @@ public class JLabelMatcher_matches_byTextAndShowing_Test extends SequentialEDTSa
@Test
public void should_return_true_if_JLabel_is_showing_and_text_is_equal_to_expected() {
MyWindow window = MyWindow.createAndShow();
- JLabelMatcher matcher = JLabelMatcher.withText("Hello").andShowing();
- assertThat(matcher.matches(window.label)).isTrue();
+ try {
+ JLabelMatcher matcher = JLabelMatcher.withText("Hello").andShowing();
+ assertThat(matcher.matches(window.label)).isTrue();
+ }
+ finally {
+ window.destroy();
+ }
}
@Test
@@ -49,8 +54,13 @@ public class JLabelMatcher_matches_byTextAndShowing_Test extends SequentialEDTSa
@Test
public void should_return_false_if_JLabel_is_showing_and_text_is_not_equal_to_expected() {
MyWindow window = MyWindow.createAndShow();
- JLabelMatcher matcher = JLabelMatcher.withText("Bye").andShowing();
- assertThat(matcher.matches(window.label)).isFalse();
+ try {
+ JLabelMatcher matcher = JLabelMatcher.withText("Bye").andShowing();
+ assertThat(matcher.matches(window.label)).isFalse();
+ }
+ finally {
+ window.destroy();
+ }
}
@Test
@@ -63,12 +73,7 @@ public class JLabelMatcher_matches_byTextAndShowing_Test extends SequentialEDTSa
private static class MyWindow extends TestWindow {
@RunsInEDT
static MyWindow createAndShow() {
- return execute(new GuiQuery<MyWindow>() {
- @Override
- protected MyWindow executeInEDT() {
- return display(new MyWindow());
- }
- });
+ return GuiQuery.get(() -> display(new MyWindow()));
}
final JLabel label = new JLabel("Hello");
diff --git a/fest-swing/src/test/java/org/fest/swing/core/matcher/JTextComponentMatcher_matches_byTextAndShowing_Test.java b/fest-swing/src/test/java/org/fest/swing/core/matcher/JTextComponentMatcher_matches_byTextAndShowing_Test.java
index e7b4477a..62cc0b15 100644..100755
--- a/fest-swing/src/test/java/org/fest/swing/core/matcher/JTextComponentMatcher_matches_byTextAndShowing_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/core/matcher/JTextComponentMatcher_matches_byTextAndShowing_Test.java
@@ -15,7 +15,6 @@
package org.fest.swing.core.matcher;
import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.swing.edt.GuiActionRunner.execute;
import static org.fest.swing.test.builder.JTextFields.textField;
import javax.swing.JTextField;
@@ -36,8 +35,13 @@ public class JTextComponentMatcher_matches_byTextAndShowing_Test extends Sequent
@Test
public void should_return_true_if_JTextComponent_is_showing_and_text_is_equal_to_expected() {
MyWindow window = MyWindow.createAndShow();
- JTextComponentMatcher matcher = JTextComponentMatcher.withText("Hello").andShowing();
- assertThat(matcher.matches(window.textField)).isTrue();
+ try {
+ JTextComponentMatcher matcher = JTextComponentMatcher.withText("Hello").andShowing();
+ assertThat(matcher.matches(window.textField)).isTrue();
+ }
+ finally {
+ window.destroy();
+ }
}
@Test
@@ -50,8 +54,13 @@ public class JTextComponentMatcher_matches_byTextAndShowing_Test extends Sequent
@Test
public void should_return_false_if_JTextComponent_is_showing_and_text_is_not_equal_to_expected() {
MyWindow window = MyWindow.createAndShow();
- JTextComponentMatcher matcher = JTextComponentMatcher.withText("Bye").andShowing();
- assertThat(matcher.matches(window.textField)).isFalse();
+ try {
+ JTextComponentMatcher matcher = JTextComponentMatcher.withText("Bye").andShowing();
+ assertThat(matcher.matches(window.textField)).isFalse();
+ }
+ finally {
+ window.destroy();
+ }
}
@Test
@@ -64,12 +73,7 @@ public class JTextComponentMatcher_matches_byTextAndShowing_Test extends Sequent
private static class MyWindow extends TestWindow {
@RunsInEDT
static MyWindow createAndShow() {
- return execute(new GuiQuery<MyWindow>() {
- @Override
- protected MyWindow executeInEDT() {
- return display(new MyWindow());
- }
- });
+ return GuiQuery.get(() -> display(new MyWindow()));
}
final JTextField textField = new JTextField("Hello");
diff --git a/fest-swing/src/test/java/org/fest/swing/driver/JComboBoxDropDownListFinder_findDropDownList_Test.java b/fest-swing/src/test/java/org/fest/swing/driver/JComboBoxDropDownListFinder_findDropDownList_Test.java
index 37819eae..d1226f29 100644..100755
--- a/fest-swing/src/test/java/org/fest/swing/driver/JComboBoxDropDownListFinder_findDropDownList_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/driver/JComboBoxDropDownListFinder_findDropDownList_Test.java
@@ -51,6 +51,11 @@ public class JComboBoxDropDownListFinder_findDropDownList_Test extends RobotBase
robot.showWindow(window);
}
+ @Override
+ protected void onTearDown() {
+ window.destroy();
+ }
+
@Test
public void should_find_drop_down_list() {
showJComboBoxDropDownList();
@@ -79,12 +84,7 @@ public class JComboBoxDropDownListFinder_findDropDownList_Test extends RobotBase
@RunsInEDT
private void showJComboBoxDropDownList() {
- execute(new GuiTask() {
- @Override
- protected void executeInEDT() {
- window.comboBox.showPopup();
- }
- });
+ GuiTask.execute(() -> window.comboBox.showPopup());
robot.waitForIdle();
}
@@ -121,12 +121,7 @@ public class JComboBoxDropDownListFinder_findDropDownList_Test extends RobotBase
@RunsInEDT
static MyWindow createNew() {
- return execute(new GuiQuery<MyWindow>() {
- @Override
- protected MyWindow executeInEDT() {
- return new MyWindow();
- }
- });
+ return GuiQuery.get(() -> new MyWindow());
}
private MyWindow() {
diff --git a/fest-swing/src/test/java/org/fest/swing/fixture/Bug279_firstCharInJComboBoxMissing_Test.java b/fest-swing/src/test/java/org/fest/swing/fixture/Bug279_firstCharInJComboBoxMissing_Test.java
index f7cf9795..55ed11b0 100644..100755
--- a/fest-swing/src/test/java/org/fest/swing/fixture/Bug279_firstCharInJComboBoxMissing_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/fixture/Bug279_firstCharInJComboBoxMissing_Test.java
@@ -40,6 +40,11 @@ public class Bug279_firstCharInJComboBoxMissing_Test extends RobotBasedTestCase
window.show();
}
+ @Override
+ protected void onTearDown() {
+ window.target().dispose();
+ }
+
@Test
public void should_enter_text_in_editable_JComboBox() {
window.comboBox("comboBox").doubleClick().enterText("hey").pressAndReleaseKeys(VK_ENTER);
diff --git a/fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withName_Test.java b/fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withName_Test.java
index bfba422d..614e2b42 100755
--- a/fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withName_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withName_Test.java
@@ -44,9 +44,14 @@ public class DialogFixture_constructor_withName_Test extends RobotBasedTestCase
Dialog target = dialog().withName("dialog")
.withTitle(getClass().getSimpleName())
.createAndShow();
- fixture = new DialogFixture(robot, "dialog");
- assertThat(fixture.robot()).isNotNull();
- assertThat(fixture.target()).isSameAs(target);
+ try {
+ fixture = new DialogFixture(robot, "dialog");
+ assertThat(fixture.robot()).isNotNull();
+ assertThat(fixture.target()).isSameAs(target);
+ }
+ finally {
+ target.dispose();
+ }
}
@Test(expected = ComponentLookupException.class)
diff --git a/fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withRobotAndName_Test.java b/fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withRobotAndName_Test.java
index de3bb8ac..afbff85a 100644..100755
--- a/fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withRobotAndName_Test.java
+++ b/fest-swing/src/test/java/org/fest/swing/fixture/DialogFixture_constructor_withRobotAndName_Test.java
@@ -35,9 +35,14 @@ public class DialogFixture_constructor_withRobotAndName_Test extends RobotBasedT
Dialog target = dialog().withName("dialog")
.withTitle(getClass().getSimpleName())
.createAndShow();
- DialogFixture fixture = new DialogFixture(robot, "dialog");
- assertThat(fixture.robot()).isSameAs(robot);
- assertThat(fixture.target()).isSameAs(target);
+ try {
+ DialogFixture fixture = new DialogFixture(robot, "dialog");
+ assertThat(fixture.robot()).isSameAs(robot);
+ assertThat(fixture.target()).isSameAs(target);
+ }
+ finally {
+ target.dispose();
+ }
}
@Test(expected = ComponentLookupException.class)
diff --git a/fest-swing/src/test/java/org/fest/swing/test/core/EDTSafeTestCase.java b/fest-swing/src/test/java/org/fest/swing/test/core/EDTSafeTestCase.java
index ce54a750..4080af90 100755
--- a/fest-swing/src/test/java/org/fest/swing/test/core/EDTSafeTestCase.java
+++ b/fest-swing/src/test/java/org/fest/swing/test/core/EDTSafeTestCase.java
@@ -15,10 +15,13 @@
package org.fest.swing.test.core;
import org.fest.swing.edt.FailOnThreadViolationRepaintManager;
+import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.Timeout;
+import java.awt.*;
+
/**
* Base test case that ensures that Swing components are created and accessed in the EDT.
*
@@ -26,10 +29,25 @@ import org.junit.rules.Timeout;
*/
public abstract class EDTSafeTestCase {
@Rule
- public Timeout globalTimeout = Timeout.seconds(30);
+ public Timeout globalTimeout = Timeout.seconds(60);
@BeforeClass
public static void setUpOnce() {
FailOnThreadViolationRepaintManager.install();
}
+
+ @After
+ public void checkOpenFrames() {
+ boolean frameFound = false;
+ for (Frame frame : Frame.getFrames()) {
+ if (frame.isDisplayable()) {
+ frameFound = true;
+ frame.dispose();
+ }
+ }
+
+ if (frameFound) {
+ throw new RuntimeException(String.format("Test in %s finished with open frames", getClass().getSimpleName()));
+ }
+ }
}