package edu.hm.hafner.analysis.parser.violations;

import org.junit.jupiter.api.Test;

import edu.hm.hafner.analysis.AbstractParserTest;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.assertions.SoftAssertions;

import static edu.hm.hafner.analysis.assertions.Assertions.*;

/**
 * Tests the class {@link SarifAdapter}.
 *
 * @author Ullrich Hafner
 */
class SarifAdapterTest extends AbstractParserTest {
    SarifAdapterTest() {
        super("sarif.json");
    }

    @Override
    protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
        softly.assertThat(report).hasSize(2);
        softly.assertThat(report.get(0))
                .hasMessage("asdasd asdasd")
                .hasFileName("/whatever/path.c")
                .hasLineStart(123)
                .hasType("Cyclomatic complexity")
                .hasSeverity(Severity.WARNING_HIGH);
        softly.assertThat(report.get(1))
                .hasMessage("asdasd asdasd")
                .hasFileName("/whatever/path.c")
                .hasLineStart(123)
                .hasType("-")
                .hasSeverity(Severity.WARNING_LOW);
    }

    @Test
    void shouldReportDifferentSeverities() {
        Report report = parse("security-scan.sarif");

        assertThat(report).hasSize(51);
        assertThat(report.getSizeOf(Severity.WARNING_HIGH)).isEqualTo(3);
        assertThat(report.getSizeOf(Severity.WARNING_NORMAL)).isEqualTo(45);
        assertThat(report.getSizeOf(Severity.WARNING_LOW)).isEqualTo(3);
    }

    @Override
    protected SarifAdapter createParser() {
        return new SarifAdapter();
    }

}

@@ -723,53 +723,8 @@
 0))%0A
-                .hasMessage(%22asdasd asdasd%22)%0A
     
@@ -947,47 +947,40 @@
 get(
-1))%0A                .hasMessage
+0).getMessage()).matches
 (%22asdasd
  asd
@@ -979,17 +979,20 @@
 dasd
- 
+%5C%5Cs*
 asdasd%22)
 %0A   
@@ -987,16 +987,58 @@
 asdasd%22)
+;%0A        softly.assertThat(report.get(1))
 %0A       
@@ -1196,16 +1196,99 @@
 G_LOW);%0A
+        softly.assertThat(report.get(1).getMessage()).matches(%22asdasd%5C%5Cs*asdasd%22);%0A
     %7D%0A%0A 

Fix Sarif `message` that now can contain new lines.