Skip to content

Commit

Permalink
Refactor failure test
Browse files Browse the repository at this point in the history
Signed-off-by: Jarno Elovirta <[email protected]>
  • Loading branch information
jelovirt committed May 9, 2024
1 parent 9c23b78 commit 86ac549
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
18 changes: 12 additions & 6 deletions src/test/java/com/elovirta/dita/markdown/MDitaReaderCoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import static org.junit.jupiter.api.Assertions.*;

import com.elovirta.dita.utils.AbstractReaderTest;
import java.io.InputStream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.opentest4j.AssertionFailedError;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class MDitaReaderCoreTest extends AbstractReaderTest {
Expand Down Expand Up @@ -81,11 +83,15 @@ public void test_unsupported(String file) {
@ParameterizedTest
@ValueSource(strings = { "header.md", "invalid_header.md", "invalid_header_third.md" })
public void test_fail(String file) {
try {
run(file);
fail();
} catch (Exception e) {
assertEquals(SAXException.class, e.getCause().getClass());
}
assertThrows(
SAXException.class,
() -> {
final String input = "/" + getSrc() + file;
try (final InputStream in = getClass().getResourceAsStream(input)) {
final InputSource i = new InputSource(in);
reader.parse(i);
}
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import com.elovirta.dita.utils.AbstractReaderTest;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class MDitaReaderExtendedTest extends AbstractReaderTest {
Expand Down Expand Up @@ -80,12 +82,16 @@ public void test(String file) throws Exception {
@ParameterizedTest
@ValueSource(strings = { "header.md", "invalid_header.md", "invalid_header_third.md" })
public void test_fail(String file) {
try {
run(file);
fail();
} catch (Exception e) {
assertEquals(SAXException.class, e.getCause().getClass());
}
assertThrows(
SAXException.class,
() -> {
final String input = "/" + getSrc() + file;
try (final InputStream in = getClass().getResourceAsStream(input)) {
final InputSource i = new InputSource(in);
reader.parse(i);
}
}
);
}

@Test
Expand Down
16 changes: 10 additions & 6 deletions src/test/java/com/elovirta/dita/markdown/MarkdownReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,16 @@ public void test_schemaParseFailure_withoutErrorHandler() throws Exception {
@ParameterizedTest
@ValueSource(strings = { "invalid_header.md" })
public void test_fail(String file) {
try {
run(file);
fail();
} catch (Exception e) {
assertEquals(SAXException.class, e.getCause().getClass());
}
assertThrows(
SAXException.class,
() -> {
final String input = "/" + getSrc() + file;
try (final InputStream in = getClass().getResourceAsStream(input)) {
final InputSource i = new InputSource(in);
reader.parse(i);
}
}
);
}

@ParameterizedTest
Expand Down

0 comments on commit 86ac549

Please sign in to comment.