| 40 | import org.sonar.plugins.python.api.tree.Tree; |
| 41 | |
| 42 | public abstract class TestBase extends PythonInventoryRule { |
| 43 | |
| 44 | @Nonnull |
| 45 | private final DetectionStoreLogger<PythonCheck, Tree, Symbol, PythonVisitorContext> |
| 46 | detectionStoreLogger = 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(PythonDetectionRules.rules()); |
| 56 | } |
| 57 | |
| 58 | @Before |
| 59 | public void debug() { |
| 60 | LogTesterJUnit5 logTesterJUnit5 = new LogTesterJUnit5(); |
| 61 | logTesterJUnit5.setLevel(Level.DEBUG); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void update(@Nonnull Finding<PythonCheck, Tree, Symbol, PythonVisitorContext> finding) { |
| 66 | final DetectionStore<PythonCheck, Tree, Symbol, PythonVisitorContext> detectionStore = |
| 67 | finding.detectionStore(); |
| 68 | detectionStoreLogger.print(detectionStore); |
| 69 | |
| 70 | List<INode> nodes = pythonTranslationProcess.initiate(detectionStore); |
| 71 | asserts(findingId, detectionStore, nodes); |
| 72 | findingId++; |
| 73 | // report |
| 74 | this.report(finding.getMarkerTree(), nodes) |
| 75 | .forEach( |
| 76 | issue -> |
| 77 | finding.detectionStore() |
| 78 | .getScanContext() |
| 79 | .reportIssue(this, issue.tree(), issue.message())); |
| 80 | } |
| 81 | |
| 82 | public abstract void asserts( |
| 83 | int findingId, |
| 84 | @Nonnull DetectionStore<PythonCheck, Tree, Symbol, PythonVisitorContext> detectionStore, |
| 85 | @Nonnull List<INode> nodes); |
| 86 | |
| 87 | @Nullable public DetectionStore<PythonCheck, Tree, Symbol, PythonVisitorContext> getStoreOfValueType( |
| 88 | @Nonnull final Class<? extends IValue> valueType, |
| 89 | @Nonnull |
| 90 | List<DetectionStore<PythonCheck, Tree, Symbol, PythonVisitorContext>> |
| 91 | detectionStores) { |
| 92 | Optional<DetectionStore<PythonCheck, Tree, Symbol, PythonVisitorContext>> relevantStore = |
| 93 | detectionStores.stream() |
| 94 | .filter( |
| 95 | store -> |
| 96 | store.getDetectionValues().stream() |
| 97 | .anyMatch( |
| 98 | value -> |
| 99 | value.getClass().equals(valueType))) |
nothing calls this directly
no outgoing calls
no test coverage detected