Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tests to JUnit 5 #643

Merged
merged 2 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -303,6 +303,14 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
<resources>
<resource>
Expand Down
13 changes: 6 additions & 7 deletions src/test/java/de/komoot/photon/ApiIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import de.komoot.photon.elasticsearch.Importer;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.stream.Collectors;

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

/**
Expand All @@ -23,7 +22,7 @@
public class ApiIntegrationTest extends ESBaseTester {
private static final int LISTEN_PORT = 30234;

@Before
@BeforeEach
public void setUp() throws Exception {
setUpES();
Importer instance = makeImporter();
Expand All @@ -33,7 +32,7 @@ public void setUp() throws Exception {
refresh();
}

@After
@AfterEach
public void shutdown() {
stop();
awaitStop();
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/de/komoot/photon/AssertUtil.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package de.komoot.photon;

import de.komoot.photon.nominatim.model.AddressType;
import org.junit.Assert;

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

public class AssertUtil {
private AssertUtil() {}

public static void assertAddressName(String name, PhotonDoc doc, AddressType addressType) {
Assert.assertNotNull(doc.getAddressParts().get(addressType));
Assert.assertEquals(name, doc.getAddressParts().get(addressType).get("name"));
assertNotNull(doc.getAddressParts().get(addressType));
assertEquals(name, doc.getAddressParts().get(addressType).get("name"));
}

public static void assertNoAddress(PhotonDoc doc, AddressType addressType) {
Assert.assertNull(doc.getAddressParts().get(addressType));
assertNull(doc.getAddressParts().get(addressType));
}
}
4 changes: 2 additions & 2 deletions src/test/java/de/komoot/photon/ESBaseTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.junit.After;
import org.junit.jupiter.api.AfterEach;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -41,7 +41,7 @@ protected GetResponse getById(int id) {
}


@After
@AfterEach
public void tearDown() {
deleteIndex();
shutdownES();
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/de/komoot/photon/PhotonDocTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.HashMap;

import de.komoot.photon.nominatim.model.AddressType;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

public class PhotonDocTest {

Expand Down Expand Up @@ -36,8 +37,8 @@ public void testCompleteAddressCreatesStreetIfNonExistantBefore() {
public void testAddCountryCode() {
PhotonDoc doc = new PhotonDoc(1, "W", 2, "highway", "residential").countryCode("de");

Assert.assertNotNull(doc.getCountryCode());
Assert.assertEquals("DE", doc.getCountryCode().getAlpha2());
assertNotNull(doc.getCountryCode());
assertEquals("DE", doc.getCountryCode().getAlpha2());
}

private PhotonDoc simplePhotonDoc() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package de.komoot.photon.elasticsearch;

import de.komoot.photon.ESBaseTester;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;

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

/**
* Tests for the database-global property store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import de.komoot.photon.ESBaseTester;
import de.komoot.photon.PhotonDoc;
import org.elasticsearch.action.get.GetResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

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

public class ImporterTest extends ESBaseTester {

@Before
@BeforeEach
public void setUp() throws IOException {
setUpES();
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/de/komoot/photon/elasticsearch/UpdaterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import de.komoot.photon.ESBaseTester;
import de.komoot.photon.PhotonDoc;
import org.elasticsearch.action.get.GetResponse;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

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

public class UpdaterTest extends ESBaseTester {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import de.komoot.photon.nominatim.testdb.H2DataAdapter;
import de.komoot.photon.nominatim.testdb.OsmlineTestRow;
import de.komoot.photon.nominatim.testdb.PlacexTestRow;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
Expand All @@ -24,7 +24,7 @@ public class NominatimConnectorDBTest {
private CollectingImporter importer;
private JdbcTemplate jdbc;

@Before
@BeforeEach
public void setup() {
db = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
Expand All @@ -46,7 +46,7 @@ public void testSimpleNodeImport() throws ParseException {
PlacexTestRow place = new PlacexTestRow("amenity", "cafe").name("Spot").add(jdbc);
connector.readEntireDatabase();

Assert.assertEquals(1, importer.size());
assertEquals(1, importer.size());
importer.assertContains(place);
}

Expand All @@ -57,7 +57,7 @@ public void testImportForSelectedCountries() throws ParseException {
new PlacexTestRow("amenity", "cafe").name("SpotUS").country("us").add(jdbc);
connector.readEntireDatabase("uk", "hu", "nl");

Assert.assertEquals(1, importer.size());
assertEquals(1, importer.size());
importer.assertContains(place);
}

Expand All @@ -68,8 +68,8 @@ public void testImportance() {

connector.readEntireDatabase();

Assert.assertEquals(0.5, importer.get(place1.getPlaceId()).getImportance(), 0.00001);
Assert.assertEquals(0.3, importer.get(place2.getPlaceId()).getImportance(), 0.00001);
assertEquals(0.5, importer.get(place1.getPlaceId()).getImportance(), 0.00001);
assertEquals(0.3, importer.get(place2.getPlaceId()).getImportance(), 0.00001);
}

@Test
Expand All @@ -85,7 +85,7 @@ public void testPlaceAddress() throws ParseException {

connector.readEntireDatabase();

Assert.assertEquals(6, importer.size());
assertEquals(6, importer.size());
importer.assertContains(place);

PhotonDoc doc = importer.get(place);
Expand All @@ -108,7 +108,7 @@ public void testPoiAddress() throws ParseException {

connector.readEntireDatabase();

Assert.assertEquals(3, importer.size());
assertEquals(3, importer.size());
importer.assertContains(place);

PhotonDoc doc = importer.get(place);
Expand All @@ -130,7 +130,7 @@ public void testInterpolationAny() throws ParseException {

connector.readEntireDatabase();

Assert.assertEquals(10, importer.size());
assertEquals(10, importer.size());

PlacexTestRow expect = new PlacexTestRow("place", "house_number").id(osmline.getPlaceId()).parent(street).osm("W", 23);

Expand All @@ -154,12 +154,12 @@ public void testAddressMappingDuplicate() {

connector.readEntireDatabase();

Assert.assertEquals(3, importer.size());
assertEquals(3, importer.size());

PhotonDoc doc = importer.get(place);

AssertUtil.assertAddressName("Dorf", doc, AddressType.CITY);
Assert.assertTrue(doc.getContext().contains(munip.getNames()));
assertTrue(doc.getContext().contains(munip.getNames()));
}

/**
Expand All @@ -174,12 +174,12 @@ public void testAddressMappingAvoidSameTypeAsPlace() {

connector.readEntireDatabase();

Assert.assertEquals(2, importer.size());
assertEquals(2, importer.size());

PhotonDoc doc = importer.get(village);

AssertUtil.assertNoAddress(doc, AddressType.CITY);
Assert.assertTrue(doc.getContext().contains(munip.getNames()));
assertTrue(doc.getContext().contains(munip.getNames()));
}

/**
Expand All @@ -192,10 +192,10 @@ public void testUnnamedObjectWithHousenumber() {

connector.readEntireDatabase();

Assert.assertEquals(2, importer.size());
assertEquals(2, importer.size());

PhotonDoc doc = importer.get(place);
Assert.assertEquals(doc.getHouseNumber(), "123");
assertEquals(doc.getHouseNumber(), "123");
}

/**
Expand All @@ -208,7 +208,7 @@ public void testObjectWithHousenumberList() throws ParseException {

connector.readEntireDatabase();

Assert.assertEquals(4, importer.size());
assertEquals(4, importer.size());

importer.assertContains(place, 1);
importer.assertContains(place, 2);
Expand All @@ -228,7 +228,7 @@ public void testObjectWithconscriptionNumber() throws ParseException {

connector.readEntireDatabase();

Assert.assertEquals(3, importer.size());
assertEquals(3, importer.size());

importer.assertContains(place, 34);
importer.assertContains(place, 99521);
Expand All @@ -243,7 +243,7 @@ public void testUnnamedObjectWithOutHousenumber() {

connector.readEntireDatabase();

Assert.assertEquals(1, importer.size());
assertEquals(1, importer.size());

importer.get(parent);
}
Expand All @@ -258,7 +258,7 @@ public void testInterpolationLines() {

connector.readEntireDatabase();

Assert.assertEquals(1, importer.size());
assertEquals(1, importer.size());

importer.get(parent);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.komoot.photon.nominatim;

import org.junit.Test;
import org.junit.jupiter.api.Test;

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

public class NominatimConnectorTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import de.komoot.photon.PhotonDoc;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.*;

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

public class NominatimResultTest {
private final PhotonDoc simpleDoc = new PhotonDoc(10000, "N", 123, "place", "house")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.komoot.photon.nominatim.model;

import org.junit.Test;
import org.junit.jupiter.api.Test;

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

public class AddressTypeTest {

/**
* All ranks coverd by Nominatim must return a corresponding Photon rank.
* All ranks covered by Nominatim must return a corresponding Photon rank.
*/
@Test
public void testAllRanksAreCovered() {
Expand Down
Loading