Skip to content

Commit 03c6c06

Browse files
committed
chore(refacto): 💥 Test files are now in one place
Tests files has been kept only in src/it/test-projects, Unit tests now read it from there... Also, suggestion to reorder each test file in a subfolder named after the rule number, like suggested for GCI67 Fixes #56
1 parent 2db61c3 commit 03c6c06

File tree

91 files changed

+718
-3019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+718
-3019
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- upgrade libraries versions
1616
- correction of technical problem with Integration tests (because of Maven format in technical answer to "sonar-orchestrator-junit5" library)
1717
- upgrade JDK from 11 to 17
18+
- huge refacto to have all the test files in the same place, to avoid maintaining 2...
1819

1920
### Deleted
2021

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@
236236
<groupId>org.apache.maven.plugins</groupId>
237237
<artifactId>maven-surefire-plugin</artifactId>
238238
<version>3.5.2</version>
239+
<configuration>
240+
<systemPropertyVariables>
241+
<testfiles.path>src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks</testfiles.path>
242+
</systemPropertyVariables>
243+
</configuration>
239244
</plugin>
240245
<plugin>
241246
<groupId>org.jacoco</groupId>

src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ void testGCI27() {
3333
String ruleId = "creedengo-java:GCI27";
3434
String ruleMsg = "Use System.arraycopy to copy arrays";
3535
int[] startLines = new int[]{
36-
51, 56, 63, 72, 85, 94,
37-
105, 116, 139, 145, 153, 163,
38-
177, 187, 199, 211, 229, 236,
39-
245, 256, 271, 282, 295, 308,
40-
334, 341, 350, 361, 376, 389,
41-
415, 422, 431, 442, 457, 470
36+
68, 73, 80, 89, 102, 111,
37+
122, 133, 156, 162, 170, 180,
38+
194, 204, 216, 228, 246, 253,
39+
262, 273, 288, 299, 312, 325,
40+
351, 358, 367, 378, 393, 406,
41+
432, 439, 448, 459, 474, 487
4242
};
4343
int[] endLines = new int[]{
44-
53, 60, 69, 82, 91, 102,
45-
113, 124, 141, 149, 159, 173,
46-
183, 195, 207, 219, 232, 241,
47-
252, 267, 278, 291, 304, 317,
48-
337, 346, 357, 372, 385, 398,
49-
418, 427, 438, 453, 466, 479
44+
70, 77, 86, 99, 108, 119,
45+
130, 141, 158, 166, 176, 190,
46+
200, 212, 224, 236, 249, 258,
47+
269, 284, 295, 308, 321, 334,
48+
354, 363, 374, 389, 402, 415,
49+
435, 444, 455, 470, 483, 496
5050
};
5151

5252
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
@@ -57,8 +57,8 @@ void testGCI27() {
5757
void testGCI74() {
5858

5959
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidFullSQLRequestCheck.java";
60-
int[] startLines = new int[]{8, 12, 17, 23};
61-
int[] endLines = new int[]{8, 12, 17, 23};
60+
int[] startLines = new int[]{25, 29, 34, 40};
61+
int[] endLines = new int[]{25, 29, 34, 40};
6262
String ruleId = "creedengo-java:GCI74";
6363
String ruleMsg = "Don't use the query SELECT * FROM";
6464

@@ -83,8 +83,8 @@ void testGCI3_forEachLoopIgnored() {
8383
void testGCI3_forLoopBad() {
8484

8585
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
86-
int[] startLines = new int[]{13};
87-
int[] endLines = new int[]{13};
86+
int[] startLines = new int[]{30};
87+
int[] endLines = new int[]{30};
8888
String ruleId = "creedengo-java:GCI3";
8989
String ruleMsg = "Avoid getting the size of the collection in the loop";
9090

@@ -122,8 +122,8 @@ void testGCI3_forLoopIgnored() {
122122
void testGCI3_whileLoopBad() {
123123

124124
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java";
125-
int[] startLines = new int[]{17};
126-
int[] endLines = new int[]{17};
125+
int[] startLines = new int[]{34};
126+
int[] endLines = new int[]{34};
127127
String ruleId = "creedengo-java:GCI3";
128128
String ruleMsg = "Avoid getting the size of the collection in the loop";
129129

@@ -163,17 +163,17 @@ void testGCI2() {
163163
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java";
164164

165165
int[] startLines = new int[]{
166-
24, 43, 45, 71, 88, 110,
167-
112, 131, 135, 137, 158, 164,
168-
190, 209, 212, 214, 211, 236,
169-
257, 259
166+
41, 60, 62, 88, 105, 127,
167+
129, 148, 152, 154, 175,
168+
181, 207, 226, 228, 229,
169+
231, 253, 274, 276
170170
};
171171

172172
int[] endLines = new int[]{
173-
24, 43, 47, 71, 90, 110,
174-
114, 133, 135, 139, 160, 166,
175-
192, 209, 212, 216, 217, 238,
176-
257, 261
173+
41, 60, 64, 88, 107, 127,
174+
131, 150, 152, 156, 177,
175+
183, 209, 226, 234, 229,
176+
233, 255, 274, 278
177177
};
178178

179179
String ruleId = "creedengo-java:GCI2";
@@ -251,8 +251,8 @@ void testGCI2_noIssue() {
251251
void testGCI77_invalid() {
252252

253253
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRegexPatternNotStatic.java";
254-
int[] startLines = new int[]{8};
255-
int[] endLines = new int[]{8};
254+
int[] startLines = new int[]{25};
255+
int[] endLines = new int[]{25};
256256
String ruleId = "creedengo-java:GCI77";
257257
String ruleMsg = "Avoid using Pattern.compile() in a non-static context.";
258258

@@ -304,20 +304,20 @@ void testGCI78() {
304304

305305
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSetConstantInBatchUpdateCheck.java";
306306
int[] startLines = new int[]{
307-
34, 35, 36, 37, 38, 39,
308-
40, 41, 42, 43, 44, 45,
309-
46, 61, 63, 64, 65, 66,
310-
67, 70, 86, 88, 90, 91,
311-
92, 93, 94, 96, 114, 116,
312-
117, 118, 119, 120, 121, 123
307+
51, 52, 53, 54, 55, 56,
308+
57, 58, 59, 60, 61, 62,
309+
63, 78, 80, 81, 82, 83,
310+
84, 87, 103, 105, 107, 108,
311+
109, 110, 111, 113, 131, 133,
312+
134, 135, 136, 137, 138, 140
313313
};
314314
int[] endLines = new int[]{
315-
34, 35, 36, 37, 38, 39,
316-
40, 41, 42, 43, 44, 45,
317-
46, 61, 63, 64, 65, 66,
318-
67, 70, 86, 88, 90, 91,
319-
92, 93, 94, 96, 114, 116,
320-
117, 118, 119, 120, 121, 123
315+
51, 52, 53, 54, 55, 56,
316+
57, 58, 59, 60, 61, 62,
317+
63, 78, 80, 81, 82, 83,
318+
84, 87, 103, 105, 107, 108,
319+
109, 110, 111, 113, 131, 133,
320+
134, 135, 136, 137, 138, 140
321321
};
322322
String ruleId = "creedengo-java:GCI78";
323323
String ruleMsg = "Avoid setting constants in batch update";
@@ -363,8 +363,8 @@ void testGCI72() {
363363
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSQLRequestInLoopCheck.java";
364364
String ruleId = "creedengo-java:GCI72";
365365
String ruleMsg = "Avoid SQL request in loop";
366-
int[] startLines = new int[]{57, 88, 119};
367-
int[] endLines = new int[]{57, 88, 119};
366+
int[] startLines = new int[]{74, 105, 136};
367+
int[] endLines = new int[]{74, 105, 136};
368368

369369
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN);
370370
}
@@ -374,8 +374,8 @@ void testGCI5() {
374374
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidStatementForDMLQueries.java";
375375
String ruleId = "creedengo-java:GCI5";
376376
String ruleMsg = "You must not use Statement for a DML query";
377-
int[] startLines = new int[]{18};
378-
int[] endLines = new int[]{18};
377+
int[] startLines = new int[]{32};
378+
int[] endLines = new int[]{32};
379379

380380
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_10MIN);
381381
}
@@ -385,8 +385,8 @@ void testGCI76() {
385385
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidUsageOfStaticCollections.java";
386386
String ruleId = "creedengo-java:GCI76";
387387
String ruleMsg = "Avoid usage of static collections.";
388-
int[] startLines = new int[]{10, 12, 14};
389-
int[] endLines = new int[]{10, 12, 14};
388+
int[] startLines = new int[]{27, 29, 31};
389+
int[] endLines = new int[]{27, 29, 31};
390390

391391
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_20MIN);
392392
}
@@ -407,8 +407,8 @@ void testGCI79() {
407407
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/FreeResourcesOfAutoCloseableInterface.java";
408408
String ruleId = "creedengo-java:GCI79";
409409
String ruleMsg = "try-with-resources Statement needs to be implemented for any object that implements the AutoClosable interface.";
410-
int[] startLines = new int[]{23};
411-
int[] endLines = new int[]{36};
410+
int[] startLines = new int[]{40};
411+
int[] endLines = new int[]{53};
412412

413413
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_15MIN);
414414
}
@@ -418,19 +418,19 @@ void testGCI32() {
418418
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/InitializeBufferWithAppropriateSize.java";
419419
String ruleId = "creedengo-java:GCI32";
420420
String ruleMsg = "Initialize StringBuilder or StringBuffer with appropriate size";
421-
int[] startLines = new int[]{16, 24};
422-
int[] endLines = new int[]{16, 24};
421+
int[] startLines = new int[]{33, 41};
422+
int[] endLines = new int[]{33, 41};
423423

424424
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
425425
}
426426

427427
@Test
428428
void testGCI67() {
429-
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/IncrementCheck.java";
429+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/gci67/IncrementCheck.java";
430430
String ruleId = "creedengo-java:GCI67";
431431
String ruleMsg = "Use ++i instead of i++";
432-
int[] startLines = new int[]{9, 19, 38};
433-
int[] endLines = new int[]{9, 19, 38};
432+
int[] startLines = new int[]{26, 36, 55};
433+
int[] endLines = new int[]{26, 36, 55};
434434

435435
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
436436
}
@@ -440,8 +440,8 @@ void testGCI82() {
440440
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java";
441441
String ruleId = "creedengo-java:GCI82";
442442
String ruleMsg = "The variable is never reassigned and can be 'final'";
443-
int[] startLines = new int[]{7, 12, 13, 45};
444-
int[] endLines = new int[]{7, 12, 13, 45};
443+
int[] startLines = new int[]{26, 31, 32, 64};
444+
int[] endLines = new int[]{26, 31, 32, 64};
445445

446446
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
447447
}
@@ -451,8 +451,8 @@ void testGCI69() {
451451
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/NoFunctionCallWhenDeclaringForLoop.java";
452452
String ruleId = "creedengo-java:GCI69";
453453
String ruleMsg = "Do not call a function when declaring a for-type loop";
454-
int[] startLines = new int[]{58, 66, 74, 101};
455-
int[] endLines = new int[]{58, 66, 74, 101};
454+
int[] startLines = new int[]{60, 68, 76, 103};
455+
int[] endLines = new int[]{60, 68, 76, 103};
456456

457457
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
458458
}
@@ -462,9 +462,9 @@ void testGCI28() {
462462

463463
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java";
464464

465-
int[] startLines = new int[]{23};
465+
int[] startLines = new int[]{38};
466466

467-
int[] endLines = new int[]{23};
467+
int[] endLines = new int[]{38};
468468

469469
String ruleId = "creedengo-java:GCI28";
470470
String ruleMsg = "Optimize Read File Exceptions";
@@ -478,9 +478,9 @@ void testGCI28_2() {
478478

479479
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java";
480480

481-
int[] startLines = new int[]{20};
481+
int[] startLines = new int[]{37};
482482

483-
int[] endLines = new int[]{20};
483+
int[] endLines = new int[]{37};
484484

485485
String ruleId = "creedengo-java:GCI28";
486486
String ruleMsg = "Optimize Read File Exceptions";
@@ -494,9 +494,9 @@ void testGCI28_3() {
494494

495495
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java";
496496

497-
int[] startLines = new int[]{19};
497+
int[] startLines = new int[]{36};
498498

499-
int[] endLines = new int[]{19};
499+
int[] endLines = new int[]{36};
500500

501501
String ruleId = "creedengo-java:GCI28";
502502
String ruleMsg = "Optimize Read File Exceptions";
@@ -510,9 +510,9 @@ void testGCI28_4() {
510510

511511
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java";
512512

513-
int[] startLines = new int[]{18};
513+
int[] startLines = new int[]{35};
514514

515-
int[] endLines = new int[]{18};
515+
int[] endLines = new int[]{35};
516516

517517
String ruleId = "creedengo-java:GCI28";
518518
String ruleMsg = "Optimize Read File Exceptions";
@@ -526,9 +526,9 @@ void testGCI28_5() {
526526

527527
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java";
528528

529-
int[] startLines = new int[]{18};
529+
int[] startLines = new int[]{35};
530530

531-
int[] endLines = new int[]{18};
531+
int[] endLines = new int[]{35};
532532

533533
String ruleId = "creedengo-java:GCI28";
534534
String ruleMsg = "Optimize Read File Exceptions";
@@ -542,8 +542,8 @@ void testGCI94() {
542542
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/UseOptionalOrElseGetVsOrElse.java";
543543
String ruleId = "creedengo-java:GCI94";
544544
String ruleMsg = "Use optional orElseGet instead of orElse.";
545-
int[] startLines = new int[]{25};
546-
int[] endLines = new int[]{25};
545+
int[] startLines = new int[]{27};
546+
int[] endLines = new int[]{27};
547547

548548
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_1MIN);
549549
}

0 commit comments

Comments
 (0)