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

Migrate to Junit5 #235

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<commons-io.version>2.16.1</commons-io.version>
<commons-lang.version>3.17.0</commons-lang.version>
<testcontainers.version>1.20.1</testcontainers.version>
<junit.version>4.13.2</junit.version>
<junit.version>5.11.0</junit.version>
<hamcrest.version>1.3</hamcrest.version>
</properties>

Expand Down Expand Up @@ -118,8 +118,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -210,8 +210,9 @@
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${java.version}</release>
<encoding>${project.build.sourceEncoding}</encoding>
<optimize>true</optimize>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
Expand All @@ -225,6 +226,7 @@
<version>3.10.0</version>
<configuration>
<source>${java.version}</source>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -315,8 +317,9 @@
</execution>
<execution>
<id>coverage-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
<goal>report-aggregate</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/jacoco</outputDirectory>
Expand Down
4 changes: 2 additions & 2 deletions signals/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,21 @@
import org.awaitility.Awaitility;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import sun.misc.Signal;

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

@RunWith(Parameterized.class)
@SuppressWarnings("squid:S1191")
public class SignalsHelperTest {

@Parameterized.Parameters(name = "SIG{0}")
public static Object[] data() {
return SignalsHelper.SIG.values();
}

private final SignalsHelper.SIG signalToTest;

public SignalsHelperTest(SignalsHelper.SIG signalToTest) {
this.signalToTest = signalToTest;
}
class SignalsHelperTest {

@Test
public void testSigUsr2() {
void testSigUsr2() {
final String s = "USR2";
final AtomicInteger counter = new AtomicInteger();

Expand All @@ -55,21 +45,25 @@ public void testSigUsr2() {
Awaitility.await()
.atMost(1, TimeUnit.SECONDS)
.until(counter::get, Matchers.is(1));
assertEquals("count signal events", 1, counter.get());
assertEquals(1, counter.get(), "count signal events");
}

@Test
public void testRegisterClearUsr2() {
void testRegisterClearUsr2() {
testRegisterClear("USR2");
}

@Test
public void testWithEnum() {
@ParameterizedTest
@EnumSource(SignalsHelper.SIG.class)
void testWithEnum(SignalsHelper.SIG signalToTest) {
assertOsSupport(signalToTest);
testRegisterClear(signalToTest);
}

@Test
public void testWithSignalName() {
@ParameterizedTest
@EnumSource(SignalsHelper.SIG.class)
void testWithSignalName(SignalsHelper.SIG signalToTest) {
assertOsSupport(signalToTest);
testRegisterClear(signalToTest.getSigName());
}

Expand All @@ -84,7 +78,7 @@ private void testRegisterClear(final String signal) {
Awaitility.await()
.atMost(1, TimeUnit.SECONDS)
.until(counter::get, Matchers.is(1));
assertEquals("count signal events", 1, counter.get());
assertEquals(1, counter.get(), "count signal events");

SignalsHelper.clearHandler(signal);

Expand All @@ -107,7 +101,7 @@ private void testRegisterClear(SignalsHelper.SIG signal) {
Awaitility.await()
.atMost(1, TimeUnit.SECONDS)
.until(counter::get, Matchers.is(1));
assertEquals("count signal events", 1, counter.get());
assertEquals(1, counter.get(), "count signal events");

SignalsHelper.clearHandler(signal);

Expand All @@ -118,4 +112,24 @@ private void testRegisterClear(SignalsHelper.SIG signal) {
MatcherAssert.assertThat("check error message", e.getMessage(), Matchers.is("Unhandled signal: SIG" + signal));
}
}

private void assertOsSupport(SignalsHelper.SIG signal) {
// Some Signals can't be used on Mac
switch (signal) {
case STKFLT:
case PWR:
Assumptions.assumeFalse(
OS.current() == OS.MAC,
String.format("Signal %s unknown on MacOS", signal)
);
break;
case BUS:
Assumptions.assumeFalse(
OS.current() == OS.MAC,
String.format("Signal %s already used by VM or OS", signal)
);
break;
default: //nop
}
}
}
9 changes: 7 additions & 2 deletions slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@
import java.util.concurrent.Callable;
import java.util.function.Supplier;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.MDC;

import static org.hamcrest.MatcherAssert.assertThat;

public class LoggingContextBuilderTest {

@Before
public void setUp() {
class LoggingContextBuilderTest {

@BeforeEach
void setUp() {
MDC.clear();
}

@Test
public void testWithMDC() {
void testWithMDC() {
final String value = UUID.randomUUID().toString();
Map<String, String> ctx = new HashMap<>();
ctx.put("mdc", value);
Expand All @@ -49,7 +50,7 @@ public void testWithMDC() {
}

@Test
public void testWrapRunnable() {
void testWrapRunnable() {
final String value = UUID.randomUUID().toString();
final String value2 = UUID.randomUUID().toString();
MDC.put("mdc", value);
Expand All @@ -61,7 +62,7 @@ public void testWrapRunnable() {
}

@Test
public void testCleanWrapRunnable() {
void testCleanWrapRunnable() {
final String value = UUID.randomUUID().toString();
final String value2 = UUID.randomUUID().toString();
MDC.put("mdc", value);
Expand All @@ -73,7 +74,7 @@ public void testCleanWrapRunnable() {
}

@Test
public void testWrapCallable() throws Exception {
void testWrapCallable() throws Exception {
final String value = UUID.randomUUID().toString();
final String value2 = UUID.randomUUID().toString();
MDC.put("mdc", value);
Expand All @@ -87,7 +88,7 @@ public void testWrapCallable() throws Exception {
}

@Test
public void testWrapFunction() {
void testWrapFunction() {
final String value = UUID.randomUUID().toString();
final String value2 = UUID.randomUUID().toString();
MDC.put("mdc", value);
Expand All @@ -102,7 +103,7 @@ public void testWrapFunction() {
}

@Test
public void testWrapSupplier() {
void testWrapSupplier() {
final String value = UUID.randomUUID().toString();
final String value2 = UUID.randomUUID().toString();
MDC.put("mdc", value);
Expand All @@ -116,7 +117,7 @@ public void testWrapSupplier() {
}

@Test
public void testWrapConsumer() {
void testWrapConsumer() {
final String value = UUID.randomUUID().toString();
final String value2 = UUID.randomUUID().toString();
MDC.put("mdc", value);
Expand Down
Loading