Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Oct 26, 2022
1 parent 3f9fa25 commit 6154ee8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 61 deletions.
8 changes: 0 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ dependencies {
testImplementation("org.awaitility:awaitility:${versions.awaitility}")
}

// Add dependencies from ivy.xml
def ivyModule = new XmlParser().parse(new File("$projectDir/ivy.xml"))
logger.info("Dependencies from ivy.xml (added to configuration `packIntoJar`):")
ivyModule.dependencies.dependency.each {
logger.info(" * ${it.@org}:${it.@name}:${it.@rev}")
project.dependencies.packIntoJar("${it.@org}:${it.@name}:${it.@rev}")
}

test {
project.afterEvaluate {
jvmArgs("-javaagent:${classpath.find { it.name.contains("jmockit") }.absolutePath}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
package com.kaart.highwaynamemodification;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import javax.swing.JOptionPane;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import com.github.tomakehurst.wiremock.WireMockServer;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;

public class HighwayNameChangeActionTest {
@Rule
public JOSMTestRules rule = new JOSMTestRules().projection().preferences();
@BasicPreferences
class HighwayNameChangeActionTest {
@RegisterExtension
static JOSMTestRules rule = new JOSMTestRules().projection();
WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock"));

@Before
public void setUp() {
@BeforeEach
void setUp() {
wireMock.start();

Config.getPref().put("download.overpass.server", wireMock.baseUrl());
Expand All @@ -35,15 +42,18 @@ public void setUp() {

}

@After
public void tearDown() {
wireMock.stop();
Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl());

@AfterEach
void tearDown() throws ExecutionException, InterruptedException, TimeoutException {
try {
MainApplication.worker.submit(() -> {/* Sync */}).get(10, TimeUnit.SECONDS);
} finally {
wireMock.stop();
Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl());
}
}

@Test
public final void testActionPerformed() {
final void testActionPerformed() {
HighwayNameListener tester = new HighwayNameListener();
Way prim = TestUtils.newWay("highway=residential name=\"North 8th Street\"",
new Node(new LatLon(39.084616, -108.559293)), new Node(new LatLon(39.0854611, -108.5592888)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
package com.kaart.highwaynamemodification;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import javax.swing.JOptionPane;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.testutils.JOSMTestRules;

import com.github.tomakehurst.wiremock.WireMockServer;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;

/**
* @author Ryan Fleming
*
*/
public class HighwayNameListenerTest {
@Rule
public JOSMTestRules rule = new JOSMTestRules().projection().preferences().fakeAPI();
@BasicPreferences
class HighwayNameListenerTest {
@RegisterExtension
static JOSMTestRules rule = new JOSMTestRules().projection().fakeAPI();
WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock"));

@Before
public void setUp() {
@BeforeEach
void setUp() {
wireMock.start();

Config.getPref().put("download.overpass.server", wireMock.baseUrl());
Expand All @@ -39,16 +46,19 @@ public void setUp() {

}

@After
public void tearDown() {
wireMock.stop();
Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl());
Config.getPref().put("download.overpass.server", "https://overpass-api.de/api/");

@AfterEach
void tearDown() throws ExecutionException, InterruptedException, TimeoutException {
try {
MainApplication.worker.submit(() -> {/* Sync thread */}).get(1, TimeUnit.MINUTES);
} finally {
wireMock.stop();
Config.getPref().put("osm-server.url", Config.getUrls().getDefaultOsmApiUrl());
Config.getPref().put("download.overpass.server", "https://overpass-api.de/api/");
}
}

@Test
public final void testTagsChanged() {
final void testTagsChanged() {
HighwayNameListener tester = new HighwayNameListener();
Way prim = TestUtils.newWay("highway=residential name=\"North 8th Street\"",
new Node(new LatLon(39.084616, -108.559293)), new Node(new LatLon(39.0854611, -108.5592888)));
Expand All @@ -63,7 +73,7 @@ public final void testTagsChanged() {
}

@Test
public final void testDataChanged() {
final void testDataChanged() {
HighwayNameListener tester = new HighwayNameListener();
Way prim = TestUtils.newWay("highway=residential name=\"North 8th Street\"",
new Node(new LatLon(39.084616, -108.559293)), new Node(new LatLon(39.0854611, -108.5592888)));
Expand All @@ -73,8 +83,8 @@ public final void testDataChanged() {
newDataset.addDataSetListener(tester);
for (int i = 0; i < 31; i++) { // 30 is minimum single stack events to trigger a DataChangedEvent
Way newprim = TestUtils.newWay("highway=residential name=\"North 8th Street\"",
new Node(new LatLon(39.084616, -108.559293 + (i / 100))),
new Node(new LatLon(39.0854611, -108.5592888 + (i / 100))));
new Node(new LatLon(39.084616, -108.559293 + (i / 100d))),
new Node(new LatLon(39.0854611, -108.5592888 + (i / 100d))));
newprim.getNodes().forEach(newDataset::addPrimitive);
newDataset.addPrimitive(newprim);
newprim.put("name", "Road " + i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.kaart.highwaynamemodification;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
Expand All @@ -9,44 +9,44 @@

import javax.swing.JMenu;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.plugins.PluginException;
import org.openstreetmap.josm.plugins.PluginInformation;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences;

public class HighwayNameModificationTest {
@Rule
public JOSMTestRules test = new JOSMTestRules().preferences().main();
@BasicPreferences
class HighwayNameModificationTest {
@RegisterExtension
static JOSMTestRules test = new JOSMTestRules().main();

public PluginInformation info;
public HighwayNameModification plugin;
PluginInformation info;
HighwayNameModification plugin;

private static final String VERSION = "no-such-version";

/**
* @throws java.lang.Exception
* @throws PluginException if the plugin could not be loaded
*/
@Before
public void setUp() throws ExceptionInInitializerError, Exception {

@BeforeEach
void setUp() throws PluginException {
final InputStream in = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
info = new PluginInformation(in, "HighwayNameModification", null);
info.localversion = VERSION;

}

@Test
public final void testHighwayNameModification() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException, ExceptionInInitializerError {
final void testHighwayNameModification() throws SecurityException,
IllegalArgumentException, ExceptionInInitializerError {
final JMenu dataMenu = MainApplication.getMenu().dataMenu;
final int dataMenuSize = dataMenu.getMenuComponentCount();
plugin = new HighwayNameModification(info);
assertEquals(dataMenuSize + 1, dataMenu.getMenuComponentCount());
plugin.destroy();
assertEquals(dataMenuSize, dataMenu.getMenuComponentCount());

}

}

0 comments on commit 6154ee8

Please sign in to comment.