Java 11 migraiton: monad
This commit is contained in:
@@ -32,8 +32,7 @@ public class AppTest {
|
||||
|
||||
@Test
|
||||
public void testMain() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
App.main(new String[]{});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -23,13 +23,12 @@
|
||||
|
||||
package com.iluwatar.monad;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test for Monad Pattern
|
||||
*/
|
||||
@@ -37,27 +36,33 @@ public class MonadTest {
|
||||
|
||||
@Test
|
||||
public void testForInvalidName() {
|
||||
User tom = new User(null, 21, Sex.MALE, "tom@foo.bar");
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
Validator.of(tom).validate(User::getName, Objects::nonNull, "name cannot be null").get();
|
||||
});
|
||||
var tom = new User(null, 21, Sex.MALE, "tom@foo.bar");
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> Validator.of(tom)
|
||||
.validate(User::getName, Objects::nonNull, "name cannot be null")
|
||||
.get()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForInvalidAge() {
|
||||
User john = new User("John", 17, Sex.MALE, "john@qwe.bar");
|
||||
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();
|
||||
});
|
||||
var john = new User("John", 17, Sex.MALE, "john@qwe.bar");
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> Validator.of(john)
|
||||
.validate(User::getName, Objects::nonNull, "name cannot be null")
|
||||
.validate(User::getAge, age -> age > 21, "user is underage")
|
||||
.get()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForValid() {
|
||||
User sarah = new User("Sarah", 42, Sex.FEMALE, "sarah@det.org");
|
||||
User validated = Validator.of(sarah).validate(User::getName, Objects::nonNull, "name cannot be null")
|
||||
.validate(User::getAge, age -> age > 21, "user is underaged")
|
||||
var sarah = new User("Sarah", 42, Sex.FEMALE, "sarah@det.org");
|
||||
var validated = Validator.of(sarah)
|
||||
.validate(User::getName, Objects::nonNull, "name cannot be null")
|
||||
.validate(User::getAge, age -> age > 21, "user is underage")
|
||||
.validate(User::getSex, sex -> sex == Sex.FEMALE, "user is not female")
|
||||
.validate(User::getEmail, email -> email.contains("@"), "email does not contain @ sign")
|
||||
.get();
|
||||
|
Reference in New Issue
Block a user