From 904df3e690814695f6b67f76c217d779047871e5 Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Mon, 19 Mar 2018 00:08:30 +0000
Subject: [PATCH v2 11/28] PreferencesTableTest: convert to use of
JOSMTestRules, ExtendedDialogMocker & JOptionPaneSimpleMocker
won't yet have an effect until some internal isHeadless() checks are removed
---
.../preferences/advanced/PreferencesTableTest.java | 36 +++++++++++++++++-----
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/test/unit/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTableTest.java b/test/unit/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTableTest.java
index 4790d806d..cfa51654a 100644
a
|
b
|
import static org.junit.Assert.assertNull; |
7 | 7 | import static org.junit.Assert.assertTrue; |
8 | 8 | |
9 | 9 | import java.util.Arrays; |
| 10 | import javax.swing.JOptionPane; |
10 | 11 | |
11 | | import org.junit.BeforeClass; |
| 12 | import org.junit.Rule; |
12 | 13 | import org.junit.Test; |
13 | | import org.openstreetmap.josm.JOSMFixture; |
14 | 14 | import org.openstreetmap.josm.spi.preferences.StringSetting; |
| 15 | import org.openstreetmap.josm.gui.ExtendedDialog; |
15 | 16 | import org.openstreetmap.josm.gui.preferences.advanced.PreferencesTable.AllSettingsTableModel; |
16 | 17 | |
| 18 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| 19 | import org.openstreetmap.josm.testutils.JOptionPaneSimpleMocker; |
| 20 | import org.openstreetmap.josm.testutils.ExtendedDialogMocker; |
| 21 | |
| 22 | import com.google.common.collect.ImmutableMap; |
| 23 | |
| 24 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 25 | |
17 | 26 | /** |
18 | 27 | * Unit tests of {@link PreferencesTable} class. |
19 | 28 | */ |
20 | 29 | public class PreferencesTableTest { |
21 | | |
22 | 30 | /** |
23 | | * Setup test. |
| 31 | * Setup tests |
24 | 32 | */ |
25 | | @BeforeClass |
26 | | public static void setUpBeforeClass() { |
27 | | JOSMFixture.createUnitTestFixture().init(); |
28 | | } |
| 33 | @Rule |
| 34 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") |
| 35 | public JOSMTestRules test = new JOSMTestRules().preferences().assertionsInEDT(); |
29 | 36 | |
30 | 37 | private static PrefEntry newPrefEntry(String value) { |
31 | 38 | StringSetting val = new StringSetting(value); |
… |
… |
public class PreferencesTableTest { |
42 | 49 | */ |
43 | 50 | @Test |
44 | 51 | public void testPreferencesTable() { |
| 52 | new JOptionPaneSimpleMocker(ImmutableMap.of( |
| 53 | "Please select the row to edit.", JOptionPane.OK_OPTION, |
| 54 | "Please select the row to delete.", JOptionPane.OK_OPTION |
| 55 | )); |
| 56 | new ExtendedDialogMocker() { |
| 57 | protected int getMockResult(final ExtendedDialog instance) { |
| 58 | if (instance.getTitle().equals("Add setting")) { |
| 59 | return 1 + this.getButtonPositionFromLabel(instance, "Cancel"); |
| 60 | } else { |
| 61 | return super.getMockResult(instance); |
| 62 | } |
| 63 | } |
| 64 | }; |
45 | 65 | PreferencesTable t = newTable(); |
46 | 66 | t.fireDataChanged(); |
47 | 67 | assertTrue(t.getSelectedItems().isEmpty()); |