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