Skip to content

Commit

Permalink
Issue #12099: Add ArchUnit test to ensure fields are modules and util…
Browse files Browse the repository at this point in the history
…s are immutable and modules are correctly annotated
  • Loading branch information
Vyom-Yadav committed Aug 31, 2022
1 parent 1b92ac8 commit 15451dd
Show file tree
Hide file tree
Showing 3 changed files with 403 additions and 5 deletions.
6 changes: 5 additions & 1 deletion config/pmd-test.xml
Expand Up @@ -119,7 +119,9 @@
from the test method.
In XdocsPagesTest PMD does not find asserts in lambdas.
All test classes which starts with XpathRegression have asserts inside parent's method.
In ArchUnitTest assertion calls are not required as they are called by the library -->
In ArchUnitTest assertion calls are not required as they are called by the library
In ImmutabilityTest assertion calls are not required as they are called
by the library -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@SimpleName='AllChecksTest'
or @SimpleName='AstRegressionTest'
Expand All @@ -132,6 +134,8 @@
//MethodDeclaration[@Name='testAllCheckSectionJavaDocs']
| //ClassOrInterfaceDeclaration[starts-with(@SimpleName,'XpathRegression')]
//MethodDeclaration
| //ClassOrInterfaceDeclaration[@SimpleName='ImmutabilityTest']
//MethodDeclaration
| //ClassOrInterfaceDeclaration[@SimpleName='ArchUnitTest']
//MethodDeclaration"/>
</properties>
Expand Down
Expand Up @@ -22,8 +22,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -67,10 +69,11 @@ private XmlMetaReader() {
*
* @param thirdPartyPackages fully qualified third party package names(can be only a
* hint, e.g. for SevNTU it can be com.github.sevntu / com.github)
* @return list of module details found in the classpath satisfying the above conditions
* @return map of module full qualified name to module details found in the classpath satisfying
* the above conditions
* @throws IllegalStateException if there was a problem reading the module metadata files
*/
public static List<ModuleDetails> readAllModulesIncludingThirdPartyIfAny(
public static Map<String, ModuleDetails> readAllModulesIncludingThirdPartyIfAny(
String... thirdPartyPackages) {
final Set<String> standardModuleFileNames = new Reflections(
"com.puppycrawl.tools.checkstyle.meta", Scanners.Resources)
Expand All @@ -83,7 +86,7 @@ public static List<ModuleDetails> readAllModulesIncludingThirdPartyIfAny(
allMetadataSources.addAll(thirdPartyModuleFileNames);
}

final List<ModuleDetails> result = new ArrayList<>(allMetadataSources.size());
final Map<String, ModuleDetails> result = new HashMap<>(allMetadataSources.size(), 1.0F);
for (String fileName : allMetadataSources) {
final ModuleType moduleType;
if (fileName.endsWith("FileFilter.xml")) {
Expand All @@ -104,7 +107,7 @@ else if (fileName.endsWith("Filter.xml")) {
throw new IllegalStateException("Problem to read all modules including third "
+ "party if any. Problem detected at file: " + fileName, ex);
}
result.add(moduleDetails);
result.put(moduleDetails.getFullQualifiedName(), moduleDetails);
}

return result;
Expand Down

0 comments on commit 15451dd

Please sign in to comment.