View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace;
21  
22  import org.junit.Test;
23  
24  import com.google.checkstyle.test.base.AbstractModuleTestSupport;
25  import com.puppycrawl.tools.checkstyle.api.Configuration;
26  
27  public class GenericWhitespaceTest extends AbstractModuleTestSupport {
28  
29      @Override
30      protected String getPackageLocation() {
31          return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace";
32      }
33  
34      @Test
35      public void testWhitespaceAroundGenerics() throws Exception {
36  
37          final String msgPreceded = "ws.preceded";
38          final String msgFollowed = "ws.followed";
39          final Configuration checkConfig = getModuleConfig("GenericWhitespace");
40  
41          final String[] expected = {
42              "12:16: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
43              "12:18: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
44              "12:36: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
45              "12:38: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
46              "12:47: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
47              "12:49: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
48              "12:49: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
49              "14:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
50              "14:34: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
51              "14:45: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
52              "15:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
53              "15:34: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
54              "15:45: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
55              "20:38: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
56              "20:40: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
57              "20:61: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
58          };
59  
60          final String filePath = getPath("InputWhitespaceAroundGenerics.java");
61  
62          final Integer[] warnList = getLinesWithWarn(filePath);
63          verify(checkConfig, filePath, expected, warnList);
64      }
65  
66      @Test
67      public void testGenericWhitespace() throws Exception {
68          final String msgPreceded = "ws.preceded";
69          final String msgFollowed = "ws.followed";
70          final String msgNotPreceded = "ws.notPreceded";
71          final String msgIllegalFollow = "ws.illegalFollow";
72          final Configuration checkConfig = getModuleConfig("GenericWhitespace");
73  
74          final String[] expected = {
75              "16:13: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
76              "16:15: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
77              "16:23: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
78              "16:43: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
79              "16:45: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
80              "16:53: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
81              "17:13: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
82              "17:15: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
83              "17:20: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
84              "17:22: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
85              "17:30: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
86              "17:32: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
87              "17:32: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
88              "17:52: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
89              "17:54: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
90              "17:59: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
91              "17:61: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, "<"),
92              "17:69: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
93              "17:71: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
94              "17:71: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, ">"),
95              "30:17: " + getCheckMessage(checkConfig.getMessages(), msgNotPreceded, "<"),
96              "30:21: " + getCheckMessage(checkConfig.getMessages(), msgIllegalFollow, ">"),
97              "42:21: " + getCheckMessage(checkConfig.getMessages(), msgPreceded, "<"),
98              "42:30: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
99              "60:60: " + getCheckMessage(checkConfig.getMessages(), msgNotPreceded, "&"),
100             "63:60: " + getCheckMessage(checkConfig.getMessages(), msgFollowed, ">"),
101         };
102 
103         final String filePath = getPath("InputGenericWhitespace.java");
104 
105         final Integer[] warnList = getLinesWithWarn(filePath);
106         verify(checkConfig, filePath, expected, warnList);
107     }
108 
109     @Test
110     public void genericEndsTheLine() throws Exception {
111         final Configuration checkConfig = getModuleConfig("GenericWhitespace");
112         final String[] expected = {
113         };
114         verify(checkConfig, getPath("InputGenericWhitespaceEndsTheLine.java"),
115                 expected);
116     }
117 }