1package org.testng.xml;
2
3import org.testng.Assert;
4import org.testng.annotations.DataProvider;
5import org.testng.annotations.Test;
6
7import java.io.File;
8import java.io.FileInputStream;
9
10import static test.SimpleBaseTest.getPathToResource;
11
12public class SuiteXmlParserTest {
13
14    private static final File PARENT = new File(getPathToResource("xml"));
15
16    @DataProvider
17    private static Object[][] dp() {
18        return new Object[][] {
19                { "goodWithDoctype.xml", true },
20                { "goodWithoutDoctype.xml", true },
21                { "badWithDoctype.xml", false }, // TestNGException -> SAXParseException
22                { "badWithoutDoctype.xml", false } // NullPointerException
23        };
24    }
25
26    @Test(dataProvider = "dp")
27    public void testParse(String fileName, boolean shouldWork) {
28        SuiteXmlParser parser = new SuiteXmlParser();
29
30        try (FileInputStream stream = new FileInputStream(new File(PARENT, fileName))) {
31            parser.parse(fileName, stream, false);
32            if (!shouldWork) {
33                Assert.fail("Parsing of " + fileName + " is supposed to fail");
34            }
35        } catch (Exception e) {
36            if (shouldWork) {
37                Assert.fail("Parsing of " + fileName + " is supposed to work");
38            }
39        }
40    }
41}