1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.checks.header;
21
22 import static com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck.MSG_MISSING;
23
24 import org.junit.jupiter.api.Test;
25
26 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
27 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
28
29 public class HeaderCheckExamplesTest extends AbstractExamplesModuleTestSupport {
30 @Override
31 public String getPackageLocation() {
32 return "com/puppycrawl/tools/checkstyle/checks/header/header";
33 }
34
35 @Test
36 public void testExample1() throws Exception {
37 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
38 verifyWithExternalXmlConfig(getPath("Example1.xml"),
39 getPath("Example1.java"),
40 expected);
41 }
42
43 @Test
44 public void testExample2() throws Exception {
45 final String[] expected = {
46 "1: " + getCheckMessage(MSG_MISSING),
47 };
48 System.setProperty("config.folder", "src/xdocs-examples/resources/" + getPackageLocation());
49 verifyWithExternalXmlConfig(getPath("Example2.xml"),
50 getPath("Example2.java"),
51 expected);
52
53 }
54
55 @Test
56 public void testExample3() throws Exception {
57 final String[] expected = {
58 "1: " + getCheckMessage(HeaderCheck.MSG_MISMATCH, "// Copyright (C) 2004 MyCompany"),
59 };
60
61 verifyWithExternalXmlConfig(getPath("Example3.xml"),
62 getPath("Example3.java"),
63 expected);
64 }
65
66 @Test
67 public void testExample4() throws Exception {
68 final String[] expected = {
69 "1: " + getCheckMessage(MSG_MISSING),
70 };
71 System.setProperty("config.folder", "src/xdocs-examples/resources/" + getPackageLocation());
72 verifyWithExternalXmlConfig(getPath("Example4.xml"),
73 getPath("Example4.java"),
74 expected);
75 }
76 }