// Path: src/main/java/org/paradise/domain/Car.java
// public class Car {
// 
//     private static Optional<Insurance> insurance;
// 
//     public Car(Insurance insurance) {
//         this.insurance = Optional.ofNullable(insurance);
//     }
// 
//     public static <U> Optional<Insurance> getInsurance(U u) {
//         return insurance;
//     }
// 
// }
// 
// Path: src/main/java/org/paradise/domain/Insurance.java
// public class Insurance {
// 
//     private static String name;
//     private static String policy;
// 
//     public Insurance(String name, String policy) {
//         this.name = name;
//         this.policy = policy;
//     }
// 
//     public static <U> String getName(U u) {
//         return name;
//     }
// 
//     public static <U> String getPolicy(U u) {
//         return policy;
//     }
// 
// }
// 
// Path: src/main/java/org/paradise/domain/Person.java
// public class Person {
// 
//     private String name;
//     private int age;
// 
//     private static Optional<Car> car;
// 
//     private static Address address;
// 
// 
//     public Person(Car car) {
//         this.car = Optional.ofNullable(car);
//     }
// 
//     public static <U> Optional<Car> getCar(U u) {
//         return car;
//     }
// 
//     public static <U> Try<Address> getAddress(U u) {
// 
//         return address == null
//                 ? new TryFailure<>(address).failure(u.toString(), new NullValueException("Address is NULL"))
//                 : new TrySuccess(address);
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public int getAge() {
//         return age;
//     }
// 
//     public void setAge(int age) {
//         this.age = age;
//     }
// 
//     @Override
//     public String toString() {
//         return "Person {" +
//                 "name = [" + name + ']' +
//                 ", age = [" + age + ']' +
//                 ", car = [" + car + ']' +
//                 ", address = [" + address + ']' +
//                 '}';
//     }
// 
// }
// 
// Path: src/main/java/org/paradise/monad/ValidationFailure.java
// public class ValidationFailure<L, A> extends Validation<L, A> {
// 
//     protected final L left;
// 
//     public ValidationFailure(L left, A value) {
//         super(value);
//         this.left = left;
//     }
// 
//     public <B> Validation<L, B> map(Function<? super A, ? extends B> mapper) {
//         return new ValidationFailure(left, mapper.apply(value));
//     }
// 
//     public <B> Validation<L, B> flatMap(Function<? super A, Validation<?, ? extends B>> mapper) {
//         Validation<?, ? extends B> result = mapper.apply(value);
// 
//         return result.isSuccess() ? new ValidationFailure(left, result.value) : new ValidationFailure(((ValidationFailure<L, B>) result).left, result.value);
//     }
// 
//     public boolean isSuccess() {
//         return false;
//     }
// 
// }
// 
// Path: src/main/java/org/paradise/monad/ValidationSuccess.java
// public class ValidationSuccess<L, A> extends Validation<L, A> {
// 
//     public ValidationSuccess(A value) {
//         super(value);
//     }
// 
//     public <B> Validation<L, B> map(Function<? super A, ? extends B> mapper) {
//         return success(mapper.apply(value));
//     }
// 
//     public <B> Validation<L, B> flatMap(Function<? super A, Validation<?, ? extends B>> mapper) {
//         return (Validation<L, B>) mapper.apply(value);
//     }
// 
//     public boolean isSuccess() {
//         return true;
//     }
// 
//     public static <L, A> ValidationSuccess<L, A> success(A value) {
//         return new ValidationSuccess<>(value);
//     }
// 
// }


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.paradise.domain.Car;
import org.paradise.domain.Insurance;
import org.paradise.domain.Person;
import org.paradise.monad.ValidationFailure;
import org.paradise.monad.ValidationSuccess;
import static org.junit.Assert.assertTrue;
package org.paradise.validator;



/**
 * Created by terrence on 12/03/2016.
 */
public class PersonValidatorTest {

    String insuranceName = "Pacific Insurance";
    String insurancePolicy = "Pacific Insurance Policy";

    Person person = new Person(new Car(new Insurance(insuranceName, insurancePolicy)));

    @Before
    public void setUp() throws Exception {

    }

    @After
    public void tearDown() throws Exception {

    }

    @Test
    public void testValidateAgePassed() throws Exception {

        person.setAge(1);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess);

        person.setAge(129);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess);

        person.setAge(100);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess);
    }

    @Test
    public void testValidateAgeFailed() throws Exception {

        person.setAge(0);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationFailure);

        person.setAge(130);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationFailure);

        person.setAge(-1);
// Path: src/main/java/org/paradise/domain/Car.java
// public class Car {
// 
//     private static Optional<Insurance> insurance;
// 
//     public Car(Insurance insurance) {
//         this.insurance = Optional.ofNullable(insurance);
//     }
// 
//     public static <U> Optional<Insurance> getInsurance(U u) {
//         return insurance;
//     }
// 
// }
// 
// Path: src/main/java/org/paradise/domain/Insurance.java
// public class Insurance {
// 
//     private static String name;
//     private static String policy;
// 
//     public Insurance(String name, String policy) {
//         this.name = name;
//         this.policy = policy;
//     }
// 
//     public static <U> String getName(U u) {
//         return name;
//     }
// 
//     public static <U> String getPolicy(U u) {
//         return policy;
//     }
// 
// }
// 
// Path: src/main/java/org/paradise/domain/Person.java
// public class Person {
// 
//     private String name;
//     private int age;
// 
//     private static Optional<Car> car;
// 
//     private static Address address;
// 
// 
//     public Person(Car car) {
//         this.car = Optional.ofNullable(car);
//     }
// 
//     public static <U> Optional<Car> getCar(U u) {
//         return car;
//     }
// 
//     public static <U> Try<Address> getAddress(U u) {
// 
//         return address == null
//                 ? new TryFailure<>(address).failure(u.toString(), new NullValueException("Address is NULL"))
//                 : new TrySuccess(address);
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public int getAge() {
//         return age;
//     }
// 
//     public void setAge(int age) {
//         this.age = age;
//     }
// 
//     @Override
//     public String toString() {
//         return "Person {" +
//                 "name = [" + name + ']' +
//                 ", age = [" + age + ']' +
//                 ", car = [" + car + ']' +
//                 ", address = [" + address + ']' +
//                 '}';
//     }
// 
// }
// 
// Path: src/main/java/org/paradise/monad/ValidationFailure.java
// public class ValidationFailure<L, A> extends Validation<L, A> {
// 
//     protected final L left;
// 
//     public ValidationFailure(L left, A value) {
//         super(value);
//         this.left = left;
//     }
// 
//     public <B> Validation<L, B> map(Function<? super A, ? extends B> mapper) {
//         return new ValidationFailure(left, mapper.apply(value));
//     }
// 
//     public <B> Validation<L, B> flatMap(Function<? super A, Validation<?, ? extends B>> mapper) {
//         Validation<?, ? extends B> result = mapper.apply(value);
// 
//         return result.isSuccess() ? new ValidationFailure(left, result.value) : new ValidationFailure(((ValidationFailure<L, B>) result).left, result.value);
//     }
// 
//     public boolean isSuccess() {
//         return false;
//     }
// 
// }
// 
// Path: src/main/java/org/paradise/monad/ValidationSuccess.java
// public class ValidationSuccess<L, A> extends Validation<L, A> {
// 
//     public ValidationSuccess(A value) {
//         super(value);
//     }
// 
//     public <B> Validation<L, B> map(Function<? super A, ? extends B> mapper) {
//         return success(mapper.apply(value));
//     }
// 
//     public <B> Validation<L, B> flatMap(Function<? super A, Validation<?, ? extends B>> mapper) {
//         return (Validation<L, B>) mapper.apply(value);
//     }
// 
//     public boolean isSuccess() {
//         return true;
//     }
// 
//     public static <L, A> ValidationSuccess<L, A> success(A value) {
//         return new ValidationSuccess<>(value);
//     }
// 
// }


// Path: src/test/java/org/paradise/validator/PersonValidatorTest.java
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.paradise.domain.Car;
import org.paradise.domain.Insurance;
import org.paradise.domain.Person;
import org.paradise.monad.ValidationFailure;
import org.paradise.monad.ValidationSuccess;
import static org.junit.Assert.assertTrue;

package org.paradise.validator;



/**
 * Created by terrence on 12/03/2016.
 */
public class PersonValidatorTest {

    String insuranceName = "Pacific Insurance";
    String insurancePolicy = "Pacific Insurance Policy";

    Person person = new Person(new Car(new Insurance(insuranceName, insurancePolicy)));

    @Before
    public void setUp() throws Exception {

    }

    @After
    public void tearDown() throws Exception {

    }

    @Test
    public void testValidateAgePassed() throws Exception {

        person.setAge(1);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess);

        person.setAge(129);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess);

        person.setAge(100);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess);
    }

    @Test
    public void testValidateAgeFailed() throws Exception {

        person.setAge(0);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationFailure);

        person.setAge(130);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationFailure);

        person.setAge(-1);
        assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationFailure);