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.io.IOException;
11  import java.util.Collection;
12  import org.cactoos.io.ResourceOf;
13  import org.cactoos.text.FormattedText;
14  import org.cactoos.text.IoCheckedText;
15  import org.cactoos.text.TextOf;
16  import org.hamcrest.MatcherAssert;
17  import org.hamcrest.Matchers;
18  import org.junit.jupiter.api.Assertions;
19  import org.junit.jupiter.api.Test;
20  
21  /**
22   * Test case for {@link CheckstyleValidator}'s handling of the
23   * stock {@code OperatorWrap} check in {@code nl} mode, see
24   * https://github.com/yegor256/qulice/issues/790.
25   * @since 0.25.1
26   */
27  final class CheckstyleOperatorWrapTest {
28  
29      @Test
30      void acceptsEqualityOperatorAtStartOfWrappedLine() throws Exception {
31          Assertions.assertDoesNotThrow(
32              () -> this.runValidation("ValidEqualityOperatorWrap.java", true)
33          );
34      }
35  
36      private Collection<Violation> runValidation(final String file,
37          final boolean passes) throws IOException {
38          final Environment.Mock mock = new Environment.Mock();
39          final Environment env = mock.withParam(
40              "license",
41              String.format(
42                  "file:%s",
43                  new License().savePackageInfo(
44                      new File(mock.basedir(), "src/main/java/foo")
45                  ).withLines("Hello.")
46                      .withEol(String.valueOf('\n')).file()
47              )
48          ).withFile(
49              String.format("src/main/java/foo/%s", file),
50              new IoCheckedText(
51                  new TextOf(
52                      new ResourceOf(
53                          new FormattedText("com/qulice/checkstyle/%s", file)
54                      )
55                  )
56              ).asString()
57          );
58          final Collection<Violation> results =
59              new CheckstyleValidator(env).validate(env.files(file));
60          MatcherAssert.assertThat(
61              "validation result should match expected state",
62              results.isEmpty(),
63              Matchers.is(passes)
64          );
65          return results;
66      }
67  }