Skip to content

Commit c7e6507

Browse files
committed
#470: extract abstract superclass for tag translator tests
1 parent 6c32671 commit c7e6507

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/tagtranslator/TagTranslatorTest.java renamed to oshdb-util/src/test/java/org/heigit/ohsome/oshdb/util/tagtranslator/AbstractTagTranslatorTest.java

+14-18
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
import org.junit.jupiter.api.BeforeAll;
1616
import org.junit.jupiter.api.Test;
1717

18-
/**
19-
* Tests the {@link TagTranslator} class.
20-
*/
21-
class TagTranslatorTest {
22-
private static JdbcConnectionPool source;
18+
public abstract class AbstractTagTranslatorTest {
19+
20+
protected static JdbcConnectionPool source;
2321

2422
/**
2523
* Initialize tests by loading the H2 driver and open a connection via jdbc.
26-
*
2724
*/
2825
@BeforeAll
2926
static void setUpClass() {
@@ -35,12 +32,12 @@ static void breakDownClass() {
3532
source.dispose();
3633
}
3734

38-
TagTranslatorTest() {}
35+
abstract TagTranslator getTranslator();
3936

4037
@Test
4138
void testTag2Int() throws OSHDBKeytablesNotFoundException {
4239
OSMTag tag = new OSMTag("building", "yes");
43-
var instance = new JdbcTagTranslator(source);
40+
TagTranslator instance = getTranslator();
4441
OSHDBTag expResult = new OSHDBTag(1, 0);
4542
OSHDBTag result = instance.getOSHDBTagOf(tag).get();
4643
assertEquals(expResult, result);
@@ -53,7 +50,7 @@ void testTags2Int() throws OSHDBKeytablesNotFoundException {
5350
new OSMTag("building", "residential"), new OSHDBTag(1, 2),
5451
new OSMTag("highway", "primary"), new OSHDBTag(2, 7));
5552

56-
var instance = new JdbcTagTranslator(source);
53+
TagTranslator instance = getTranslator();
5754
var result = instance.getOSHDBTagOf(tags.keySet());
5855
assertEquals(tags.size(), result.size());
5956
for (var entry : tags.entrySet()) {
@@ -62,12 +59,11 @@ void testTags2Int() throws OSHDBKeytablesNotFoundException {
6259
}
6360
}
6461

65-
6662
@Test
6763
void testTag2String() throws OSHDBKeytablesNotFoundException {
6864
OSHDBTag tag = new OSHDBTag(1, 2);
6965
OSMTag expResult = new OSMTag("building", "residential");
70-
var instance = new JdbcTagTranslator(source);
66+
TagTranslator instance = getTranslator();
7167
OSMTag result = instance.lookupTag(tag);
7268
assertEquals(expResult, result);
7369
}
@@ -78,7 +74,7 @@ void testTags2String() {
7874
new OSHDBTag(1, 0), new OSMTag("building", "yes"),
7975
new OSHDBTag(1, 2), new OSMTag("building", "residential"),
8076
new OSHDBTag(2, 7), new OSMTag("highway", "primary"));
81-
var instance = new JdbcTagTranslator(source);
77+
TagTranslator instance = getTranslator();
8278
var result = instance.lookupTag(tags.keySet());
8379
assertEquals(tags.size(), result.size());
8480
for (var entry : tags.entrySet()) {
@@ -89,8 +85,8 @@ void testTags2String() {
8985

9086
@Test
9187
void testOSMEntityTag2String() {
92-
var osm = OSM.node(123, 1, 1000L, 100L, 1, new int[] {1, 0, 2, 7}, 0, 0);
93-
var instance = new JdbcTagTranslator(source);
88+
var osm = OSM.node(123, 1, 1000L, 100L, 1, new int[]{1, 0, 2, 7}, 0, 0);
89+
TagTranslator instance = getTranslator();
9490
var tags = instance.lookupTag(osm.getTags());
9591
assertEquals(2, tags.size());
9692
assertEquals(new OSMTag("building", "yes"), tags.get(new OSHDBTag(1, 0)));
@@ -100,7 +96,7 @@ void testOSMEntityTag2String() {
10096
@Test
10197
void testKey2Int() throws OSHDBKeytablesNotFoundException {
10298
OSMTagKey key = new OSMTagKey("highway");
103-
var instance = new JdbcTagTranslator(source);
99+
TagTranslator instance = getTranslator();
104100
OSHDBTagKey expResult = new OSHDBTagKey(2);
105101
OSHDBTagKey result = instance.getOSHDBTagKeyOf(key).get();
106102
assertEquals(expResult, result);
@@ -109,7 +105,7 @@ void testKey2Int() throws OSHDBKeytablesNotFoundException {
109105
@Test
110106
void testRole2Int() throws OSHDBKeytablesNotFoundException {
111107
OSMRole role = new OSMRole("from");
112-
var instance = new JdbcTagTranslator(source);
108+
TagTranslator instance = getTranslator();
113109
OSHDBRole expResult = OSHDBRole.of(4);
114110
OSHDBRole result = instance.getOSHDBRoleOf(role).get();
115111
assertEquals(expResult, result);
@@ -118,15 +114,15 @@ void testRole2Int() throws OSHDBKeytablesNotFoundException {
118114
@Test
119115
void testRole2String() throws OSHDBKeytablesNotFoundException {
120116
OSHDBRole role = OSHDBRole.of(1);
121-
var instance = new JdbcTagTranslator(source);
117+
TagTranslator instance = getTranslator();
122118
OSMRole expResult = new OSMRole("inner");
123119
OSMRole result = instance.lookupRole(role);
124120
assertEquals(expResult, result);
125121
}
126122

127123
@Test
128124
void testKeysIdentity() {
129-
var instance = new JdbcTagTranslator(source);
125+
TagTranslator instance = getTranslator();
130126
var tags = new ArrayList<OSMTag>(10);
131127
for (var i = 0; i < 10; i++) {
132128
tags.add(instance.lookupTag(new OSHDBTag(1, i)));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.heigit.ohsome.oshdb.util.tagtranslator;
2+
3+
/**
4+
* Tests the {@link JdbcTagTranslator} class.
5+
*/
6+
class JdbcTagTranslatorTest extends AbstractTagTranslatorTest {
7+
8+
@Override
9+
TagTranslator getTranslator() {
10+
return new JdbcTagTranslator(source);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)