forked from phoedos/pmd
[test-schema] Migrate test to JUnit5
This commit is contained in:
@ -38,17 +38,14 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.stefanbirkner</groupId>
|
||||
<artifactId>system-rules</artifactId>
|
||||
<artifactId>system-lambda</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
|
@ -4,17 +4,15 @@
|
||||
|
||||
package net.sourceforge.pmd.test.schema;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.contrib.java.lang.system.SystemErrRule;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
@ -22,17 +20,15 @@ import net.sourceforge.pmd.lang.PlainTextLanguage;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.rule.AbstractRule;
|
||||
|
||||
import com.github.stefanbirkner.systemlambda.SystemLambda;
|
||||
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class TestSchemaParserTest {
|
||||
|
||||
@Rule
|
||||
public final SystemErrRule errStreamCaptor = new SystemErrRule().muteForSuccessfulTests();
|
||||
|
||||
class TestSchemaParserTest {
|
||||
|
||||
@Test
|
||||
public void testSchemaSimple() throws IOException {
|
||||
void testSchemaSimple() throws IOException {
|
||||
String file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
+ "<test-data\n"
|
||||
+ " xmlns=\"http://pmd.sourceforge.net/rule-tests\"\n"
|
||||
@ -59,11 +55,10 @@ public class TestSchemaParserTest {
|
||||
RuleTestCollection parsed = parseFile(file);
|
||||
|
||||
assertEquals(2, parsed.getTests().size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaDeprecatedAttr() throws IOException {
|
||||
void testSchemaDeprecatedAttr() throws Exception {
|
||||
String file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
+ "<test-data\n"
|
||||
+ " xmlns=\"http://pmd.sourceforge.net/rule-tests\"\n"
|
||||
@ -79,16 +74,17 @@ public class TestSchemaParserTest {
|
||||
+ " </test-code>\n"
|
||||
+ "</test-data>\n";
|
||||
|
||||
errStreamCaptor.enableLog();
|
||||
String log = SystemLambda.tapSystemErr(() -> {
|
||||
RuleTestCollection parsed = parseFile(file);
|
||||
|
||||
assertEquals(1, parsed.getTests().size());
|
||||
MatcherAssert.assertThat(errStreamCaptor.getLog(), containsString(" 6| <test-code regressionTest='false'>\n"
|
||||
});
|
||||
|
||||
assertThat(log, containsString(" 6| <test-code regressionTest='false'>\n"
|
||||
+ " ^^^^^^^^^^^^^^ Attribute 'regressionTest' is deprecated, use 'disabled' with inverted value\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownProperty() throws IOException {
|
||||
void testUnknownProperty() throws Exception {
|
||||
String file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
+ "<test-data\n"
|
||||
+ " xmlns=\"http://pmd.sourceforge.net/rule-tests\"\n"
|
||||
@ -105,10 +101,11 @@ public class TestSchemaParserTest {
|
||||
+ " </test-code>\n"
|
||||
+ "</test-data>\n";
|
||||
|
||||
errStreamCaptor.enableLog();
|
||||
String log = SystemLambda.tapSystemErr(() -> {
|
||||
assertThrows(IllegalStateException.class, () -> parseFile(file));
|
||||
});
|
||||
|
||||
MatcherAssert.assertThat(errStreamCaptor.getLog(), containsString(" 8| <rule-property name='invalid_property'>foo</rule-property>\n"
|
||||
assertThat(log, containsString(" 8| <rule-property name='invalid_property'>foo</rule-property>\n"
|
||||
+ " ^^^^ Unknown property, known property names are violationSuppressRegex, violationSuppressXPath\n"));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user