///////////////////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
// Copyright (C) 2001-2023 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
///////////////////////////////////////////////////////////////////////////////////////////////

package com.puppycrawl.tools.checkstyle.api;

import static com.google.common.truth.Truth.assertWithMessage;

import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultLocale;

/**
 * Test cases for {@link Scope} enumeration.
 */
public class ScopeTest {

    /* Additional test for jacoco, since valueOf()
     * is generated by javac and jacoco reports that
     * valueOf() is uncovered.
     */
    @Test
    public void testScopeValueOf() {
        final Scope scope = Scope.valueOf("PRIVATE");
        assertWithMessage("Invalid scope")
            .that(scope)
            .isEqualTo(Scope.PRIVATE);
    }

    @Test
    public void testMisc() {
        final Scope scope = Scope.getInstance("public");
        assertWithMessage("Scope must not be null")
            .that(scope)
            .isNotNull();
        assertWithMessage("Invalid scope toString")
            .that(scope.toString())
            .isEqualTo("public");
        assertWithMessage("Invalid scope name")
            .that(scope.getName())
            .isEqualTo("public");

        try {
            Scope.getInstance("unknown");
            assertWithMessage("exception expected").fail();
        }
        catch (IllegalArgumentException ex) {
            assertWithMessage("Invalid error message")
                .that(ex.getMessage())
                .isEqualTo("No enum constant com.puppycrawl.tools.checkstyle.api.Scope.UNKNOWN");
        }
    }

    @Test
    public void testMixedCaseSpaces() {
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance("NothinG "))
            .isEqualTo(Scope.NOTHING);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance(" PuBlic"))
            .isEqualTo(Scope.PUBLIC);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance(" ProteCted"))
            .isEqualTo(Scope.PROTECTED);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance("    PackAge "))
            .isEqualTo(Scope.PACKAGE);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance("privaTe   "))
            .isEqualTo(Scope.PRIVATE);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance("AnonInner"))
            .isEqualTo(Scope.ANONINNER);
    }

    @DefaultLocale(language = "tr", country = "TR")
    @Test
    public void testMixedCaseSpacesWithDifferentLocale() {
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance("NothinG "))
            .isEqualTo(Scope.NOTHING);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance(" PuBlic"))
            .isEqualTo(Scope.PUBLIC);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance(" ProteCted"))
            .isEqualTo(Scope.PROTECTED);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance("    PackAge "))
            .isEqualTo(Scope.PACKAGE);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance("privaTe   "))
            .isEqualTo(Scope.PRIVATE);
        assertWithMessage("Invalid scope")
            .that(Scope.getInstance("AnonInner"))
            .isEqualTo(Scope.ANONINNER);
    }

    @Test
    public void testIsInAnonInner() {
        assertWithMessage("Invalid subscope")
                .that(Scope.NOTHING.isIn(Scope.ANONINNER))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PUBLIC.isIn(Scope.ANONINNER))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PROTECTED.isIn(Scope.ANONINNER))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PACKAGE.isIn(Scope.ANONINNER))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PRIVATE.isIn(Scope.ANONINNER))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.ANONINNER.isIn(Scope.ANONINNER))
                .isTrue();
    }

    @Test
    public void testIsInPrivate() {
        assertWithMessage("Invalid subscope")
                .that(Scope.NOTHING.isIn(Scope.PRIVATE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PUBLIC.isIn(Scope.PRIVATE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PROTECTED.isIn(Scope.PRIVATE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PACKAGE.isIn(Scope.PRIVATE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PRIVATE.isIn(Scope.PRIVATE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.ANONINNER.isIn(Scope.PRIVATE))
                .isFalse();
    }

    @Test
    public void testIsInPackage() {
        assertWithMessage("Invalid subscope")
                .that(Scope.NOTHING.isIn(Scope.PACKAGE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PUBLIC.isIn(Scope.PACKAGE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PROTECTED.isIn(Scope.PACKAGE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PACKAGE.isIn(Scope.PACKAGE))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PRIVATE.isIn(Scope.PACKAGE))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.ANONINNER.isIn(Scope.PACKAGE))
                .isFalse();
    }

    @Test
    public void testIsInProtected() {
        assertWithMessage("Invalid subscope")
                .that(Scope.NOTHING.isIn(Scope.PROTECTED))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PUBLIC.isIn(Scope.PROTECTED))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PROTECTED.isIn(Scope.PROTECTED))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PACKAGE.isIn(Scope.PROTECTED))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.PRIVATE.isIn(Scope.PROTECTED))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.ANONINNER.isIn(Scope.PROTECTED))
                .isFalse();
    }

    @Test
    public void testIsInPublic() {
        assertWithMessage("Invalid subscope")
                .that(Scope.NOTHING.isIn(Scope.PUBLIC))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PUBLIC.isIn(Scope.PUBLIC))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PROTECTED.isIn(Scope.PUBLIC))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.PACKAGE.isIn(Scope.PUBLIC))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.PRIVATE.isIn(Scope.PUBLIC))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.ANONINNER.isIn(Scope.PUBLIC))
                .isFalse();
    }

    @Test
    public void testIsInNothing() {
        assertWithMessage("Invalid subscope")
                .that(Scope.NOTHING.isIn(Scope.NOTHING))
                .isTrue();
        assertWithMessage("Invalid subscope")
                .that(Scope.PUBLIC.isIn(Scope.NOTHING))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.PROTECTED.isIn(Scope.NOTHING))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.PACKAGE.isIn(Scope.NOTHING))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.PRIVATE.isIn(Scope.NOTHING))
                .isFalse();
        assertWithMessage("Invalid subscope")
                .that(Scope.ANONINNER.isIn(Scope.NOTHING))
                .isFalse();
    }

}
