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 LambdaTest extends AbstractModuleTestSupport {
30      @Override
31      protected String getPackageLocation() {
32          return "com/puppycrawl/tools/checkstyle/grammars/java8";
33      }
34  
35      @Test
36      public void testLambdaInVariableInitialization()
37              throws Exception {
38          final DefaultConfiguration checkConfig =
39                  createModuleConfig(MemberNameCheck.class);
40          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
41          verify(checkConfig, getPath("InputLambda1.java"), expected);
42  
43      }
44  
45      @Test
46      public void testWithoutArgsOneLineLambdaBody()
47              throws Exception {
48          final DefaultConfiguration checkConfig =
49                  createModuleConfig(MemberNameCheck.class);
50          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
51          verify(checkConfig, getPath("InputLambda2.java"), expected);
52  
53      }
54  
55      @Test
56      public void testWithoutArgsFullLambdaBody()
57              throws Exception {
58          final DefaultConfiguration checkConfig =
59                  createModuleConfig(MemberNameCheck.class);
60          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
61          verify(checkConfig, getPath("InputLambda3.java"), expected);
62  
63      }
64  
65      @Test
66      public void testWithOneArgWithOneLineBody()
67              throws Exception {
68          final DefaultConfiguration checkConfig =
69                  createModuleConfig(MemberNameCheck.class);
70          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
71          verify(checkConfig, getPath("InputLambda4.java"), expected);
72  
73      }
74  
75      @Test
76      public void testWithOneArgWithFullBody()
77              throws Exception {
78          final DefaultConfiguration checkConfig =
79                  createModuleConfig(MemberNameCheck.class);
80          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
81          verify(checkConfig, getPath("InputLambda5.java"), expected);
82  
83      }
84  
85      @Test
86      public void testWithOneArgWithoutTypeOneLineBody()
87              throws Exception {
88          final DefaultConfiguration checkConfig =
89                  createModuleConfig(MemberNameCheck.class);
90          final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
91          verify(checkConfig, getPath("InputLambda6.java"), expected);
92  
93      }
94  
95      @Test
96      public void testWithOneArgWithoutTypeFullBody()
97              throws Exception {
98          final DefaultConfiguration checkConfig =
99                  createModuleConfig(MemberNameCheck.class);
100         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
101         verify(checkConfig, getPath("InputLambda7.java"), expected);
102 
103     }
104 
105     @Test
106     public void testWithFewArgsWithoutTypeOneLineBody()
107             throws Exception {
108         final DefaultConfiguration checkConfig =
109                 createModuleConfig(MemberNameCheck.class);
110         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
111         verify(checkConfig, getPath("InputLambda8.java"), expected);
112 
113     }
114 
115     @Test
116     public void testWithFewArgsWithoutTypeFullBody()
117             throws Exception {
118         final DefaultConfiguration checkConfig =
119                 createModuleConfig(MemberNameCheck.class);
120         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
121         verify(checkConfig, getPath("InputLambda9.java"), expected);
122 
123     }
124 
125     @Test
126     public void testWithOneArgWithoutParenthesesWithoutTypeOneLineBody()
127             throws Exception {
128         final DefaultConfiguration checkConfig =
129                 createModuleConfig(MemberNameCheck.class);
130         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
131         verify(checkConfig, getPath("InputLambda10.java"), expected);
132 
133     }
134 
135     @Test
136     public void testWithOneArgWithoutParenthesesWithoutTypeFullBody()
137             throws Exception {
138         final DefaultConfiguration checkConfig =
139                 createModuleConfig(MemberNameCheck.class);
140         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
141         verify(checkConfig, getPath("InputLambda11.java"), expected);
142 
143     }
144 
145     @Test
146     public void testWithFewArgWithTypeOneLine()
147             throws Exception {
148         final DefaultConfiguration checkConfig =
149                 createModuleConfig(MemberNameCheck.class);
150         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
151         verify(checkConfig, getPath("InputLambda12.java"), expected);
152 
153     }
154 
155     @Test
156     public void testWithFewArgWithTypeFullBody()
157             throws Exception {
158         final DefaultConfiguration checkConfig =
159                 createModuleConfig(MemberNameCheck.class);
160         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
161         verify(checkConfig, getPath("InputLambda13.java"), expected);
162 
163     }
164 
165     @Test
166     public void testWithMultilineBody()
167             throws Exception {
168         final DefaultConfiguration checkConfig =
169                 createModuleConfig(MemberNameCheck.class);
170         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
171         verify(checkConfig, getPath("InputLambda14.java"), expected);
172 
173     }
174 
175     @Test
176     public void testCasesFromSpec()
177             throws Exception {
178         final DefaultConfiguration checkConfig =
179                 createModuleConfig(MemberNameCheck.class);
180         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
181         verify(checkConfig, getPath("InputLambda15.java"), expected);
182 
183     }
184 
185     @Test
186     public void testWithTypecast()
187             throws Exception {
188         final DefaultConfiguration checkConfig =
189                 createModuleConfig(MemberNameCheck.class);
190         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
191         verify(checkConfig, getPath("InputLambda16.java"), expected);
192 
193     }
194 
195     @Test
196     public void testInAssignment()
197             throws Exception {
198         final DefaultConfiguration checkConfig =
199                 createModuleConfig(MemberNameCheck.class);
200         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
201         verify(checkConfig, getPath("InputLambda17.java"), expected);
202 
203     }
204 
205     @Test
206     public void testInTernary()
207             throws Exception {
208         final DefaultConfiguration checkConfig =
209                 createModuleConfig(MemberNameCheck.class);
210         final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
211         verify(checkConfig, getPath("InputLambda18.java"), expected);
212 
213     }
214 
215 }