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 CheckstyleJavadocTypeTest {
28
29 @Test
30 void reportsErrorWhenParameterObjectIsNotDocumented() throws Exception {
31 final String file = "ParametrizedClass.java";
32 MatcherAssert.assertThat(
33 "missing @param <T> must be reported",
34 this.runValidation(file, false),
35 Matchers.hasItem(
36 new ViolationMatcher(
37 "Type Javadoc comment is missing @param <T> tag.", file
38 )
39 )
40 );
41 }
42
43 @Test
44 void doesNotReportErrorWhenMissingJavadocInTests() throws Exception {
45 Assertions.assertDoesNotThrow(
46 () -> this.runValidation("MissingJavadocTest.java", true)
47 );
48 }
49
50 private Collection<Violation> runValidation(final String file,
51 final boolean passes) throws IOException {
52 final Environment.Mock mock = new Environment.Mock();
53 final Environment env = mock.withParam(
54 "license",
55 String.format(
56 "file:%s",
57 new License().savePackageInfo(
58 new File(mock.basedir(), "src/main/java/foo")
59 ).withLines("Hello.")
60 .withEol(String.valueOf('\n')).file()
61 )
62 ).withFile(
63 String.format("src/main/java/foo/%s", file),
64 new IoCheckedText(
65 new TextOf(
66 new ResourceOf(
67 new FormattedText("com/qulice/checkstyle/%s", file)
68 )
69 )
70 ).asString()
71 );
72 final Collection<Violation> results =
73 new CheckstyleValidator(env).validate(env.files(file));
74 MatcherAssert.assertThat(
75 "validation result should match expected state",
76 results.isEmpty(),
77 Matchers.is(passes)
78 );
79 return results;
80 }
81 }