|
9 | 9 | import io.codemodder.remediation.SearcherStrategyRemediator; |
10 | 10 | import java.util.List; |
11 | 11 | import java.util.Optional; |
12 | | -import org.junit.jupiter.api.Test; |
| 12 | +import java.util.stream.Stream; |
| 13 | +import org.junit.jupiter.params.ParameterizedTest; |
| 14 | +import org.junit.jupiter.params.provider.Arguments; |
| 15 | +import org.junit.jupiter.params.provider.MethodSource; |
13 | 16 |
|
14 | 17 | final class XMLReaderAtParseFixerTest { |
15 | 18 |
|
16 | | - @Test |
17 | | - void it_fixes_xmlreaders_at_parse_call() { |
| 19 | + private static Stream<Arguments> provideRemediators() { |
| 20 | + return Stream.of( |
| 21 | + Arguments.of( |
| 22 | + new SearcherStrategyRemediator.Builder<>() |
| 23 | + .withMatchAndFixStrategy(new XMLReaderAtParseFixStrategy()) |
| 24 | + .build()), |
| 25 | + |
| 26 | + // now try with the previously conflicting parser strategy inline as well |
| 27 | + Arguments.of( |
| 28 | + new SearcherStrategyRemediator.Builder<>() |
| 29 | + .withMatchAndFixStrategy(new DocumentBuilderFactoryAtParseFixStrategy()) |
| 30 | + .withMatchAndFixStrategy(new XMLReaderAtParseFixStrategy()) |
| 31 | + .build()), |
| 32 | + |
| 33 | + // reverse the order to confirm no ordering issues |
| 34 | + Arguments.of( |
| 35 | + new SearcherStrategyRemediator.Builder<>() |
| 36 | + .withMatchAndFixStrategy(new XMLReaderAtParseFixStrategy()) |
| 37 | + .withMatchAndFixStrategy(new DocumentBuilderFactoryAtParseFixStrategy()) |
| 38 | + .build())); |
| 39 | + } |
| 40 | + |
| 41 | + @MethodSource("provideRemediators") |
| 42 | + @ParameterizedTest |
| 43 | + void it_fixes_xmlreaders_at_parse_call(final SearcherStrategyRemediator remediator) { |
18 | 44 | String vulnerableCode = |
19 | 45 | """ |
20 | 46 | public class MyCode { |
@@ -43,12 +69,8 @@ public void foo() { |
43 | 69 | CompilationUnit cu = StaticJavaParser.parse(vulnerableCode); |
44 | 70 | LexicalPreservingPrinter.setup(cu); |
45 | 71 |
|
46 | | - var searcherRemediator = |
47 | | - new SearcherStrategyRemediator.Builder<>() |
48 | | - .withMatchAndFixStrategy(new XMLReaderAtParseFixStrategy()) |
49 | | - .build(); |
50 | 72 | var result = |
51 | | - searcherRemediator.remediateAll( |
| 73 | + remediator.remediateAll( |
52 | 74 | cu, |
53 | 75 | "path", |
54 | 76 | new DetectorRule("", "", ""), |
|
0 commit comments