MCPcopy Create free account
hub / github.com/cbomkit/sonar-cryptography / TestBase

Class TestBase

java/src/test/java/com/ibm/plugin/TestBase.java:44–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42import org.sonar.plugins.java.api.tree.Tree;
43
44public abstract class TestBase extends JavaInventoryRule {
45
46 @Nonnull
47 private final DetectionStoreLogger<JavaCheck, Tree, Symbol, JavaFileScannerContext>
48 detectionStoreLogger = new DetectionStoreLogger<>();
49
50 private int findingId = 0;
51
52 public TestBase(@Nonnull List<IDetectionRule<Tree>> detectionRules) {
53 super(detectionRules);
54 }
55
56 public TestBase() {
57 super(JavaDetectionRules.rules());
58 }
59
60 @BeforeEach
61 public void resetState() {
62 JavaAggregator.reset();
63 }
64
65 @BeforeEach
66 public void debug() {
67 LogTesterJUnit5 logTesterJUnit5 = new LogTesterJUnit5();
68 logTesterJUnit5.setLevel(Level.DEBUG);
69 }
70
71 @Override
72 public void update(@Nonnull Finding<JavaCheck, Tree, Symbol, JavaFileScannerContext> finding) {
73 final DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext> detectionStore =
74 finding.detectionStore();
75 detectionStoreLogger.print(detectionStore);
76
77 final List<INode> nodes = javaTranslationProcess.initiate(detectionStore);
78 asserts(findingId, detectionStore, nodes);
79 findingId++;
80 // report
81 this.report(finding.getMarkerTree(), nodes)
82 .forEach(
83 issue ->
84 finding.detectionStore()
85 .getScanContext()
86 .reportIssue(this, issue.tree(), issue.message()));
87 }
88
89 public abstract void asserts(
90 int findingId,
91 @Nonnull DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext> detectionStore,
92 @Nonnull List<INode> nodes);
93
94 @Nullable public DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext> getStoreWithValue(
95 @Nonnull
96 List<DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext>>
97 detectionStores) {
98 return detectionStores.stream()
99 .filter(store -> !store.getDetectionValues().isEmpty())
100 .findFirst()
101 .orElse(null);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected