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

Class TestBase

go/src/test/java/com/ibm/plugin/TestBase.java:42–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected