otherList = new ArrayList<>();
44 | otherList.add("DO");
45 | otherList.add("BO");
46 | otherList.add("DTO");
47 | otherList.add("VO");
48 |
49 | for(String otherName: otherList){
50 | if(otherName.equalsIgnoreCase(className.substring(className.length()-otherName.length()))){
51 | if(!otherName.equals(className.substring(className.length()-otherName.length()))){
52 | context.reportIssue(this,tree,"Can't Name this");
53 | }
54 | }
55 | }
56 |
57 | //判断第一个字符是否为大写
58 | char name = className.charAt(0);
59 | if(Character.isLowerCase(name)){
60 | context.reportIssue(this,tree,"Can't Name this");
61 | }
62 | super.visitClass(tree);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/AbstractClassNameCheck.html:
--------------------------------------------------------------------------------
1 | AbstractClassNameCheck Check
2 | Noncompliant Code Example
3 |
4 | public abstract class HiClass {// Noncompliant
5 | }
6 |
7 | public abstract class MyNameIsAbstract {// Noncompliant
8 | }
9 |
10 | Compliant Solution
11 |
12 | public abstract class AbstractMysql {
13 | }
14 |
15 | public abstract class BaseMysql {
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/AbstractClassNameCheck.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "The Name Of Abstract Class should use Abstract or Base first",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/AbstractClassNameCheck_java.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "The Name Of Abstract Class should use Abstract or Base first",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ArrayNameCheck.html:
--------------------------------------------------------------------------------
1 | AbstractClassNameCheck Check
2 | [] should follow the array object
3 |
4 | Noncompliant Code Example
5 |
6 |
7 | private String errorTemp[];// Noncompliant
8 |
9 | private String[] rightTemp;
10 |
11 | public void getTemp(String noTemp[]){// Noncompliant
12 | int intHi[];// Noncompliant
13 | int[] intNo;
14 | }
15 |
16 | Compliant Solution
17 |
18 | private String[] errorTemp;// Noncompliant
19 | private String[] rightTemp;// Noncompliant
20 |
21 | public void getTemp(String[] noTemp){// Noncompliant
22 | int[] intHi;// Noncompliant
23 | int[] intNo;// Noncompliant
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ArrayNameCheck.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "[] should follow the array object",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "MAJOR"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ArrayNameCheck_java.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "[] should follow the array object",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "MAJOR"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ConstantNameCheck.html:
--------------------------------------------------------------------------------
1 | ConstantNameCheck Check
2 | Noncompliant Code Example
3 |
4 | private static final String z; // Noncompliant
5 |
6 | private static final String Hello_WORLD = "Hello WOLD"; // Noncompliant
7 |
8 | private static final String NO_123_ZZZ = "sdddsaa";// Noncompliant
9 |
10 | private static final String HELLOWORLDMYNAMEISLILEI = "Hello WOLD MY NAME IS LI LEI"; // Noncompliant
11 |
12 |
13 | Compliant Solution
14 |
15 | private static final String BAIDU_HOST_NAME = "http://www.baidu.com";
16 |
17 | private static final String V = "1.0";
18 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ConstantNameCheck.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Constant Name rule should use UppCase,And each word show spilt as _",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ConstantNameCheck_java.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Constant Name rule should use UppCase,And each word show spilt as _",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ExceptionClassNameCheck.html:
--------------------------------------------------------------------------------
1 | ExceptionClassNameCheck Check
2 | Noncompliant Code Example
3 |
4 | public abstract class HiClass {// Noncompliant
5 | }
6 |
7 | public abstract class MyNameIsAbstract {// Noncompliant
8 | }
9 |
10 | Compliant Solution
11 |
12 | public abstract class AbstractMysql {
13 | }
14 |
15 | public abstract class BaseMysql {
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ExceptionClassNameCheck.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Class name must end with Exception",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/ExceptionClassNameCheck_java.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Class name must end with Exception",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/LowerCameCaseCheck.html:
--------------------------------------------------------------------------------
1 | LowerCameCase Check
2 | Noncompliant Code Example
3 |
4 | private String ID; // Noncompliant
5 | private String UserName; // Noncompliant
6 | private String password;
7 |
8 | public String getUserInfo(String info) {
9 | String Yes = "Yes"; // Noncompliant
10 | }
11 |
12 | public void GetPassword(){}// Noncompliant
13 |
14 | public void getUser(String UserInfo){}// Noncompliant
15 |
16 | Compliant Solution
17 |
18 | private String id;
19 | private String userName;
20 | private String password;
21 |
22 | public String getUserInfo(String info) {
23 | String yes = "Yes";
24 | }
25 |
26 | public void getPassword(){}
27 |
28 | public void getUser(String userInfo){}
29 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/LowerCameCaseCheck.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Can't use LowerCamelCase Style As Name",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/LowerCameCaseCheck_java.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Can't use LowerCamelCase Style As Name",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/UnderlineDollarNameCheck.html:
--------------------------------------------------------------------------------
1 | Can't use underline or Dollar first or end As Name
2 | Noncompliant Code Example
3 |
4 | private String _Hi;// Noncompliant
5 | private String Hi_;// Noncompliant
6 | private String $Hi;// Noncompliant
7 | private String Hi$;// Noncompliant
8 |
9 | public void test(String _Hi, String Hi_,String $Hi,String Hi$){ // Noncompliant
10 | }
11 |
12 | public void test_(){} // Noncompliant
13 |
14 | public void $test(){} // Noncompliant
15 |
16 | public void test$(){} // Noncompliant
17 |
18 | Compliant Solution
19 |
20 | private String Hi;
21 |
22 | public void test(String Hi){
23 | }
24 |
25 | public void test(){}
26 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/UnderlineDollarNameCheck.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Can't use underline or Dollar first or end As Name",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/UnderlineDollarNameCheck_java.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Can't use underline or Dollar first or end As Name",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/UpperCameCaseCheck.html:
--------------------------------------------------------------------------------
1 | UpperCamelCase check
2 | Noncompliant Code Example
3 |
4 | macroPolo // Noncompliant
5 | UserDo // Noncompliant
6 | XMLService // Noncompliant
7 | TCPUDPDeal // Noncompliant
8 | TAPromotion // Noncompliant
9 |
10 | Compliant Solution
11 |
12 | MarcoPolo
13 | UserDO
14 | XmlService
15 | TcpUdpDeal
16 | TaPromotion
17 |
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/UpperCameCaseCheck.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Can't use UpperCamelCase Style As Name",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/main/resources/org/sonar/l10n/java/rules/squid/UpperCameCaseCheck_java.json:
--------------------------------------------------------------------------------
1 | {
2 | "title": "Can't use UpperCamelCase Style As Name",
3 | "status": "ready",
4 | "remediation": {
5 | "func": "Constant\/Issue",
6 | "constantCost": "5min"
7 | },
8 | "tags": [
9 | "bug",
10 | "pitfall"
11 | ],
12 | "defaultSeverity": "CRITICAL"
13 | }
--------------------------------------------------------------------------------
/src/test/files/AbstractMysql.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/17.
5 | */
6 | public abstract class AbstractMysql {
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/files/ActionTestCase.java:
--------------------------------------------------------------------------------
1 | package com.finger.web.api;
2 |
3 | import com.finger.web.model.HTTPRequestInfo;
4 | import com.finger.web.pojo.TResultInfo;
5 | import net.sf.json.JSONObject;
6 |
7 | /**
8 | * 执行测试用例
9 | * Created by huqingen on 2017/3/10.
10 | */
11 | public interface ActionTestCase {
12 |
13 | /**
14 | * 执行http测试请求
15 | * @param httpRequestInfo
16 | * @return
17 | */
18 | TResultInfo runTestCase(JSONObject HttpRequestInfo, String assertValue);// Noncompliant
19 | }
--------------------------------------------------------------------------------
/src/test/files/ActionTestCaseImpl.java:
--------------------------------------------------------------------------------
1 | package com.finger.web.api.impl;
2 |
3 | import com.finger.web.api.ActionTestCase;
4 | import com.finger.web.common.DateUtils;
5 | import com.finger.web.common.HTTPClientMethod;
6 | import com.finger.web.pojo.TResultInfo;
7 | import net.sf.json.JSONArray;
8 | import net.sf.json.JSONObject;
9 | import org.apache.commons.logging.Log;
10 | import org.apache.commons.logging.LogFactory;
11 | import org.springframework.stereotype.Component;
12 |
13 | import java.text.ParseException;
14 | import java.util.ArrayList;
15 | import java.util.HashMap;
16 | import java.util.Iterator;
17 | import java.util.Map;
18 | /**
19 | * Created by huqingen on 2017/3/10.
20 | */
21 | @Component
22 | public class ActionTestCaseImpl implements ActionTestCase{
23 |
24 | private static final Log LOGGER= LogFactory.getLog(ActionTestCaseImpl.class);
25 |
26 | private static final String FINGERSSLHOST = "https://stable.fingerapp.cn";
27 |
28 | private DateUtils dateUtils;
29 |
30 | /**
31 | *
32 | * @param httpRequestInfo
33 | * @param assertValue
34 | * @return
35 | */
36 | public TResultInfo runTestCase(JSONObject httpRequestInfo,String assertValue){
37 | TResultInfo tResultInfo = new TResultInfo();
38 | try {
39 | tResultInfo = HTTPTestRun(httpRequestInfo,assertValue);
40 | } catch (ParseException e) {
41 | LOGGER.info(e);
42 | }
43 |
44 | return tResultInfo;
45 | }
46 |
47 | /**
48 | * http请求
49 | * @param httpRequestInfo
50 | * @param assertValue
51 | * @return
52 | */
53 | public TResultInfo HTTPTestRun(JSONObject httpRequestInfo,String assertValue) throws ParseException {
54 | HTTPClientMethod httpClientMethod = new HTTPClientMethod();
55 | TResultInfo resultInfo = new TResultInfo();
56 | String model = httpRequestInfo.get("model").toString();
57 | String method = httpRequestInfo.get("method").toString();
58 |
59 | if("delete".equalsIgnoreCase(method) || "get".equalsIgnoreCase(method)) {
60 | resultInfo = deleteOrGet(httpClientMethod, resultInfo, httpRequestInfo, method, assertValue,model);
61 | return resultInfo;
62 | }
63 |
64 | if("post".equalsIgnoreCase(method) || "put".equalsIgnoreCase(method)){
65 | resultInfo = postOrPut(httpClientMethod,resultInfo,httpRequestInfo,method,assertValue,model);
66 | return resultInfo;
67 | }
68 | resultInfo.setActionresult(0);
69 | return resultInfo;
70 | }
71 |
72 | /**
73 | * 处理header
74 | * @param headerContent
75 | * @return
76 | */
77 |
78 | public Map getHeaders(String headerContent){
79 | Map headers = new HashMap();
80 | if (headerContent.length() != 0) {
81 | JSONObject headerJSON = JSONObject.fromObject(headerContent);//转换成JSON
82 | Iterator keys = headerJSON.keys();
83 | while (keys.hasNext()) {
84 | String key = String.valueOf(keys.next());
85 | String value = (String) headerJSON.get(key);
86 | headers.put(key, value);
87 | }
88 | }
89 | return headers;
90 | }
91 |
92 | /**
93 | * 处理post或put请求
94 | * @param httpClientMethod
95 | * @param resultInfo
96 | * @param httpRequestInfo
97 | * @param method
98 | * @param assertValue
99 | * @return
100 | */
101 | public TResultInfo postOrPut(HTTPClientMethod httpClientMethod,TResultInfo resultInfo,JSONObject httpRequestInfo,String method,String assertValue,String model) throws ParseException {
102 | //处理Headers
103 | String headerContent = httpRequestInfo.get("header").toString();
104 | String paramsContent = httpRequestInfo.get("params").toString();
105 | String uriContent = httpRequestInfo.get("uri").toString();
106 | Map headers = getHeaders(headerContent);
107 | String url = FINGERSSLHOST + uriContent;
108 |
109 | LOGGER.info("URL信息:" + url);
110 | LOGGER.info("Header信息:" + headerContent);
111 | JSONObject result = new JSONObject();
112 | //判断参数是JSONOjcet还是JSONArray
113 | if ("{".equals(paramsContent.substring(0, 1))) {
114 | JSONObject paramsJSON = JSONObject.fromObject(paramsContent);//生成JSON格式的参数
115 | LOGGER.info("Params信息: " + paramsJSON.toString());
116 | //发送HTTP请求
117 | try {
118 | if("HTTPS".equalsIgnoreCase(model)) {
119 | if ("post".equalsIgnoreCase(method)) {
120 | result = httpClientMethod.postSSLJSONMethod(url, paramsJSON, headers);
121 | } else {
122 | result = httpClientMethod.putSSLJSONMethod(url, paramsJSON, headers);
123 | }
124 | }else {
125 | if ("post".equalsIgnoreCase(method)) {
126 | result = httpClientMethod.postJSONMethod(url, paramsJSON, headers);
127 | } else {
128 | result = httpClientMethod.putJSONMethod(url, paramsJSON, headers);
129 | }
130 | }
131 | resultInfo.setTestresultinfo(result.toString());
132 | } catch (Exception e) {
133 | LOGGER.info(e);
134 | }
135 |
136 | } else {
137 | JSONArray paramsJSON = JSONArray.fromObject(paramsContent);//生成JSONArray格式
138 | LOGGER.info("Params信息: " + paramsJSON.toString());
139 | //发送HTTP请求
140 | try {
141 | if("HTTPS".equalsIgnoreCase(model)) {
142 | if ("post".equalsIgnoreCase(method)) {
143 | result = httpClientMethod.postSSLJSONArrayMethod(url, paramsJSON, headers);
144 | } else {
145 | result = httpClientMethod.putSSLJSONArrayMethod(url, paramsJSON, headers);
146 | }
147 | }else {
148 | if ("post".equalsIgnoreCase(method)) {
149 | result = httpClientMethod.postJSONArrayMethod(url, paramsJSON, headers);
150 | } else {
151 | result = httpClientMethod.putJSONArrayMethod(url, paramsJSON, headers);
152 | }
153 | }
154 | resultInfo.setTestresultinfo(result.toString());
155 | } catch (Exception e) {
156 | LOGGER.info(e);
157 | }
158 |
159 | }
160 |
161 | //断言结果
162 | boolean actionResult = resultAssert(assertValue,result.toString());
163 |
164 | if(actionResult == true){
165 | resultInfo.setActionresult(1);
166 | }else {
167 | resultInfo.setActionresult(2);
168 | }
169 | return resultInfo;
170 | }
171 |
172 | /**
173 | * 处理delete或get请求
174 | * @param httpClientMethod
175 | * @param resultInfo
176 | * @param httpRequestInfo
177 | * @param method
178 | * @param assertValue
179 | * @param model
180 | * @return
181 | */
182 | public TResultInfo deleteOrGet(HTTPClientMethod httpClientMethod,TResultInfo resultInfo,JSONObject httpRequestInfo,String method,String assertValue,String model) throws ParseException {
183 | //处理Headers
184 | String headerContent = httpRequestInfo.get("header").toString();
185 | // String paramsContent = httpRequestInfo.get("params").toString();
186 | String uriContent = httpRequestInfo.get("uri").toString();
187 | Map headers = getHeaders(headerContent);
188 | String url = FINGERSSLHOST + uriContent;
189 |
190 | LOGGER.info("Header信息:" + headerContent);
191 | LOGGER.info("URL信息:" + url);
192 |
193 | JSONObject result = new JSONObject();
194 |
195 |
196 | //发送HTTP请求
197 | try {
198 |
199 | if("HTTPS".equalsIgnoreCase(model)) {
200 | if("get".equalsIgnoreCase(method)) {
201 | result = httpClientMethod.getSSLMethod(url, headers);
202 | }else {
203 | result = httpClientMethod.deleteSSLMethod(url,new HashMap(), headers);
204 | }
205 | }else {
206 | if("get".equalsIgnoreCase(method)) {
207 | result = httpClientMethod.getMethod(url, headers);
208 | }else {
209 | result = httpClientMethod.deleteMethod(url,new HashMap(), headers);
210 | }
211 | }
212 | resultInfo.setTestresultinfo(result.toString());
213 | } catch (Exception e) {
214 | LOGGER.info(e);
215 | }
216 |
217 | //断言结果
218 | boolean actionResult = resultAssert(assertValue,result.toString());
219 |
220 | if(actionResult == true){
221 | resultInfo.setActionresult(1);
222 | }else {
223 | resultInfo.setActionresult(2);
224 | }
225 | return resultInfo;
226 | }
227 |
228 |
229 |
230 | /**
231 | * 断言处理
232 | * @param excepContent
233 | * @param resultContent
234 | * @return
235 | */
236 | public boolean resultAssert(String excepContent,String resultContent) {
237 |
238 | //判断预期结果中是否要判断多种类型,以,进行分割
239 | if(excepContent.contains(",") && !",".equals(excepContent.substring(excepContent.length()-1))) {
240 | String[] excepContentList = excepContent.split(",");
241 | //增加不等于,以 !表示不等于
242 | ArrayList equalContentList = new ArrayList(); //等于
243 | ArrayList notEqualContentList = new ArrayList(); //不等于
244 | for(String str : excepContentList){
245 | if(str.substring(0,1).contains("!")){
246 | notEqualContentList.add(str.substring(1));
247 | }else {
248 | equalContentList.add(str);
249 | }
250 | }
251 | ArrayList failList = new ArrayList();//专门存储失败项
252 | //遍历等于
253 | for(String tempStr : equalContentList){
254 | if(!resultContent.contains(tempStr)){
255 | failList.add("FAIL");
256 | }
257 | }
258 | //遍历不等于
259 | for(String tempStr : notEqualContentList){
260 | if(resultContent.contains(tempStr)){
261 | failList.add("FAIL");
262 | }
263 | }
264 | //判断FailList是否为空
265 | if(failList.isEmpty()){
266 | LOGGER.info("测试结果: PASS");
267 | return true;
268 | }
269 | LOGGER.info("测试结果: FAIL");
270 | return false;
271 | }else {
272 | if(!"".equals(excepContent)) {
273 | if (resultContent.contains(excepContent)) {
274 | LOGGER.info("测试结果: PASS ");
275 | return true;
276 | }
277 | LOGGER.info("测试结果: FAIL");
278 | return false;
279 | }
280 | LOGGER.info("测试结果: FAIL");
281 | return false;
282 | }
283 | }
284 |
285 |
286 | }
287 |
--------------------------------------------------------------------------------
/src/test/files/AgeOutOfBound.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/18.
5 | */
6 | public class AgeOutOfBound extends Exception implements Hi{// Noncompliant
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/files/AgeOutOfException.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/18.
5 | */
6 | public class AgeOutOfException extends Exception implements Hi{
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/files/AgeOutOfExceptionBound.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/18.
5 | */
6 | public class AgeOutOfExceptionBound extends Exception implements Hi{// Noncompliant
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/files/ArrayNameCheckMapper.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/18.
5 | */
6 | public class ArrayNameCheckMapper {
7 |
8 | private String zzzz;
9 |
10 | private String errorTemp[];// Noncompliant
11 |
12 | private String[] rightTemp;
13 |
14 | public void getTemp(String noTemp[]){// Noncompliant
15 | int intHi[];// Noncompliant
16 | int[] intNo;
17 | }
18 |
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/files/BaseMysql.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/17.
5 | */
6 | public abstract class BaseMysql {
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/files/ConstantNameMapper.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/17.
5 | */
6 | public class ConstantNameMapper {
7 |
8 | private String Biz ;
9 |
10 | private static String WH = "2221";
11 |
12 | private static final String NO_BB_CC_DD_CC_SSS = "2212313213";
13 |
14 | private static final String V = "122333";
15 |
16 | private static final String HELLOWORLDMYNAMEISLILEI = "Hello WOLD MY NAME IS LI LEI"; // Noncompliant
17 |
18 | private static final String Hello_WORLD = "Hello WOLD"; // Noncompliant
19 |
20 | private static final String NO_123_ZZZ = "sdddsaa";// Noncompliant
21 | }
22 |
--------------------------------------------------------------------------------
/src/test/files/HiClass.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/17.
5 | */
6 | public abstract class HiClass {// Noncompliant
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/files/LowerCameCaseMapper.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/17.
5 | */
6 | public class LowerCameCaseMapper {
7 | private String ID;// Noncompliant
8 | private String UserName;// Noncompliant
9 | private String password;// Compliant
10 |
11 | private static final String NO_BB_CC_DD_CC_SSS = "2212313213";
12 |
13 | public String getUserInfo(String info) { // Noncompliant
14 | String Yes = "Yes";// Noncompliant
15 | return info+Yes;
16 | }
17 |
18 | public void GetPassword(){} // Noncompliant
19 |
20 | public void getUser(String UserInfo) {// Noncompliant
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/test/files/MyFirstCustomCheck.java:
--------------------------------------------------------------------------------
1 | class MyClass {
2 | MyClass(MyClass mc) { }
3 |
4 | int foo1() { return 0; }
5 | void foo2(int value) { }
6 | int foo3(int value) { return 0; } // Noncompliant
7 | Object foo4(int value) { return null; }
8 | MyClass foo5(MyClass value) {return null; } // Noncompliant
9 |
10 | int foo6(int value, String name) { return 0; }
11 | int foo7(int ... values) { return 0;}
12 | }
--------------------------------------------------------------------------------
/src/test/files/MyNameIsAbstract.java:
--------------------------------------------------------------------------------
1 | package org.finger.java.rule.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/17.
5 | */
6 | public abstract class MyNameIsAbstract {// Noncompliant
7 | }
8 |
--------------------------------------------------------------------------------
/src/test/files/TestKeyWordContainsRule.java:
--------------------------------------------------------------------------------
1 | import a.b.CallMessage;
2 |
3 | class TestKeyWordContainsRule {
4 |
5 |
6 | void foo(int value) {
7 | CallMessage.sendMsg("abc");
8 | Thread.sleep();
9 | }
10 |
11 | int foo3(int value) {
12 | return 0;
13 | }
14 |
15 |
16 | }
--------------------------------------------------------------------------------
/src/test/files/UnderlineDollarRuleMapper.java:
--------------------------------------------------------------------------------
1 | package com.finger.alirules.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/16.
5 | */
6 | public class UnderlineDollarRuleMapper {
7 | private String _Hi;// Noncompliant
8 | private String Hi_;// Noncompliant
9 | private String $Hi;// Noncompliant
10 | private String Hi$;// Noncompliant
11 |
12 | private String Hi;
13 |
14 | public void test(String _Hi){}// Noncompliant
15 |
16 | public void test(String Hi_){}// Noncompliant
17 |
18 | public void test(String $Hi){}// Noncompliant
19 |
20 | public void test(String Hi$){}// Noncompliant
21 |
22 | public void test_(){} // Noncompliant
23 |
24 | public void $test(){} // Noncompliant
25 |
26 | public void test$(){} // Noncompliant
27 | }
28 |
--------------------------------------------------------------------------------
/src/test/files/UserDo.java:
--------------------------------------------------------------------------------
1 | package com.finger.alirules.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/16.
5 | */
6 | public class UserDo { // Noncompliant
7 |
8 | }
--------------------------------------------------------------------------------
/src/test/files/XMLService.java:
--------------------------------------------------------------------------------
1 | package com.finger.alirules.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/16.
5 | */
6 | public class XMLService {
7 |
8 | }
--------------------------------------------------------------------------------
/src/test/files/macroPolo.java:
--------------------------------------------------------------------------------
1 | package com.finger.alirules.checks.namerules;
2 |
3 | /**
4 | * Created by huqingen on 2017/3/16.
5 | */
6 | public class macroPolo { // Noncompliant
7 |
8 | }
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/MyJavaRulesDefinitionTest.java:
--------------------------------------------------------------------------------
1 | package org.sonar.java.rule;
2 |
3 | import static org.fest.assertions.Assertions.assertThat;
4 |
5 | import org.junit.Test;
6 | import org.sonar.api.rules.RuleType;
7 | import org.sonar.api.server.debt.DebtRemediationFunction;
8 | import org.sonar.api.server.rule.RuleParamType;
9 | import org.sonar.api.server.rule.RulesDefinition;
10 |
11 | public class MyJavaRulesDefinitionTest {
12 |
13 | @Test
14 | public void test() {
15 | MyJavaRulesDefinition rulesDefinition = new MyJavaRulesDefinition();
16 | RulesDefinition.Context context = new RulesDefinition.Context();
17 | rulesDefinition.define(context);
18 | RulesDefinition.Repository repository = context.repository(MyJavaRulesDefinition.REPOSITORY_KEY);
19 |
20 | assertThat(repository.key()).isEqualTo("finger-java-custom-rules");
21 | assertThat(repository.name()).isEqualTo("Finger Java Custom Rules");
22 | assertThat(repository.language()).isEqualTo("java");
23 | assertThat(repository.rules()).hasSize(RulesList.getChecks().size());
24 |
25 | assertRuleProperties(repository);
26 | // assertParameterProperties(repository);
27 | // assertAllRuleParametersHaveDescription(repository);
28 | }
29 |
30 | private void assertParameterProperties(RulesDefinition.Repository repository) {
31 | // TooManyLinesInFunctionCheck
32 | RulesDefinition.Param max = repository.rule("AvoidAnnotation").param("name");
33 | assertThat(max).isNotNull();
34 | assertThat(max.defaultValue()).isEqualTo("Inject");
35 | assertThat(max.description()).isEqualTo("Name of the annotation to avoid, without the prefix @, for instance 'Override'");
36 | assertThat(max.type()).isEqualTo(RuleParamType.STRING);
37 | }
38 |
39 | private void assertRuleProperties(RulesDefinition.Repository repository) {
40 | RulesDefinition.Rule rule = repository.rule("UnderlineDollarNameCheck");
41 | assertThat(rule).isNotNull();
42 | assertThat(rule.name()).isEqualTo("Can't use underline or Dollar first or end As Name");
43 | assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
44 | assertThat(rule.type()).isEqualTo(RuleType.BUG);
45 | }
46 |
47 | private void assertAllRuleParametersHaveDescription(RulesDefinition.Repository repository) {
48 | for (RulesDefinition.Rule rule : repository.rules()) {
49 | for (RulesDefinition.Param param : rule.params()) {
50 | assertThat(param.description()).as("description for " + param.key()).isNotEmpty();
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/checks/MyFirstCustomCheckTest.java:
--------------------------------------------------------------------------------
1 | //package org.finger.java.rule.checks;
2 | //
3 | //import org.junit.Test;
4 | //import org.sonar.java.checks.verifier.JavaCheckVerifier;
5 | //
6 | ///**
7 | // * Created by huqingen on 2017/3/16.
8 | // */
9 | //public class MyFirstCustomCheckTest {
10 | // @Test
11 | // public void test() {
12 | // JavaCheckVerifier.verify("src/test/files/MyFirstCustomCheck.java", new MyFirstCustomCheck());
13 | // }
14 | //}
15 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/checks/namerules/AbstractClassNameCheckTest.java:
--------------------------------------------------------------------------------
1 | package org.sonar.java.rule.checks.namerules;
2 |
3 | import org.junit.Test;
4 | import org.sonar.java.checks.verifier.JavaCheckVerifier;
5 |
6 | /**
7 | * Created by huqingen on 2017/3/17.
8 | */
9 | public class AbstractClassNameCheckTest {
10 | @Test
11 | public void test() {
12 | JavaCheckVerifier.verify("src/test/files/HiClass.java", new AbstractClassNameCheck());
13 | }
14 |
15 | @Test
16 | public void test1() {
17 | JavaCheckVerifier.verify("src/test/files/MyNameIsAbstract.java", new AbstractClassNameCheck());
18 | }
19 |
20 | @Test
21 | public void test2() {
22 | JavaCheckVerifier.verify("src/test/files/BaseMysql.java", new AbstractClassNameCheck());
23 | }
24 | @Test
25 | public void test3() {
26 | JavaCheckVerifier.verify("src/test/files/AbstractMysql.java", new AbstractClassNameCheck());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/checks/namerules/ArrayNameCheckTest.java:
--------------------------------------------------------------------------------
1 | package org.sonar.java.rule.checks.namerules;
2 |
3 | import org.junit.Test;
4 | import org.sonar.java.checks.verifier.JavaCheckVerifier;
5 |
6 | /**
7 | * Created by huqingen on 2017/3/18.
8 | */
9 | public class ArrayNameCheckTest {
10 | @Test
11 | public void test() {
12 | JavaCheckVerifier.verify("src/test/files/ArrayNameCheckMapper.java", new ArrayNameCheck());
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/checks/namerules/ConstantNameCheckTest.java:
--------------------------------------------------------------------------------
1 | package org.sonar.java.rule.checks.namerules;
2 |
3 | import org.junit.Test;
4 | import org.sonar.java.checks.verifier.JavaCheckVerifier;
5 |
6 | /**
7 | * Created by huqingen on 2017/3/17.
8 | */
9 | public class ConstantNameCheckTest {
10 | @Test
11 | public void test() {
12 | JavaCheckVerifier.verify("src/test/files/ConstantNameMapper.java", new ConstantNameCheck());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/checks/namerules/ExceptionClassNameCheckTest.java:
--------------------------------------------------------------------------------
1 | package org.sonar.java.rule.checks.namerules;
2 |
3 | import org.junit.Test;
4 | import org.sonar.java.checks.verifier.JavaCheckVerifier;
5 |
6 | /**
7 | * Created by huqingen on 2017/3/18.
8 | */
9 | public class ExceptionClassNameCheckTest {
10 | @Test
11 | public void test() {
12 | JavaCheckVerifier.verify("src/test/files/AgeOutOfBound.java", new ExceptionClassNameCheck());
13 | }
14 |
15 | @Test
16 | public void test1() {
17 | JavaCheckVerifier.verify("src/test/files/HiClass.java", new ExceptionClassNameCheck());
18 | }
19 |
20 | @Test
21 | public void test2() {
22 | JavaCheckVerifier.verify("src/test/files/AgeOutOfException.java", new ExceptionClassNameCheck());
23 | }
24 |
25 | @Test
26 | public void test3() {
27 | JavaCheckVerifier.verify("src/test/files/AgeOutOfExceptionBound.java", new ExceptionClassNameCheck());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/checks/namerules/LowerCameCaseChecTest.java:
--------------------------------------------------------------------------------
1 | package org.sonar.java.rule.checks.namerules;
2 |
3 | import org.junit.Test;
4 | import org.sonar.java.checks.verifier.JavaCheckVerifier;
5 |
6 | /**
7 | * Created by huqingen on 2017/3/17.
8 | */
9 | public class LowerCameCaseChecTest {
10 | @Test
11 | public void test() {
12 | try {
13 | JavaCheckVerifier.verify("src/test/files/LowerCameCaseMapper.java", new LowerCameCaseCheck());
14 | }catch (IllegalStateException e){
15 | e.printStackTrace();
16 | }
17 | }
18 |
19 | @Test
20 | public void test1() {
21 | JavaCheckVerifier.verify("src/test/files/Result.java", new LowerCameCaseCheck());
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/checks/namerules/UnderlineDollarNameCheckTest.java:
--------------------------------------------------------------------------------
1 | package org.sonar.java.rule.checks.namerules;
2 |
3 | import org.junit.Test;
4 | import org.sonar.java.checks.verifier.JavaCheckVerifier;
5 |
6 | /**
7 | * Created by huqingen on 2017/3/17.
8 | */
9 | public class UnderlineDollarNameCheckTest {
10 | @Test
11 | public void test() {
12 | JavaCheckVerifier.verify("src/test/files/UnderlineDollarRuleMapper.java", new UnderlineDollarNameCheck());
13 | }
14 | @Test
15 | public void test1(){
16 | JavaCheckVerifier.verify("src/test/files/ActionTestCase.java", new UnderlineDollarNameCheck());
17 | }
18 | @Test
19 | public void test2(){
20 | JavaCheckVerifier.verify("src/test/files/ActionTestCaseImpl.java", new UnderlineDollarNameCheck());
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/java/rule/checks/namerules/UpperCameCaseCheckTest.java:
--------------------------------------------------------------------------------
1 | package org.sonar.java.rule.checks.namerules;
2 |
3 | import org.junit.Test;
4 | import org.sonar.java.checks.verifier.JavaCheckVerifier;
5 |
6 | /**
7 | * Created by huqingen on 2017/3/17.
8 | */
9 | public class UpperCameCaseCheckTest {
10 | @Test
11 | public void test1() {
12 | JavaCheckVerifier.verify("src/test/files/macroPolo.java", new UpperCameCaseCheck());
13 | }
14 |
15 | @Test
16 | public void test2(){
17 | JavaCheckVerifier.verify("src/test/files/UserDo.java", new UpperCameCaseCheck());
18 | }
19 | @Test
20 | public void test3(){
21 | JavaCheckVerifier.verify("src/test/files/AbstractMysql.java", new UpperCameCaseCheck());
22 | }
23 | @Test
24 | public void test4(){
25 | JavaCheckVerifier.verify("src/test/files/ActionTestCase.java", new UpperCameCaseCheck());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------