1
2
3
4
5 package com.qulice.checkstyle;
6
7 import com.qulice.spi.Environment;
8 import java.io.File;
9 import org.cactoos.io.ResourceOf;
10 import org.cactoos.text.FormattedText;
11 import org.cactoos.text.IoCheckedText;
12 import org.cactoos.text.TextOf;
13 import org.hamcrest.MatcherAssert;
14 import org.hamcrest.Matchers;
15 import org.junit.jupiter.api.Test;
16
17
18
19
20
21
22 final class CheckstyleSingleSpaceSeparatorTest {
23
24 @Test
25 void rejectsDoubleWhitespaceInFieldDeclaration() throws Exception {
26 final String file = "DoubleWhitespaceFieldDecl.java";
27 final Environment.Mock mock = new Environment.Mock();
28 final Environment env = mock.withParam(
29 "license",
30 String.format(
31 "file:%s",
32 new License().savePackageInfo(
33 new File(mock.basedir(), "src/main/java/foo")
34 ).withLines("Hello.")
35 .withEol(String.valueOf('\n')).file()
36 )
37 ).withFile(
38 String.format("src/main/java/foo/%s", file),
39 new IoCheckedText(
40 new TextOf(
41 new ResourceOf(
42 new FormattedText("com/qulice/checkstyle/%s", file)
43 )
44 )
45 ).asString()
46 );
47 MatcherAssert.assertThat(
48 "double whitespace in a field declaration must be reported",
49 new CheckstyleValidator(env).validate(env.files(file)),
50 Matchers.hasItem(
51 new ViolationMatcher(
52 "Use a single space to separate non-whitespace characters.",
53 file, "17", "SingleSpaceSeparatorCheck"
54 )
55 )
56 );
57 }
58 }