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