Skip to content

Refactor Junit4 to Junit 5 #440

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

Open
wants to merge 1 commit into
base: series/5.x
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
16 changes: 8 additions & 8 deletions consume/src/test/java/fj/EmptyTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package fj;

import org.junit.Ignore;
import org.junit.Test;

import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class EmptyTest {

@Ignore @Test
public void missing() {
Assert.fail("not implemented");
@Disabled
@Test
void missing() {
Assertions.fail("not implemented");

}
}
}
73 changes: 37 additions & 36 deletions core/src/test/java/fj/ClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,51 @@
import fj.data.Natural;
import fj.data.Option;
import fj.data.Tree;
import org.junit.Test;

import java.lang.reflect.Type;

import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.Iterator;

import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class ClassTest {
@Test
public void testInheritance() {
Class<Natural> c = Class.clas(Natural.class);
List<Class<? super Natural>> l = c.inheritance();
assertThat(l.length(), is(3));
}

@Test
public void testClassParameters() {
Class<? extends Option> c = Class.clas(Option.none().getClass());
Tree<Type> cp = c.classParameters();
assertThat(cp.length(), is(1));
}

@Test
public void testSuperclassParameters() {
Class<? extends Option> c = Class.clas(Option.none().getClass());
Tree<Type> cp = c.superclassParameters();
assertThat(cp.length(), is(2));
}

@Test
public void testInterfaceParameters() {
Class<? extends Option> c = Class.clas(Option.none().getClass());
List<Tree<Type>> l =c.interfaceParameters();
assertThat(l.length(), is(0));
}

@Test
public void testTypeParameterTree() {
Class<? extends Option> c = Class.clas(Option.none().getClass());
Collection<Type> coll = c.classParameters().toCollection();
for (Type t: coll) {
assertThat(Class.typeParameterTree(t).toString(), is("Tree(class fj.data.Option$None)"));
}
@Test
void testInheritance() {
Class<Natural> c = Class.clas(Natural.class);
List<Class<? super Natural>> l = c.inheritance();
assertThat(l.length(), is(3));
}

@Test
void testClassParameters() {
Class<? extends Option> c = Class.clas(Option.none().getClass());
Tree<Type> cp = c.classParameters();
assertThat(cp.length(), is(1));
}

@Test
void testSuperclassParameters() {
Class<? extends Option> c = Class.clas(Option.none().getClass());
Tree<Type> cp = c.superclassParameters();
assertThat(cp.length(), is(2));
}

@Test
void testInterfaceParameters() {
Class<? extends Option> c = Class.clas(Option.none().getClass());
List<Tree<Type>> l = c.interfaceParameters();
assertThat(l.length(), is(0));
}

@Test
void testTypeParameterTree() {
Class<? extends Option> c = Class.clas(Option.none().getClass());
Collection<Type> coll = c.classParameters().toCollection();
for (Type t : coll) {
assertThat(Class.typeParameterTree(t).toString(), is("Tree(class fj.data.Option$None)"));
}
}
}
45 changes: 23 additions & 22 deletions core/src/test/java/fj/DigitTest.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package fj;

import fj.data.Option;
import org.junit.Test;
import fj.data.Option;

import org.junit.jupiter.api.Test;

import static fj.data.Array.range;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class DigitTest {
@Test
public void testInteger() {
for (Integer i: range(0, 10)) {
assertThat(Digit.fromLong(i).toLong(), is(i.longValue()));
}
}

@Test
public void testChar() {
for (Integer i: range(0, 10)) {
Character c = Character.forDigit(i, 10);
assertThat(Digit.fromChar(c).some().toChar(), is(c));
}
import static org.hamcrest.MatcherAssert.assertThat;

public class DigitTest {
@Test
void testInteger() {
for (Integer i : range(0, 10)) {
assertThat(Digit.fromLong(i).toLong(), is(i.longValue()));
}

@Test
public void testCharNone() {
assertThat(Digit.fromChar('x'), is(Option.none()));
}

@Test
void testChar() {
for (Integer i : range(0, 10)) {
Character c = Character.forDigit(i, 10);
assertThat(Digit.fromChar(c).some().toChar(), is(c));
}
}

@Test
void testCharNone() {
assertThat(Digit.fromChar('x'), is(Option.none()));
}
}
8 changes: 4 additions & 4 deletions core/src/test/java/fj/EqualTest.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package fj;

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

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class EqualTest {
@Test
public void contramapShouldWork() {
void contramapShouldWork() {
Equal<String> equalByLength = Equal.contramap(String::length, Equal.intEqual);

assertThat(equalByLength.eq("str1", "str2"), is(true));
assertThat(equalByLength.eq("str1", "str11"), is(false));
}

@Test
public void thenShouldWork() {
void thenShouldWork() {
Equal<String> equalByLengthThenLastDigit = Equal.on(String::length, Equal.intEqual)
.then(s -> s.charAt(s.length() - 1), Equal.charEqual).equal();
.then(s -> s.charAt(s.length() - 1), Equal.charEqual).equal();

assertThat(equalByLengthThenLastDigit.eq("str1", "spr1"), is(true));
assertThat(equalByLengthThenLastDigit.eq("str1", "str2"), is(false));
Expand Down
39 changes: 20 additions & 19 deletions core/src/test/java/fj/FFunctionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

import fj.data.Tree;
import fj.data.TreeZipper;
import org.junit.Test;

import org.junit.jupiter.api.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class FFunctionsTest {

@Test
public void testTreeK() {
final Tree<Integer> t1 = Function.<Integer>identity().treeK().f(1);
final Tree<Integer> t2 = Function.<Integer>identity().treeK().f(2);
F<Integer, Integer> f = i -> i + 1;
F<Integer, Integer> g = i -> i * 1;
assertThat(f.mapTree().f(t1),
is(g.mapTree().f(t2)));
}
@Test
void testTreeK() {
final Tree<Integer> t1 = Function.<Integer>identity().treeK().f(1);
final Tree<Integer> t2 = Function.<Integer>identity().treeK().f(2);
F<Integer, Integer> f = i -> i + 1;
F<Integer, Integer> g = i -> i * 1;
assertThat(f.mapTree().f(t1),
is(g.mapTree().f(t2)));
}

@Test
public void testTreeZipperK() {
final TreeZipper<Integer> tz1 = Function.<Integer>identity().treeZipperK().f(1);
final TreeZipper<Integer> tz2 = Function.<Integer>identity().treeZipperK().f(2);
F<Integer, Integer> f = i -> i + 1;
F<Integer, Integer> g = i -> i * 1;
assertThat(f.mapTreeZipper().f(tz1),
is(g.mapTreeZipper().f(tz2)));
}
@Test
void testTreeZipperK() {
final TreeZipper<Integer> tz1 = Function.<Integer>identity().treeZipperK().f(1);
final TreeZipper<Integer> tz2 = Function.<Integer>identity().treeZipperK().f(2);
F<Integer, Integer> f = i -> i + 1;
F<Integer, Integer> g = i -> i * 1;
assertThat(f.mapTreeZipper().f(tz1),
is(g.mapTreeZipper().f(tz2)));
}
}
13 changes: 7 additions & 6 deletions core/src/test/java/fj/MonoidTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import fj.data.Option;
import fj.data.Set;
import fj.data.Stream;
import org.junit.Test;

import org.junit.jupiter.api.Test;

import static fj.data.Option.some;
import static org.hamcrest.core.Is.is;
Expand All @@ -13,14 +14,14 @@
public class MonoidTest {

@Test
public void lifted_sum_of_two_numbers() {
void lifted_sum_of_two_numbers() {
Monoid<Option<Integer>> optionMonoid = Semigroup.intAdditionSemigroup.lift();
assertThat(optionMonoid.sum(some(3), some(5)), is(some(8)));
assertThat(optionMonoid.sumLeft(Stream.arrayStream(some(3), some(5))), is(some(8)));
}

@Test
public void intersection_monoid_test() {
void intersection_monoid_test() {
Bounded<Integer> integersBounded = Bounded.bounded(0, 10);
Monoid<Set<Integer>> intersectionMonoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator);
Set<Integer> first = Set.set(Ord.intOrd, 1, 2, 3, 4);
Expand All @@ -30,7 +31,7 @@ public void intersection_monoid_test() {
}

@Test
public void union_monoid_test() {
void union_monoid_test() {
Monoid<Set<Integer>> unionMonoid = Monoid.setMonoid(Ord.intOrd);
Set<Integer> first = Set.set(Ord.intOrd, 1, 2, 3, 4);
Set<Integer> second = Set.set(Ord.intOrd, 3, 4, 5, 6);
Expand All @@ -39,7 +40,7 @@ public void union_monoid_test() {
}

@Test
public void intersection_monoid_zero_test() {
void intersection_monoid_zero_test() {
Bounded<Integer> integersBounded = Bounded.bounded(0, 10);
Monoid<Set<Integer>> monoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator);
Set<Integer> set = Set.set(Ord.intOrd, 7, 8, 9, 10);
Expand All @@ -48,7 +49,7 @@ public void intersection_monoid_zero_test() {
}

@Test
public void union_monoid_zero_test() {
void union_monoid_zero_test() {
Monoid<Set<Integer>> monoid = Monoid.setMonoid(Ord.intOrd);
Set<Integer> set = Set.set(Ord.intOrd, 1, 2, 3, 4);
Set<Integer> zero = monoid.zero();
Expand Down
12 changes: 6 additions & 6 deletions core/src/test/java/fj/OrdTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package fj;

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

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class OrdTest {

@Test
public void isGreaterThan() {
void isGreaterThan() {
F<Long, Boolean> pred = Ord.longOrd.isGreaterThan(1L);

assertThat(pred.f(0L), is(false));
Expand All @@ -17,7 +17,7 @@ public void isGreaterThan() {
}

@Test
public void isLessThan() {
void isLessThan() {
F<Long, Boolean> pred = Ord.longOrd.isLessThan(1L);

assertThat(pred.f(0L), is(true));
Expand All @@ -26,17 +26,17 @@ public void isLessThan() {
}

@Test
public void contramapShouldWork() {
void contramapShouldWork() {
Ord<String> lengthOrd = Ord.contramap(String::length, Ord.intOrd);

assertThat(lengthOrd.compare("str", "rts"), is(Ordering.EQ));
assertThat(lengthOrd.compare("strlong", "str"), is(Ordering.GT));
}

@Test
public void thenShouldWork() {
void thenShouldWork() {
Ord<String> lengthThenLastDigitOrd = Ord.on(String::length, Ord.intOrd)
.then(s -> s.charAt(s.length() - 1), Ord.charOrd).ord();
.then(s -> s.charAt(s.length() - 1), Ord.charOrd).ord();

assertThat(lengthThenLastDigitOrd.compare("str", "dyr"), is(Ordering.EQ));
assertThat(lengthThenLastDigitOrd.compare("stt", "str"), is(Ordering.GT));
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/fj/OrderingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.hamcrest.Matcher;
import org.hamcrest.core.Is;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static fj.Ordering.EQ;
import static fj.Ordering.GT;
Expand All @@ -13,7 +13,7 @@
public class OrderingTest {

@Test
public void reverse() throws Exception {
void reverse() throws Exception {
assertThat(GT.reverse(), is(LT));
assertThat(LT.reverse(), is(GT));
assertThat(EQ.reverse(), is(EQ));
Expand Down
13 changes: 7 additions & 6 deletions core/src/test/java/fj/P1Test.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fj;

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

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -10,7 +11,7 @@
public final class P1Test {

@Test
public void bug105() throws Exception {
void bug105() throws Exception {
final P1<String> p1 = P.weakMemo(() -> "Foo");
final AtomicInteger nullCounter = new AtomicInteger();
ExecutorService executorService = Executors.newCachedThreadPool();
Expand All @@ -26,14 +27,14 @@ public void bug105() throws Exception {
executorService.shutdown();
executorService.awaitTermination(10, TimeUnit.DAYS);

org.junit.Assert.assertEquals("Race condition in P1.memo()", 0, nullCounter.get());
Assertions.assertEquals(0, nullCounter.get(), "Race condition in P1.memo()");
}

@Test
public void bug122() throws Exception {
void bug122() throws Exception {
final P1<Integer> p1a = P.lazy(() -> 1);
final P1<Integer> p1b = P.lazy(() -> 1);

org.junit.Assert.assertTrue(p1a + " and " + p1b + " should be equal by Object.equals", p1a.equals(p1b));
Assertions.assertTrue(p1a.equals(p1b), p1a + " and " + p1b + " should be equal by Object.equals");
}
}
Loading