/*
 * Copyright 2021, TeamDev. All rights reserved.
 *
 * 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
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.tools.protoc;

import com.google.common.collect.ImmutableMap;
import com.google.common.testing.NullPointerTester;
import com.google.common.truth.Truth;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.spine.code.proto.FileName;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import static io.spine.testing.Assertions.assertIllegalArgument;
import static io.spine.testing.DisplayNames.NOT_ACCEPT_NULLS;

@DisplayName("`MessageSelectorFactory` should")
final class MessageSelectorFactoryTest {

    private final MessageSelectorFactory factory = MessageSelectorFactory.INSTANCE;

    @CanIgnoreReturnValue
    private PatternSelector inFiles(ImmutableMap<String, String> conf) {
        return factory.inFiles(conf);
    }

    @Test
    @DisplayName(NOT_ACCEPT_NULLS)
    void passNullToleranceCheck() {
        NullPointerTester tester = new NullPointerTester();
        tester.testAllPublicStaticMethods(MessageSelectorFactory.class);
        tester.testAllPublicInstanceMethods(factory);
    }

    @Test
    @DisplayName("create `UuidMessage` selector")
    void createUuidSelector() {
        Truth.assertThat(factory.uuid()).isInstanceOf(UuidMessage.class);
    }

    @Test
    @DisplayName("create `EntityState` selector")
    void createEntityStateSelector() {
        Truth.assertThat(factory.entityState()).isInstanceOf(EntityState.class);
    }

    @Test
    @DisplayName("create all messages selector")
    void createAllSelector() {
        PatternSelector allSelector = factory.all();
        Truth.assertThat(allSelector).isInstanceOf(SuffixSelector.class);
        Truth.assertThat(allSelector.getPattern()).isEqualTo(FileName.EXTENSION);
    }

    @Nested
    @DisplayName("create `PatternSelector` out of")
    final class CreatePatternSelector {

        @Test
        @DisplayName(MessageSelectorFactory.SUFFIX)
        void suffix() {
            String suffix = "_documents.proto";
            Truth.assertThat(inFiles(MessageSelectorFactory.suffix(suffix)))
                 .isInstanceOf(SuffixSelector.class);
        }

        @Test
        @DisplayName(MessageSelectorFactory.PREFIX)
        void prefix() {
            String prefix = "io/spine/test/orders_";
            Truth.assertThat(inFiles(MessageSelectorFactory.prefix(prefix)))
                 .isInstanceOf(PrefixSelector.class);
        }

        @Test
        @DisplayName(MessageSelectorFactory.REGEX)
        void regex() {
            String regex = ".*test.*";
            Truth.assertThat(inFiles(MessageSelectorFactory.regex(regex)))
                 .isInstanceOf(RegexSelector.class);
        }
    }

    @Nested
    @DisplayName("throw `IllegalArgumentException` if `inFiles` configuration has")
    final class Prohibit {

        @Test
        @DisplayName("more than one element")
        void moreThanOneElement() {
            assertIllegalArgument(() -> inFiles(ImmutableMap.of("first", "v1", "second", "v2")));
        }

        @Test
        @DisplayName("non supported parameter")
        void nonSupportParameter() {
            assertIllegalArgument(() -> inFiles(ImmutableMap.of("NON_SUPPORTED", "v1")));
        }
    }
}

@@ -1371,46 +1371,8 @@
 er;%0A
-import com.google.common.truth.Truth;%0A
 impo
@@ -1430,16 +1430,16 @@
 nValue;%0A
+
 import i
@@ -1582,16 +1582,72 @@
 .Test;%0A%0A
+import static com.google.common.truth.Truth.assertThat;%0A
 import s
@@ -2452,38 +2452,32 @@
 tor() %7B%0A        
-Truth.
 assertThat(facto
@@ -2626,38 +2626,32 @@
 tor() %7B%0A        
-Truth.
 assertThat(facto
@@ -2851,38 +2851,32 @@
 .all();%0A        
-Truth.
 assertThat(allSe
@@ -2919,38 +2919,32 @@
 class);%0A        
-Truth.
 assertThat(allSe
@@ -3249,38 +3249,32 @@
 o%22;%0A            
-Truth.
 assertThat(inFil
@@ -3528,38 +3528,32 @@
 _%22;%0A            
-Truth.
 assertThat(inFil
@@ -3787,16 +3787,16 @@
 est.*%22;%0A
+
         
@@ -3799,22 +3799,16 @@
         
-Truth.
 assertTh

Use static import