source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTableTest.java@ 14081

Last change on this file since 14081 was 14081, checked in by Don-vip, 6 years ago

see #16010 - Ignore tests using JMockit on Java 11+, workaround to https://github.com/jmockit/jmockit1/issues/534

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.advanced;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertNull;
7import static org.junit.Assert.assertTrue;
8
9import java.util.Arrays;
10
11import javax.swing.JOptionPane;
12
13import org.junit.Rule;
14import org.junit.Test;
15import org.openstreetmap.josm.TestUtils;
16import org.openstreetmap.josm.gui.ExtendedDialog;
17import org.openstreetmap.josm.gui.preferences.advanced.PreferencesTable.AllSettingsTableModel;
18import org.openstreetmap.josm.spi.preferences.StringSetting;
19import org.openstreetmap.josm.testutils.JOSMTestRules;
20import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
21import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
22
23import com.google.common.collect.ImmutableMap;
24
25import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
26
27/**
28 * Unit tests of {@link PreferencesTable} class.
29 */
30public class PreferencesTableTest {
31 /**
32 * Setup tests
33 */
34 @Rule
35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
36 public JOSMTestRules test = new JOSMTestRules().preferences().assertionsInEDT();
37
38 private static PrefEntry newPrefEntry(String value) {
39 StringSetting val = new StringSetting(value);
40 StringSetting def = new StringSetting("defaultValue");
41 return new PrefEntry("key", val, def, false);
42 }
43
44 private static PreferencesTable newTable() {
45 return new PreferencesTable(Arrays.asList(newPrefEntry("value")));
46 }
47
48 /**
49 * Unit test of {@link PreferencesTable#PreferencesTable}.
50 */
51 @Test
52 public void testPreferencesTable() {
53 TestUtils.assumeWorkingJMockit();
54 new JOptionPaneSimpleMocker(ImmutableMap.of(
55 "Please select the row to edit.", JOptionPane.OK_OPTION,
56 "Please select the row to delete.", JOptionPane.OK_OPTION
57 ));
58 new ExtendedDialogMocker() {
59 @Override
60 protected int getMockResult(final ExtendedDialog instance) {
61 if (instance.getTitle().equals("Add setting")) {
62 return 1 + this.getButtonPositionFromLabel(instance, "Cancel");
63 } else {
64 return super.getMockResult(instance);
65 }
66 }
67 };
68 PreferencesTable t = newTable();
69 t.fireDataChanged();
70 assertTrue(t.getSelectedItems().isEmpty());
71 assertFalse(t.editPreference(null));
72 assertNull(t.addPreference(null));
73 t.resetPreferences(null);
74 }
75
76 /**
77 * Unit test of {@link PreferencesTable.AllSettingsTableModel} class.
78 */
79 @Test
80 public void testAllSettingsTableModel() {
81 AllSettingsTableModel model = (AllSettingsTableModel) newTable().getModel();
82 assertEquals(1, model.getRowCount());
83 assertFalse(model.isCellEditable(0, 0));
84 assertTrue(model.isCellEditable(0, 1));
85 assertEquals("key", model.getValueAt(0, 0));
86 assertEquals(newPrefEntry("value"), model.getValueAt(0, 1));
87 String foobar = "foobar";
88 model.setValueAt(foobar, 0, 1);
89 assertEquals(newPrefEntry(foobar), model.getValueAt(0, 1));
90 }
91}
Note: See TracBrowser for help on using the repository browser.