Add tests for plugin initialization and versioning

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-10-03 10:45:26 -06:00
rodzic e7d7e495ab
commit d3ea8f2d82
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
3 zmienionych plików z 157 dodań i 8 usunięć

Wyświetl plik

@ -21,15 +21,15 @@ import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
import org.openstreetmap.josm.plugins.rapid.backend.RapiDDataUtils;
public class RapiDPreferences implements SubPreferenceSetting {
private final JLabel rapidApiUrl = new JLabel(tr("RapiD API URL"));
private final JComboBox<String> possibleRapidApiUrl = new JComboBox<>();
protected final JLabel rapidApiUrl = new JLabel(tr("RapiD API URL"));
protected final JComboBox<String> possibleRapidApiUrl = new JComboBox<>();
private final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
private final JCheckBox switchLayerCheckBox = new JCheckBox();
protected final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
protected final JCheckBox switchLayerCheckBox = new JCheckBox();
private final JLabel maximumAddition = new JLabel(
protected final JLabel maximumAddition = new JLabel(
tr("Maximum features (add)"));
private final JSpinner maximumAdditionSpinner = new JSpinner(
protected final JSpinner maximumAdditionSpinner = new JSpinner(
new SpinnerNumberModel(RapiDDataUtils.getMaximumAddition(), 0, 100, 1));
@Override
@ -85,8 +85,8 @@ public class RapiDPreferences implements SubPreferenceSetting {
RapiDDataUtils.setRapiDUrl((String) possibleRapidApiUrl.getSelectedItem());
RapiDDataUtils.setSwitchLayers(switchLayerCheckBox.isSelected());
Object value = maximumAdditionSpinner.getValue();
if (value instanceof Integer) {
RapiDDataUtils.setMaximumAddition((Integer) value);
if (value instanceof Number) {
RapiDDataUtils.setMaximumAddition(((Number) value).intValue());
}
return false;
}

Wyświetl plik

@ -0,0 +1,71 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.rapid;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.swing.JMenu;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.openstreetmap.josm.data.preferences.sources.MapPaintPrefHelper;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.plugins.PluginInformation;
import org.openstreetmap.josm.testutils.JOSMTestRules;
/**
* @author Taylor Smock
*/
public class RapiDPluginTest {
@Rule
public JOSMTestRules test = new JOSMTestRules().preferences().main();
public PluginInformation info;
public RapiDPlugin plugin;
private static String VERSION = "no-such-version";
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
InputStream in = new ByteArrayInputStream("".getBytes());
info = new PluginInformation(in, "Rapid", null);
info.localversion = VERSION;
}
/**
* Test method for {@link RapiDPlugin#getPreferenceSetting()}.
*/
@Test
public void testGetPreferenceSetting() {
plugin = new RapiDPlugin(info);
Assert.assertTrue(plugin.getPreferenceSetting() instanceof RapiDPreferences);
}
/**
* Test method for {@link RapiDPlugin#RapiDPlugin(PluginInformation)}.
*/
@Test
public void testRapiDPlugin() {
JMenu dataMenu = MainApplication.getMenu().dataMenu;
int originalPaintStyles = MapPaintPrefHelper.INSTANCE.get().size();
int dataMenuSize = dataMenu.getMenuComponentCount();
plugin = new RapiDPlugin(info);
Assert.assertEquals(dataMenuSize + 2, dataMenu.getMenuComponentCount());
Assert.assertEquals(originalPaintStyles + 1, MapPaintPrefHelper.INSTANCE.get().size());
}
/**
* Test method for {@link RapiDPlugin#getVersionInfo()}.
*/
@Test
public void testGetVersionInfo() {
plugin = new RapiDPlugin(info); // needs to be called for version info to be initialized.
Assert.assertEquals(VERSION, RapiDPlugin.getVersionInfo());
}
}

Wyświetl plik

@ -0,0 +1,78 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.rapid;
import javax.swing.SpinnerNumberModel;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
import org.openstreetmap.josm.plugins.rapid.backend.RapiDDataUtils;
import org.openstreetmap.josm.testutils.JOSMTestRules;
/**
* @author Taylor Smock
*
*/
public class RapiDPreferencesTest {
@Rule
public JOSMTestRules test = new JOSMTestRules().preferences().main();
private RapiDPreferences preferences;
/**
* @throws Exception
*/
@Before
public void setUp() throws Exception {
preferences = new RapiDPreferences();
}
/**
* Test method for {@link RapiDPreferences#addGui(PreferenceTabbedPane)}.
*/
@Test
public void testAddGui() {
PreferenceTabbedPane pane = new PreferenceTabbedPane();
pane.buildGui();
int tabs = pane.getPluginPreference().getTabPane().getTabCount();
preferences.addGui(pane);
Assert.assertEquals(tabs + 1, pane.getPluginPreference().getTabPane().getTabCount());
Assert.assertEquals(pane.getPluginPreference(), preferences.getTabPreferenceSetting(pane));
boolean switchLayers = RapiDDataUtils.getSwitchLayers();
Assert.assertEquals(switchLayers, preferences.switchLayerCheckBox.isSelected());
preferences.ok();
Assert.assertEquals(switchLayers, RapiDDataUtils.getSwitchLayers());
preferences.switchLayerCheckBox.setSelected(!switchLayers);
Assert.assertNotEquals(!switchLayers, RapiDDataUtils.getSwitchLayers());
preferences.ok();
Assert.assertEquals(!switchLayers, RapiDDataUtils.getSwitchLayers());
Object tmp = preferences.maximumAdditionSpinner.getModel();
SpinnerNumberModel spinnerModel = null;
if (tmp instanceof SpinnerNumberModel) {
spinnerModel = (SpinnerNumberModel) tmp;
}
Assert.assertNotNull(spinnerModel);
Number currentNumber = RapiDDataUtils.getMaximumAddition();
Assert.assertEquals(currentNumber.intValue(), spinnerModel.getNumber().intValue());
spinnerModel.setValue(currentNumber.intValue() + 3);
Assert.assertNotEquals(spinnerModel.getNumber().intValue(), RapiDDataUtils.getMaximumAddition());
preferences.ok();
Assert.assertEquals(spinnerModel.getNumber().intValue(), RapiDDataUtils.getMaximumAddition());
}
/**
* Test method for {@link RapiDPreferences#isExpert()}.
*/
@Test
public void testIsExpert() {
Assert.assertFalse(preferences.isExpert());
}
}