update test class
@@ -3,6 +3,7 @@ package io.jenkins.plugins.analysis.core.model;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Collection;
+import java.util.List;
import java.util.function.Function;
import org.junit.jupiter.api.Test;
@@ -10,13 +11,17 @@ import org.junit.jupiter.api.Test;
import edu.hm.hafner.analysis.AbstractParser;
import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
-import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.Issues;
import edu.hm.hafner.analysis.Priority;
import static io.jenkins.plugins.analysis.core.testutil.Assertions.assertThat;
import static org.mockito.Mockito.*;
-public class StaticAnalysisToolSuiteTest {
+/**
+ * Tests the class {@link StaticAnalysisToolSuite}.
+ *
+ * @author Arne Schntag
+ */
+class StaticAnalysisToolSuiteTest {
private Issue issue = new IssueBuilder().setMessage("test")
.setFileName("filename")
@@ -38,22 +43,53 @@ public class StaticAnalysisToolSuiteTest {
};
//parse
+
@Test
- void shouldBeOkIfCreateDoesNotReturnNull() {
- IssueParser<Issue> parser = suite.createParser();
- assertThat(parser).isNotNull();
+ void shouldBeOkIfAsListDoesContainParser() {
+ List<AbstractParser<Issue>> result = (List<AbstractParser<Issue>>) suite.asList(parser);
+ assertThat(result).contains(this.parser);
}
@Test
- void shouldBeOkIfAsListDoesNotReturnNull() {
- Collection<? extends AbstractParser<Issue>> result = suite.asList();
- assertThat(result).isNotNull();
+ void shouldBeOkIfParseIsPerformedCorrectlyWithOneParser() {
+ Issues<Issue> issues = suite.createParser().parse(file, charset, func);
+ verify(parser, times(1)).parse(file, charset, func);
+ assertThat(issues.get(0)).isEqualTo(issue);
}
@Test
- void shouldBeOkIfParseIsCalledExactlyOnce() {
- suite.createParser().parse(file, charset, func);
- verify(parser, times(1)).parse(file, charset, func);
+ void shouldBeOkIfParseIsPerformedCorrectlyWithMoreParsers() {
+ AbstractParser<Issue> parser2 = mock(AbstractParser.class);
+ Issue issue2 = new IssueBuilder().setMessage("second")
+ .setFileName("filename2")
+ .setPriority(Priority.LOW)
+ .build();
+
+ AbstractParser<Issue> parser3 = mock(AbstractParser.class);
+ Issue issue3 = new IssueBuilder().setMessage("third")
+ .setFileName("filename3")
+ .setPriority(Priority.NORMAL)
+ .build();
+
+ StaticAnalysisToolSuite toolSuite = new StaticAnalysisToolSuite() {
+ @Override
+ protected Collection<? extends AbstractParser<Issue>> getParsers() {
+ Issues<Issue> list = new Issues<>();
+ list.add(issue);
+ when(parser.parse(file, charset, func)).thenReturn(list);
+
+ Issues<Issue> list2 = new Issues<>();
+ list.add(issue2);
+ when(parser2.parse(file, charset, func)).thenReturn(list2);
+
+ Issues<Issue> list3 = new Issues<>();
+ list.add(issue3);
+ when(parser3.parse(file, charset, func)).thenReturn(list3);
+ return asList(parser, parser2, parser3);
+ }
+ };
+ Issues<Issue> issues = toolSuite.createParser().parse(file, charset, func);
+ assertThat(issues).hasSize(3);
}
}
\ No newline at end of file
