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
28 final class CheckstyleTypeParamDescriptionTest {
29
30 @Test
31 @SuppressWarnings("unchecked")
32 void rejectsLowercaseTypeParamDescription() throws Exception {
33 final String file = "InvalidTypeParamDescription.java";
34 final String message =
35 "@param tag description should start with capital letter";
36 final String name = "RegexpSinglelineCheck";
37 MatcherAssert.assertThat(
38 "Both class and method type parameter descriptions must be reported",
39 this.runValidation(file, false),
40 Matchers.hasItems(
41 new ViolationMatcher(message, file, "9", name),
42 new ViolationMatcher(message, file, "17", name)
43 )
44 );
45 }
46
47 @Test
48 void allowsUppercaseTypeParamDescription() throws Exception {
49 Assertions.assertDoesNotThrow(
50 () -> this.runValidation("ValidTypeParamDescription.java", true)
51 );
52 }
53
54 private Collection<Violation> runValidation(final String file,
55 final boolean passes) throws IOException {
56 final Environment.Mock mock = new Environment.Mock();
57 final Environment env = mock.withParam(
58 "license",
59 String.format(
60 "file:%s",
61 new License().savePackageInfo(
62 new File(mock.basedir(), "src/main/java/foo")
63 ).withLines("Hello.")
64 .withEol(String.valueOf('\n')).file()
65 )
66 ).withFile(
67 String.format("src/main/java/foo/%s", file),
68 new IoCheckedText(
69 new TextOf(
70 new ResourceOf(
71 new FormattedText("com/qulice/checkstyle/%s", file)
72 )
73 )
74 ).asString()
75 );
76 final Collection<Violation> results =
77 new CheckstyleValidator(env).validate(env.files(file));
78 MatcherAssert.assertThat(
79 "validation result should match expected state",
80 results.isEmpty(),
81 Matchers.is(passes)
82 );
83 return results;
84 }
85 }