View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.qulice.errorprone;
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.params.ParameterizedTest;
14  import org.junit.jupiter.params.provider.ValueSource;
15  
16  /**
17   * Test case for {@link ErrorProneValidator} and the directories Qulice
18   * ignores by default, which it must leave alone without being told to.
19   *
20   * <p>The same self-assignment in {@code src/main/java} is reported, as
21   * {@link ErrorProneValidatorTest} shows.</p>
22   *
23   * @since 1.0
24   */
25  final class ErrorProneIgnoredTest {
26  
27      @ParameterizedTest
28      @ValueSource(
29          strings = {
30              "src/test/resources/com/qulice/Bad.java",
31              "src/site/apt/Bad.java",
32              "src/it/violations/src/main/java/foo/Bad.java"
33          }
34      )
35      void ignoresJavaFilesInIgnoredDirectories(final String file) throws Exception {
36          final Environment env = new Environment.Mock().withFile(
37              file,
38              "class Bad { private int value; void set(int v) { this.value = this.value; } }"
39          );
40          MatcherAssert.assertThat(
41              String.format("%s must not be compiled", file),
42              new ErrorProneValidator(env).validate(
43                  Collections.singletonList(new File(env.basedir(), file))
44              ),
45              Matchers.<Violation>empty()
46          );
47      }
48  }