瀏覽代碼

Upgrade to using JUnit5

Sam Jaffe 5 年之前
父節點
當前提交
c98e4b834a

+ 1 - 0
lombok.config

@@ -0,0 +1 @@
+lombok.addLombokGeneratedAnnotation = true

+ 11 - 11
pom.xml

@@ -23,7 +23,7 @@
 			<plugin>
 				<groupId>org.projectlombok</groupId>
 				<artifactId>lombok-maven-plugin</artifactId>
-				<version>1.16.18.0</version>
+				<version>1.18.16.0</version>
 				<executions>
 					<execution>
 						<id>delombok</id>
@@ -75,21 +75,21 @@
 	
 	<dependencies>
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.12</version>
-      <scope>test</scope>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-api</artifactId>
+        <version>5.7.0</version>
+        <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.projectlombok</groupId>
-      <artifactId>lombok</artifactId>
-      <version>1.16.18</version>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-engine</artifactId>
+        <version>5.7.0</version>
+        <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.projectlombok</groupId>
-      <artifactId>lombok-maven-plugin</artifactId>
-      <version>1.16.18.0</version>
-      <type>maven-plugin</type>
+      <artifactId>lombok</artifactId>
+      <version>1.18.16</version>
     </dependency>
 	</dependencies>
 	<version>0.2</version>

+ 4 - 4
src/test/java/org/leumasjaffe/container/EitherFunctionalTest.java

@@ -4,14 +4,14 @@ import static org.hamcrest.CoreMatchers.*;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.fail;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class EitherFunctionalTest {
+class EitherFunctionalTest {
 	String str;
 	Integer i;
 	
-	@Before
+	@BeforeEach
 	public void setUp() {
 		str = "testing";
 		i = Integer.valueOf(500);

+ 4 - 4
src/test/java/org/leumasjaffe/container/EitherStateTest.java

@@ -3,14 +3,14 @@ package org.leumasjaffe.container;
 import static org.hamcrest.CoreMatchers.*;
 import static org.hamcrest.MatcherAssert.assertThat;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class EitherStateTest {
+class EitherStateTest {
 	String str;
 	Integer i;
 	
-	@Before
+	@BeforeEach
 	public void setUp() {
 		str = "testing";
 		i = Integer.valueOf(500);

+ 0 - 13
src/test/java/org/leumasjaffe/container/EitherTestSuite.java

@@ -1,13 +0,0 @@
-package org.leumasjaffe.container;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses(value = {
-		EitherStateTest.class,
-		EitherValidationTest.class,
-		EitherFunctionalTest.class
-})
-public class EitherTestSuite {
-}

+ 30 - 41
src/test/java/org/leumasjaffe/container/EitherValidationTest.java

@@ -1,99 +1,88 @@
 package org.leumasjaffe.container;
 
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
-public class EitherValidationTest {
+class EitherValidationTest {
 	String str;
 	Integer i;
 	
-	@Before
+	@BeforeEach
 	public void setUp() {
 		str = "testing";
 		i = Integer.valueOf(500);
 	}
 	
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void testEitherLeftNullThrows() {
-		Either.ofLeft(null);
-		fail();
+		assertThrows(NullPointerException.class, () -> Either.ofLeft(null));
 	}
 	
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void testEitherRightNullThrows() {
-		Either.ofRight(null);
-		fail();
+		assertThrows(NullPointerException.class, () -> Either.ofRight(null));
 	}
 
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void testEitherSetLeftWithNullThrows() {
 		Either<String, Integer> either = Either.ofRight(i);
-		either.setLeft(null);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.setLeft(null));
 	}
 	
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void testEitherSetRightWithNullThrows() {
 		Either<String, Integer> either = Either.ofLeft(str);
-		either.setRight(null);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.setRight(null));
 	}
 	
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void consumeWithNullLeftFunctionThrowsEvenIfUnneeded() {
 		Either<String, Integer> either = Either.ofRight(i);
-		either.consume(null, i -> fail());
-		fail();
+		assertThrows(NullPointerException.class, () -> either.consume(null, i -> fail()));
 	}
 	
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void consumeWithNullRightFunctionThrowsEvenIfUnneeded() {
 		Either<String, Integer> either = Either.ofLeft(str);
-		either.consume(s -> fail(), null);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.consume(s -> fail(), null));
 	}
 
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void mapWithNullLeftFunctionThrowsEvenIfUnneeded() {
 		Either<String, Integer> either = Either.ofRight(i);
-		either.map(null, i -> str);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.map(null, i -> str));
 	}
 
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void mapWithNullRightFunctionThrowsEvenIfUnneeded() {
 		Either<String, Integer> either = Either.ofLeft(str);
-		either.map(s -> i, null);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.map(s -> i, null));
 	}
 	
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void mapLeftWithNullFunctionThrows() {
 		Either<String, Integer> either = Either.ofLeft(str);
-		either.mapLeft(null);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.mapLeft(null));
 	}
 	
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void mapRightWithNullFunctionThrows() {
 		Either<String, Integer> either = Either.ofRight(i);
-		either.mapRight(null);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.mapRight(null));
 	}
 	
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void unifyWithNullLeftFunctionThrowsEvenIfUnneeded() {
 		Either<String, Integer> either = Either.ofRight(i);
-		either.unify(null, i -> "int:" + i);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.unify(null, i -> "int:" + i));
 	}
 
-	@Test(expected=NullPointerException.class)
+	@Test
 	public void unifyWithNullRightFunctionThrowsEvenIfUnneeded() {
 		Either<String, Integer> either = Either.ofLeft(str);
-		either.unify(s -> "str:" + s, null);
-		fail();
+		assertThrows(NullPointerException.class, () -> either.unify(s -> "str:" + s, null));
 	}
 }

+ 10 - 0
src/test/java/org/leumasjaffe/container/TestSuite.java

@@ -0,0 +1,10 @@
+package org.leumasjaffe.container;
+
+import org.junit.platform.runner.JUnitPlatform;
+import org.junit.platform.suite.api.SelectPackages;
+import org.junit.runner.RunWith;
+
+@RunWith(JUnitPlatform.class)
+@SelectPackages("org.leumasjaffe.container")
+public class TestSuite {
+}