|
|
@@ -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));
|
|
|
}
|
|
|
}
|