Migrate to JUnit5

This commit is contained in:
Artur Mogozov
2017-12-31 16:29:48 +09:00
parent a20e54d0a7
commit 6694d742a3
408 changed files with 2656 additions and 2165 deletions

View File

@ -22,7 +22,7 @@
*/
package com.iluwatar.monad;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Application Test

View File

@ -22,36 +22,34 @@
*/
package com.iluwatar.monad;
import junit.framework.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Test for Monad Pattern
*/
public class MonadTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testForInvalidName() {
thrown.expect(IllegalStateException.class);
User tom = new User(null, 21, Sex.MALE, "tom@foo.bar");
Validator.of(tom).validate(User::getName, Objects::nonNull, "name cannot be null").get();
assertThrows(IllegalStateException.class, () -> {
Validator.of(tom).validate(User::getName, Objects::nonNull, "name cannot be null").get();
});
}
@Test
public void testForInvalidAge() {
thrown.expect(IllegalStateException.class);
User john = new User("John", 17, Sex.MALE, "john@qwe.bar");
Validator.of(john).validate(User::getName, Objects::nonNull, "name cannot be null")
.validate(User::getAge, age -> age > 21, "user is underaged")
.get();
assertThrows(IllegalStateException.class, () -> {
Validator.of(john).validate(User::getName, Objects::nonNull, "name cannot be null")
.validate(User::getAge, age -> age > 21, "user is underaged")
.get();
});
}
@Test
@ -62,6 +60,6 @@ public class MonadTest {
.validate(User::getSex, sex -> sex == Sex.FEMALE, "user is not female")
.validate(User::getEmail, email -> email.contains("@"), "email does not contain @ sign")
.get();
Assert.assertSame(validated, sarah);
assertSame(validated, sarah);
}
}