Skip to content

Commit

Permalink
#243 Update test framework JUnit to 5.x (#244)
Browse files Browse the repository at this point in the history
- updates to JUnit 5.10.x
- adapts existing test classes to new package names and test concepts of JUnit 5
  • Loading branch information
mawiesne authored Oct 30, 2023
1 parent 1d59b48 commit 18d3dfc
Show file tree
Hide file tree
Showing 25 changed files with 374 additions and 351 deletions.
17 changes: 11 additions & 6 deletions dkpro-jwpl-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@
<scope>test</scope>
</dependency>

<!-- JUnit dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- TEST dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
Expand Down
16 changes: 9 additions & 7 deletions dkpro-jwpl-api/src/it/java/org/dkpro/jwpl/api/PerformanceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
*/
package org.dkpro.jwpl.api;

import org.dkpro.jwpl.api.exception.WikiApiException;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.util.*;
import java.util.Properties;

import org.dkpro.jwpl.api.exception.WikiApiException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class PerformanceIT implements WikiConstants {

private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
Expand All @@ -40,7 +42,7 @@ public class PerformanceIT implements WikiConstants {
// The system under test
private static PerformanceTest pt;

@BeforeClass
@BeforeAll
public static void setupWikipedia() throws WikiApiException {
Properties configuration = loadConfiguration();
retrievedNumberOfPages = Integer.parseInt(configuration.getProperty("performance.pages.retrieved"));
Expand Down Expand Up @@ -84,7 +86,7 @@ private static InputStream checkResourceExists(String resourceName) {
return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
}

@Before
@BeforeEach
public void setup() throws WikiApiException {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.List;
import java.util.Set;

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

/**
* Encapsulates the integration test code that stresses a Wikipedia backend to check the performance of it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class BaseJWPLTest {

protected static Wikipedia wiki;

protected static final DatabaseConfiguration obtainHSDLDBConfiguration() {
protected static DatabaseConfiguration obtainHSDLDBConfiguration() {
DatabaseConfiguration db = new DatabaseConfiguration();
db.setDatabase("wikiapi_test");
db.setHost("localhost");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
*/
package org.dkpro.jwpl.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.dkpro.jwpl.api.exception.WikiApiException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

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

import org.dkpro.jwpl.api.exception.WikiApiException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class CategoryDescendantsIteratorTest extends BaseJWPLTest{

Expand All @@ -37,22 +37,22 @@ public class CategoryDescendantsIteratorTest extends BaseJWPLTest{
* This could be changed back as soon as JUnit ignored tests after failed
* assumptions
*/
@BeforeClass
public static void setupWikipedia() {
@BeforeAll
public static void setupWikipedia() {
DatabaseConfiguration db = obtainHSDLDBConfiguration();
try {
wiki = new Wikipedia(db);
} catch (Exception e) {
fail("Wikipedia could not be initialized: "+e.getLocalizedMessage());
}
}
}


/**
* The category UKP has 9 descendants with pageIds 7-15.
*/
@Test
public void test_categoryIteratorTest() {
/**
* The category UKP has 9 descendants with pageIds 7-15.
*/
@Test
public void test_categoryIteratorTest() {

Category cat = null;
try {
Expand Down Expand Up @@ -80,14 +80,14 @@ public void test_categoryIteratorTest() {
}
Collections.sort(expectedPageIds);
Collections.sort(isIds);
assertEquals("descendants", expectedPageIds, isIds);
}
assertEquals(expectedPageIds, isIds, "descendants");
}

/**
* The category UKP has 9 descendants with pageIds 7-15.
*/
@Test
public void test_categoryIteratorTestBufferSize() {
@Test
public void test_categoryIteratorTestBufferSize() {

Category cat = null;
try {
Expand All @@ -110,14 +110,14 @@ public void test_categoryIteratorTestBufferSize() {
expectedPageIds.add(15);

for (int bufferSize=1;bufferSize<=100;bufferSize+=5) {
List<Integer> isIds = new ArrayList<>();
for(Category descendant : cat.getDescendants(bufferSize)) {
isIds.add(descendant.getPageId());
}
Collections.sort(expectedPageIds);
Collections.sort(isIds);
assertEquals("descendants", expectedPageIds, isIds);

List<Integer> isIds = new ArrayList<>();
for(Category descendant : cat.getDescendants(bufferSize)) {
isIds.add(descendant.getPageId());
}
Collections.sort(expectedPageIds);
Collections.sort(isIds);
assertEquals(expectedPageIds, isIds, "descendants");

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
*/
package org.dkpro.jwpl.api;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.dkpro.jwpl.api.exception.WikiApiException;

import java.util.Map;

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

import org.dkpro.jwpl.api.exception.WikiApiException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class CategoryGraphTest extends BaseJWPLTest{

Expand All @@ -39,7 +38,7 @@ public class CategoryGraphTest extends BaseJWPLTest{
* This could be changed back as soon as JUnit ignored tests after failed
* assumptions
*/
@BeforeClass
@BeforeAll
public static void setupWikipedia() {
DatabaseConfiguration db = obtainHSDLDBConfiguration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/
package org.dkpro.jwpl.api;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.util.Iterator;

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

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

public class CategoryIteratorTest extends BaseJWPLTest {

Expand All @@ -33,13 +33,13 @@ public class CategoryIteratorTest extends BaseJWPLTest {
* This could be changed back as soon as JUnit ignored tests after failed
* assumptions
*/
@BeforeClass
@BeforeAll
public static void setupWikipedia() {
DatabaseConfiguration db = obtainHSDLDBConfiguration();
try {
wiki = new Wikipedia(db);
} catch (Exception e) {
fail("Wikipedia could not be initialized: "+e.getLocalizedMessage());
fail("Wikipedia could not be initialized: "+e.getLocalizedMessage());
}
}

Expand All @@ -53,7 +53,7 @@ public void test_categoryIteratorTest() {
for (Category c : wiki.getCategories()) {
nrOfPages++;
}
assertEquals("Number of categories == 17", 17, nrOfPages);
assertEquals(17, nrOfPages, "Number of categories == 17");

}

Expand All @@ -71,7 +71,7 @@ public void test_categoryIteratorTestBufferSize() {
Category c = catIter.next();
nrOfPages++;
}
assertEquals("Number of categories == 17", 17, nrOfPages);
assertEquals(17, nrOfPages, "Number of categories == 17");
}
}
}
Loading

0 comments on commit 18d3dfc

Please sign in to comment.