java/admin/src/test/java/com/exadel/frs/validation/EmailValidatorTest.java
<reponame>rohankumardubey/CompreFace/*
 * Copyright (c) 2020 the original author or authors
 *
 * 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
 *
 *      https://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.exadel.frs.validation;

import static com.exadel.frs.validation.EmailValidator.isInvalid;
import static com.exadel.frs.validation.EmailValidator.isValid;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

class EmailValidatorTest {

    private static List<String> VALID_EMAILS;
    private static List<String> INVALID_EMAILS;

    @BeforeAll
    public static void init() {
        VALID_EMAILS = List.of(
                "kenaa@example.com",
                "envkt@example.com",
                "ychag@example.com",
                "hzdkv@example.com",
                "lyhxr@example.com",
                "envkt@example.com",
                "efpyi@example.com",
                "dycjh@example.com",
                "efpyi@example.com",
                "hzdkv@example.com",
                "hzdkv@example.com"
        );

        INVALID_EMAILS = List.of(
                "tester",
                "tester@.com.my",
                "tester123@gmail.a",
                "tester123@.com",
                "tester123@.com.com",
                "envkt@example.com",
                "tester()*@gmail.com",
                "upchh@example.com",
                "tester.upchh@example.com",
                "tester.@gmail.com",
                "tester@nnheo@example.com",
                "tester@gmail.com.1a",
                "",
                "   "
        );
    }

    @Test
    void validEmailsAreValid() {
        assertThat(VALID_EMAILS).allSatisfy(
                email -> assertThat(isValid(email)).isTrue()
        );
    }

    @Test
    void invalidEmailsAreNotValid() {
        assertThat(INVALID_EMAILS).allSatisfy(
                email -> assertThat(isValid(email)).isFalse()
        );
    }

    @Test
    void invalidEmailsAreInvalid() {
        assertThat(INVALID_EMAILS).allSatisfy(
                email -> assertThat(isInvalid(email)).isTrue()
        );
    }

    @Test
    void validEmailsAreNotInvalid() {
        assertThat(VALID_EMAILS).allSatisfy(
                email -> assertThat(isInvalid(email)).isFalse()
        );
    }
}