Changeset 32591 in osm for applications/editors


Ignore:
Timestamp:
2016-07-06T16:00:47+02:00 (8 years ago)
Author:
floscher
Message:

[mapillary] Add test cases for PreferenceSetting (the Mapillary-tab in the JOSM settings dialog)

Location:
applications/editors/josm/plugins/mapillary
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r32581 r32591  
    9797    format24.setSelected(Main.pref.getBoolean("mapillary.format-24"));
    9898    moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true));
    99         this.hoverEnabled.setSelected(Main.pref.getBoolean("mapillary.hover-enabled", true));
     99    hoverEnabled.setSelected(Main.pref.getBoolean("mapillary.hover-enabled", true));
    100100
    101101    mainPanel.setLayout(new GridBagLayout());
     
    170170
    171171    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), false);
    172     if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Automatic.toString()))
     172    if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Automatic.toString())) {
    173173      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Automatic.toString());
    174     if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Semiautomatic.toString()))
     174    }
     175    if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Semiautomatic.toString())) {
    175176      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Semiautomatic.toString());
     177    }
    176178    if (this.downloadModeComboBox.getSelectedItem().equals(MapillaryDownloader.MODES.Manual.toString())) {
    177179      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Manual.toString());
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSettingTest.java

    r32078 r32591  
    77import java.awt.GraphicsEnvironment;
    88import java.lang.reflect.Field;
     9import java.util.HashMap;
     10import java.util.Map;
    911
    1012import javax.swing.JButton;
     13import javax.swing.JCheckBox;
     14import javax.swing.JComboBox;
    1115import javax.swing.JLabel;
    1216import javax.swing.JPanel;
    1317
    1418import org.junit.Test;
     19import org.openstreetmap.josm.Main;
    1520import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
    1621import org.openstreetmap.josm.plugins.mapillary.AbstractTest;
     
    3136    assertEquals(displayTabs + 1, tabs.getDisplayPreference().getTabPane().getTabCount());
    3237    assertEquals(tabs.getDisplayPreference(), setting.getTabPreferenceSetting(tabs));
     38  }
     39
     40  @Test
     41  public void testIsExpert() {
     42    assertFalse(new MapillaryPreferenceSetting().isExpert());
    3343  }
    3444
     
    5868  }
    5969
    60   private static Object getPrivateField(MapillaryPreferenceSetting object, String name) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
     70  /**
     71   * Helper method for obtaining the value of a private field
     72   * @param object the object of which you want the private field
     73   * @param name the name of the private field
     74   * @return the current value that field has
     75   */
     76  private static Object getPrivateField(MapillaryPreferenceSetting object, String name)
     77      throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
    6178    Field field = object.getClass().getDeclaredField(name);
    6279    field.setAccessible(true);
     
    6481  }
    6582
     83  @SuppressWarnings("unchecked")
     84  @Test
     85  public void testOk() throws SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchFieldException {
     86    MapillaryPreferenceSetting settings = new MapillaryPreferenceSetting();
     87
     88    // Test checkboxes
     89    settings.ok();
     90    assertEquals(Main.pref.get("mapillary.display-hour"),
     91        Boolean.toString(((JCheckBox) getPrivateField(settings, "displayHour")).isSelected()));
     92    assertEquals(Main.pref.get("mapillary.format-24"),
     93        Boolean.toString(((JCheckBox) getPrivateField(settings, "format24")).isSelected()));
     94    assertEquals(Main.pref.get("mapillary.move-to-picture"),
     95        Boolean.toString(((JCheckBox) getPrivateField(settings, "moveTo")).isSelected()));
     96    assertEquals(Main.pref.get("mapillary.hover-enabled"),
     97        Boolean.toString(((JCheckBox) getPrivateField(settings, "hoverEnabled")).isSelected()));
     98
     99    // Toggle state of the checkboxes
     100    toggleCheckbox((JCheckBox) getPrivateField(settings, "displayHour"));
     101    toggleCheckbox((JCheckBox) getPrivateField(settings, "format24"));
     102    toggleCheckbox((JCheckBox) getPrivateField(settings, "moveTo"));
     103    toggleCheckbox((JCheckBox) getPrivateField(settings, "hoverEnabled"));
     104
     105    // Test the second state of the checkboxes
     106    settings.ok();
     107    assertEquals(Main.pref.get("mapillary.display-hour"),
     108        Boolean.toString(((JCheckBox) getPrivateField(settings, "displayHour")).isSelected()));
     109    assertEquals(Main.pref.get("mapillary.format-24"),
     110        Boolean.toString(((JCheckBox) getPrivateField(settings, "format24")).isSelected()));
     111    assertEquals(Main.pref.get("mapillary.move-to-picture"),
     112        Boolean.toString(((JCheckBox) getPrivateField(settings, "moveTo")).isSelected()));
     113    assertEquals(Main.pref.get("mapillary.hover-enabled"),
     114        Boolean.toString(((JCheckBox) getPrivateField(settings, "hoverEnabled")).isSelected()));
     115
     116    // Test combobox
     117    for (int i = 0; i < ((JComboBox<String>) getPrivateField(settings, "downloadModeComboBox")).getItemCount(); i++) {
     118      ((JComboBox<String>) getPrivateField(settings, "downloadModeComboBox")).setSelectedIndex(i);
     119      settings.ok();
     120      assertEquals(Main.pref.get("mapillary.download-mode"),
     121          ((JComboBox<String>) getPrivateField(settings, "downloadModeComboBox")).getSelectedItem());
     122    }
     123  }
     124
     125  private static void toggleCheckbox(JCheckBox jcb) {
     126    jcb.setSelected(!jcb.isSelected());
     127  }
     128
    66129}
Note: See TracChangeset for help on using the changeset viewer.