1
2
3
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
23
24
25
26
27 final class ConditionalRegexpMultilineCheckTest {
28
29 @Test
30 void suppressesConditionalRegexpMultilineInComment() throws Exception {
31 Assertions.assertDoesNotThrow(
32 () -> this.runValidation(
33 "SuppressConditionalRegexpMultilineInComment.java", true
34 )
35 );
36 }
37
38 private Collection<Violation> runValidation(final String file,
39 final boolean passes) throws IOException {
40 final Environment.Mock mock = new Environment.Mock();
41 final Environment env = mock.withParam(
42 "license",
43 String.format(
44 "file:%s",
45 new License().savePackageInfo(
46 new File(mock.basedir(), "src/main/java/foo")
47 ).withLines("Hello.")
48 .withEol(String.valueOf('\n')).file()
49 )
50 ).withFile(
51 String.format("src/main/java/foo/%s", file),
52 new IoCheckedText(
53 new TextOf(
54 new ResourceOf(
55 new FormattedText("com/qulice/checkstyle/%s", file)
56 )
57 )
58 ).asString()
59 );
60 final Collection<Violation> results =
61 new CheckstyleValidator(env).validate(env.files(file));
62 MatcherAssert.assertThat(
63 "validation result should match expected state",
64 results.isEmpty(),
65 Matchers.is(passes)
66 );
67 return results;
68 }
69 }