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.puppycrawl.tools.checkstyle.grammars.java8;
21  
22  import org.junit.Test;
23  
24  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
25  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
26  import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
27  import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
28  
29  public class AnnotationTest extends AbstractModuleTestSupport {
30      @Override
31      protected String getPackageLocation() {
32          return "com/puppycrawl/tools/checkstyle/grammars/java8";
33      }
34  
35      @Test
36      public void testSimpleTypeAnnotation()
37              throws Exception {
38          final DefaultConfiguration checkConfig =
39                  createModuleConfig(MemberNameCheck.class);
40          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
41          verify(checkConfig, getPath("InputAnnotations1.java"), expected);
42  
43      }
44  
45      @Test
46      public void testAnnotationOnClass()
47              throws Exception {
48          final DefaultConfiguration checkConfig =
49                  createModuleConfig(MemberNameCheck.class);
50          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
51          verify(checkConfig, getPath("InputAnnotations2.java"), expected);
52  
53      }
54  
55      @Test
56      public void testClassCastTypeAnnotation()
57              throws Exception {
58          final DefaultConfiguration checkConfig =
59                  createModuleConfig(MemberNameCheck.class);
60          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
61          verify(checkConfig, getPath("InputAnnotations3.java"), expected);
62  
63      }
64  
65      @Test
66      public void testMethodParametersTypeAnnotation()
67              throws Exception {
68          final DefaultConfiguration checkConfig =
69                  createModuleConfig(MemberNameCheck.class);
70          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
71          verify(checkConfig, getPath("InputAnnotations4.java"), expected);
72  
73      }
74  
75      @Test
76      public void testAnnotationInThrows()
77              throws Exception {
78          final DefaultConfiguration checkConfig =
79                  createModuleConfig(MemberNameCheck.class);
80          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
81          verify(checkConfig, getPath("InputAnnotations5.java"), expected);
82  
83      }
84  
85      @Test
86      public void testAnnotationInGeneric()
87              throws Exception {
88          final DefaultConfiguration checkConfig =
89                  createModuleConfig(MemberNameCheck.class);
90          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
91          verify(checkConfig, getPath("InputAnnotations6.java"), expected);
92  
93      }
94  
95      @Test
96      public void testAnnotationOnConstructorCall()
97              throws Exception {
98          final DefaultConfiguration checkConfig =
99                  createModuleConfig(MemberNameCheck.class);
100         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
101         verify(checkConfig, getPath("InputAnnotations7.java"), expected);
102 
103     }
104 
105     @Test
106     public void testAnnotationNestedCall()
107             throws Exception {
108         final DefaultConfiguration checkConfig =
109                 createModuleConfig(MemberNameCheck.class);
110         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
111         verify(checkConfig, getPath("InputAnnotations8.java"), expected);
112 
113     }
114 
115     @Test
116     public void testAnnotationOnWildcards()
117             throws Exception {
118         final DefaultConfiguration checkConfig =
119                 createModuleConfig(MemberNameCheck.class);
120         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
121         verify(checkConfig, getPath("InputAnnotations9.java"), expected);
122 
123     }
124 
125     @Test
126     public void testAnnotationInCatchParameters()
127             throws Exception {
128         final DefaultConfiguration checkConfig =
129                 createModuleConfig(MemberNameCheck.class);
130         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
131         verify(checkConfig, getPath("InputAnnotations10.java"), expected);
132 
133     }
134 
135     @Test
136     public void testAnnotationInTypeParameters()
137             throws Exception {
138         final DefaultConfiguration checkConfig =
139                 createModuleConfig(MemberNameCheck.class);
140         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
141         verify(checkConfig, getPath("InputAnnotations11.java"), expected);
142 
143     }
144 }