Skip to content

Upgrade to JUnit5 #2810

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

Merged
merged 1 commit into from
Sep 11, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/build-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11', '17']
java: [ '8', '11', '17' ]
architecture: [ 'x64' ]
name: Build with JDK ${{ matrix.java }} on ${{ matrix.architecture }}
steps:
- uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: 'temurin'
java-version: ${{ matrix.java }}
architecture: ${{ matrix.architecture }}
cache: 'maven'
Expand Down
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ We use these goals frequently to keep the dependencies and plugins up-to-date:
<eclipse.lifecycle.mapping.version>1.0.0</eclipse.lifecycle.mapping.version>
<java.version>1.8</java.version>
<jmh.version>1.21</jmh.version>
<junit.version>4.13-beta-1</junit.version>
<junit.version>5.11.0</junit.version>
<maven.enforcer.version>3.0.0-M2</maven.enforcer.version>
<maven.build-helper.version>3.0.0</maven.build-helper.version>
<maven.bundle.version>5.1.1</maven.bundle.version>
Expand All @@ -93,9 +93,10 @@ We use these goals frequently to keep the dependencies and plugins up-to-date:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
Expand Down
4 changes: 2 additions & 2 deletions vavr-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<version>15.0</version>
</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,7 +20,7 @@
package io.vavr.collection;

import io.vavr.JmhRunner;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package io.vavr.collection;

import io.vavr.JmhRunner;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;

import static io.vavr.JmhRunner.create;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package io.vavr.collection;

import io.vavr.JmhRunner;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;

import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package io.vavr.collection;

import io.vavr.JmhRunner;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;

import static io.vavr.JmhRunner.create;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,34 @@
package io.vavr.collection;

import io.vavr.JmhRunner;
import org.junit.Assert;
import org.junit.Test;
import org.openjdk.jmh.annotations.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;

import java.util.Random;

import static io.vavr.JmhRunner.Includes.*;
import static io.vavr.JmhRunner.Includes.JAVA;
import static io.vavr.JmhRunner.Includes.SCALA;
import static io.vavr.JmhRunner.Includes.VAVR;
import static io.vavr.JmhRunner.getRandomValues;

@SuppressWarnings({ "ALL", "unchecked", "rawtypes" })
@SuppressWarnings({"ALL", "unchecked", "rawtypes"})
public class IteratorBenchmark {

static final Array<Class<?>> CLASSES = Array.of(
Sliding.class,
Concat.class
Sliding.class,
Concat.class
);

@Test
public void testAsserts() { JmhRunner.runDebugWithAsserts(CLASSES); }
public void testAsserts() {
JmhRunner.runDebugWithAsserts(CLASSES);
}

public static void main(String... args) {
JmhRunner.runDebugWithAsserts(CLASSES);
Expand All @@ -60,7 +68,8 @@ public static class Base {
public void setup() {
final Random random = new Random(0);
ELEMENTS = getRandomValues(CONTAINER_SIZE, false, random);
scalaIterator = (scala.collection.Iterator<Integer>) (Object) scala.collection.mutable.WrappedArray$.MODULE$.make(ELEMENTS).iterator();
scalaIterator = (scala.collection.Iterator<Integer>) (Object) scala.collection.mutable.WrappedArray$.MODULE$.make(ELEMENTS)
.iterator();
vavrIterator = Iterator.of(ELEMENTS);
}
}
Expand All @@ -87,32 +96,32 @@ public void vavr_persistent(Blackhole bh) {
@State(Scope.Benchmark)
public static class Concat {

@Param({ "10", "20" , "100", "1000" })
@Param({"10", "20", "100", "1000"})
private int size;

@Benchmark
public void vavr_persistent(Blackhole bh) {
Iterator<Integer> iterator = Iterator.range(0, size)
.foldLeft(Iterator.empty(), (result, __) -> result.concat(Iterator.of(1)));
.foldLeft(Iterator.empty(), (result, __) -> result.concat(Iterator.of(1)));

long sum = 0;
while (iterator.hasNext()) {
sum += iterator.next();
}
Assert.assertEquals(size, sum);
Assertions.assertEquals(size, sum);
}

@Benchmark
public void scala_persistent(Blackhole bh) {
final scala.collection.Iterator<Integer> iterator = scala.collection.Iterator.range(0, size)
.foldLeft((scala.collection.Iterator<Integer>) (Object) scala.collection.Iterator.empty(),
(result, i) -> result.$plus$plus(() -> scala.collection.Iterator.single(1)));
.foldLeft((scala.collection.Iterator<Integer>) (Object) scala.collection.Iterator.empty(),
(result, i) -> result.$plus$plus(() -> scala.collection.Iterator.single(1)));

long sum = 0;
while (iterator.hasNext()) {
sum += iterator.next();
}
Assert.assertEquals(size, sum);
Assertions.assertEquals(size, sum);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package io.vavr.collection;

import io.vavr.JmhRunner;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import io.vavr.Function1;
import io.vavr.JmhRunner;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import fj.P;
import io.vavr.JmhRunner;
import io.vavr.Tuple2;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;
import scala.math.Ordering;
import scala.math.Ordering$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package io.vavr.collection;

import io.vavr.JmhRunner;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import scala.collection.generic.CanBuildFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.vavr.Lazy;
import io.vavr.collection.Array;
import io.vavr.collection.Iterator;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import io.vavr.JmhRunner;
import io.vavr.collection.Array;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import io.vavr.JmhRunner;
import io.vavr.collection.Array;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import io.vavr.JmhRunner;
import io.vavr.collection.Array;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.vavr.JmhRunner;
import io.vavr.Tuple;
import io.vavr.collection.Array;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
Expand Down
4 changes: 2 additions & 2 deletions vavr-match-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,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
31 changes: 18 additions & 13 deletions vavr-test/generator/Generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,9 @@ def generateTestClasses(): Unit = {
val tuple = im.getType("io.vavr.Tuple")

// test classes
val test = im.getType("org.junit.Test")
val test = im.getType("org.junit.jupiter.api.Test")
val assertThat = im.getStatic("org.assertj.core.api.Assertions.assertThat")
val assertThrows = im.getStatic("org.junit.jupiter.api.Assertions.assertThrows")
val woops = "yay! (this is a negative test)"

xs"""
Expand All @@ -368,14 +369,14 @@ def generateTestClasses(): Unit = {

static final Arbitrary<Object> OBJECTS = Gen.of(null).arbitrary();

@$test(expected = NullPointerException.class)
@$test
public void shouldThrowWhenPropertyNameIsNull() {
Property.def(null);
$assertThrows(${im.getType("java.lang.NullPointerException")}.class, () -> Property.def(null));
}

@$test(expected = IllegalArgumentException.class)
@$test
public void shouldThrowWhenPropertyNameIsEmpty() {
Property.def("");
$assertThrows(${im.getType("java.lang.IllegalArgumentException")}.class, () -> Property.def(""));
}

// -- Property.check methods
Expand All @@ -394,9 +395,12 @@ def generateTestClasses(): Unit = {
$assertThat(result.isExhausted()).isTrue();
}

@$test(expected = IllegalArgumentException.class)
@$test
public void shouldThrowOnCheckGivenNegativeTries() {
Property.def("test").forAll(OBJECTS).suchThat(tautology()).check(0, -1);
$assertThrows(${im.getType("java.lang.IllegalArgumentException")}.class, () -> Property.def("test")
.forAll(OBJECTS)
.suchThat(tautology())
.check(0, -1));
}

@$test
Expand Down Expand Up @@ -577,8 +581,9 @@ def generateTestClasses(): Unit = {
val args = (1 to i).gen(j => s"o$j")(", ")

// test classes
val test = im.getType("org.junit.Test")
val test = im.getType("org.junit.jupiter.api.Test")
val assertThat = im.getStatic("org.assertj.core.api.Assertions.assertThat")
val assertThrows = im.getStatic("org.junit.jupiter.api.Assertions.assertThrows")
val woops = "yay! (this is a negative test)"

xs"""
Expand Down Expand Up @@ -645,12 +650,12 @@ def generateTestClasses(): Unit = {
$assertThat(result.isExhausted()).isTrue();
}

@$test(expected = IllegalArgumentException.class)
@$test
public void shouldThrowOnProperty${i}CheckGivenNegativeTries() {
Property.def("test")
.forAll($arbitraries)
.suchThat(($args) -> true)
.check(Checkable.RNG.get(), 0, -1);
$assertThrows(${im.getType("java.lang.IllegalArgumentException")}.class, () -> Property.def("test")
.forAll($arbitraries)
.suchThat(($args) -> true)
.check(Checkable.RNG.get(), 0, -1));
}

@$test
Expand Down
4 changes: 2 additions & 2 deletions vavr-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
14 changes: 8 additions & 6 deletions vavr-test/src-gen/test/java/io/vavr/test/PropertyCheck1Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
\*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import io.vavr.CheckedFunction1;
import org.junit.Test;
import java.lang.IllegalArgumentException;
import org.junit.jupiter.api.Test;

public class PropertyCheck1Test {

Expand Down Expand Up @@ -91,12 +93,12 @@ public void shouldCheckProperty1ImplicationWithFalsePrecondition() {
assertThat(result.isExhausted()).isTrue();
}

@Test(expected = IllegalArgumentException.class)
@Test
public void shouldThrowOnProperty1CheckGivenNegativeTries() {
Property.def("test")
.forAll(OBJECTS)
.suchThat((o1) -> true)
.check(Checkable.RNG.get(), 0, -1);
assertThrows(IllegalArgumentException.class, () -> Property.def("test")
.forAll(OBJECTS)
.suchThat((o1) -> true)
.check(Checkable.RNG.get(), 0, -1));
}

@Test
Expand Down
Loading