package com.redfin.validity;

import com.redfin.validity.FailedValidationExecutor;
import com.redfin.validity.ValidityUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

final class VerifiableFactoryTest {

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Test requirements
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    private static final String VALID_MESSAGE = "hello";
    private static final FailedValidationExecutor<IllegalArgumentException> VALIDATION_EXECUTOR = new FailedValidationExecutor<IllegalArgumentException>() {
        @Override
        public <T> void fail(String expected, T subject, String message) throws IllegalArgumentException {
            throw new IllegalArgumentException(expected + subject + message);
        }
    };

    private static final class TestVerifiableFactory extends VerifiableFactory<IllegalArgumentException> {
        private TestVerifiableFactory(String message, FailedValidationExecutor<IllegalArgumentException> failedValidationExecutor) {
            super(message, failedValidationExecutor);
        }
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Test cases
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    @Test
    void testCanInstantiateWithValidArguments() {
        Assertions.assertNotNull(new TestVerifiableFactory(VALID_MESSAGE, VALIDATION_EXECUTOR),
                                 "Should be able to instantiate a VerifiableFactory with valid arguments.");
    }

    @Test
    void testCanInstantiateWithNullMessage() {
        Assertions.assertNotNull(new TestVerifiableFactory(null, VALIDATION_EXECUTOR),
                                 "Should be able to instantiate a VerifiableFactory with a null message.");
    }

    @Test
    void testConstructorThrowsExceptionForNullValidationExecutor() {
        NullPointerException exception = Assertions.expectThrows(NullPointerException.class,
                                                                 () -> new TestVerifiableFactory(VALID_MESSAGE, null));
        Assertions.assertEquals(ValidityUtils.nullArgumentMessage("failedValidationExecutor"),
                                exception.getMessage(),
                                "Should not be able to instantiate a VerifiableFactory with a null failed validation executor.");
    }
}

/*
 * Copyright: (c) 2016 Redfin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.redfin.validity;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

final class VerifiableFactoryTest {

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Test requirements
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    private static final String VALID_MESSAGE = "hello";
    private static final FailedValidationExecutor<IllegalArgumentException> VALIDATION_EXECUTOR = new FailedValidationExecutor<IllegalArgumentException>() {
        @Override
        public <T> void fail(String expected, T subject, String message) throws IllegalArgumentException {
            throw new IllegalArgumentException(expected + subject + message);
        }
    };

    private static final class TestVerifiableFactory extends VerifiableFactory<IllegalArgumentException> {
        private TestVerifiableFactory(String message, FailedValidationExecutor<IllegalArgumentException> failedValidationExecutor) {
            super(message, failedValidationExecutor);
        }
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Test cases
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    @Test
    void testCanInstantiateWithValidArguments() {
        Assertions.assertNotNull(new TestVerifiableFactory(VALID_MESSAGE, VALIDATION_EXECUTOR),
                                 "Should be able to instantiate a VerifiableFactory with valid arguments.");
    }

    @Test
    void testCanInstantiateWithNullMessage() {
        Assertions.assertNotNull(new TestVerifiableFactory(null, VALIDATION_EXECUTOR),
                                 "Should be able to instantiate a VerifiableFactory with a null message.");
    }

    @Test
    void testConstructorThrowsExceptionForNullValidationExecutor() {
        NullPointerException exception = Assertions.expectThrows(NullPointerException.class,
                                                                 () -> new TestVerifiableFactory(VALID_MESSAGE, null));
        Assertions.assertEquals(ValidityUtils.nullArgumentMessage("failedValidationExecutor"),
                                exception.getMessage(),
                                "Should not be able to instantiate a VerifiableFactory with a null failed validation executor.");
    }
}

Add missing license comment