View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.checkstyle;
6   
7   import com.qulice.spi.Environment;
8   import com.qulice.spi.Violation;
9   import java.io.File;
10  import java.util.Collections;
11  import org.hamcrest.MatcherAssert;
12  import org.hamcrest.Matchers;
13  import org.junit.jupiter.api.Test;
14  
15  /**
16   * Test case for {@link CheckstyleValidator} file-exclusion short-circuit.
17   *
18   * <p>Regression coverage for
19   * <a href="https://github.com/yegor256/qulice/issues/759">#759</a>: when
20   * every file the validator is asked to check matches an exclude pattern,
21   * Checkstyle itself must not be invoked and no violations can be
22   * produced.</p>
23   *
24   * @since 0.24.2
25   */
26  final class CheckstyleValidatorExcludesTest {
27  
28      @Test
29      void skipsProcessingWhenAllFilesExcluded() throws Exception {
30          final String file = "src/main/java/foo/Main.java";
31          final Environment env = new ExcludingEnvironment(
32              new Environment.Mock().withFile(file, "class Main { }")
33          );
34          MatcherAssert.assertThat(
35              "Excluded files must not yield violations",
36              new CheckstyleValidator(env).validate(
37                  Collections.singletonList(new File(env.basedir(), file))
38              ),
39              Matchers.<Violation>empty()
40          );
41      }
42  }