Skip to content

Switch to Junit 5 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ limitations under the License.

<scm>
<connection>scm:git:https://github.com/codehaus-plexus/plexus-xml.git</connection>
<developerConnection>scm:git:https://github.com/codehaus-plexus/plexus-xml.git</developerConnection>
<developerConnection>${project.scm.connection}</developerConnection>
<tag>3.x</tag>
<url>https://github.com/codehaus-plexus/plexus-xml/tree/${project.scm.tag}/</url>
</scm>
Expand All @@ -52,12 +52,6 @@ limitations under the License.
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>4.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
Expand All @@ -71,9 +65,14 @@ limitations under the License.
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>4.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import java.util.NoSuchElementException;

import org.codehaus.plexus.util.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Test of {@link org.codehaus.plexus.util.xml.PrettyPrintXMLWriter}
Expand All @@ -50,15 +50,15 @@ public class PrettyPrintXMLWriterTest {
/**
* <p>setUp.</p>
*/
@Before
@BeforeEach
public void setUp() {
initWriter();
}

/**
* <p>tearDown.</p>
*/
@After
@AfterEach
public void tearDown() {
writer = null;
w = null;
Expand Down Expand Up @@ -175,7 +175,7 @@ public void testendElementAlreadyClosed() {
public void testIssue51DetectJava7ConcatenationBug() throws IOException {
File dir = new File("target/test-xml");
if (!dir.exists()) {
assertTrue("cannot create directory test-xml", dir.mkdir());
assertTrue(dir.mkdir(), "cannot create directory test-xml");
}
File xmlFile = new File(dir, "test-issue-51.xml");
OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(xmlFile.toPath()), "UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import java.io.InputStream;
import java.io.SequenceInputStream;

import junit.framework.ComparisonFailure;
import junit.framework.TestCase;
import org.codehaus.plexus.util.IOUtil;
import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* <p>XmlStreamReaderTest class.</p>
Expand All @@ -32,7 +35,7 @@
* @version $Id: $Id
* @since 3.4.0
*/
public class XmlStreamReaderTest extends TestCase {
public class XmlStreamReaderTest {
/** french */
private static final String TEXT_LATIN1 = "eacute: \u00E9";

Expand Down Expand Up @@ -111,6 +114,7 @@ private static void checkXmlStreamReader(String text, String encoding, String ef
*
* @throws java.io.IOException if any.
*/
@Test
public void testNoXmlHeader() throws IOException {
String xml = "<text>text with no XML header</text>";
checkXmlContent(xml, "UTF-8");
Expand All @@ -122,6 +126,7 @@ public void testNoXmlHeader() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testDefaultEncoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8");
checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8", BOM_UTF8);
Expand All @@ -132,6 +137,7 @@ public void testDefaultEncoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testUTF8Encoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, "UTF-8");
checkXmlStreamReader(TEXT_UNICODE, "UTF-8", BOM_UTF8);
Expand All @@ -142,6 +148,7 @@ public void testUTF8Encoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testUTF16Encoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", null);
checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE);
Expand All @@ -153,6 +160,7 @@ public void testUTF16Encoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testUTF16BEEncoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, "UTF-16BE");
}
Expand All @@ -162,6 +170,7 @@ public void testUTF16BEEncoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testUTF16LEEncoding() throws IOException {
checkXmlStreamReader(TEXT_UNICODE, "UTF-16LE");
}
Expand All @@ -171,6 +180,7 @@ public void testUTF16LEEncoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testLatin1Encoding() throws IOException {
checkXmlStreamReader(TEXT_LATIN1, "ISO-8859-1");
}
Expand All @@ -180,6 +190,7 @@ public void testLatin1Encoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testLatin7Encoding() throws IOException {
checkXmlStreamReader(TEXT_LATIN7, "ISO-8859-7");
}
Expand All @@ -189,6 +200,7 @@ public void testLatin7Encoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testLatin15Encoding() throws IOException {
checkXmlStreamReader(TEXT_LATIN15, "ISO-8859-15");
}
Expand All @@ -198,6 +210,7 @@ public void testLatin15Encoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testEUC_JPEncoding() throws IOException {
checkXmlStreamReader(TEXT_EUC_JP, "EUC-JP");
}
Expand All @@ -207,6 +220,7 @@ public void testEUC_JPEncoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testEBCDICEncoding() throws IOException {
checkXmlStreamReader("simple text in EBCDIC", "CP1047");
}
Expand All @@ -216,20 +230,21 @@ public void testEBCDICEncoding() throws IOException {
*
* @throws java.io.IOException if any.
*/
@Test
public void testInappropriateEncoding() throws IOException {
try {
checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2");
fail("Check should have failed, since some characters are not available in the specified encoding");
} catch (ComparisonFailure cf) {
// expected failure, since the encoding does not contain some characters
}
// expected failure, since the encoding does not contain some characters
assertThrows(
AssertionFailedError.class,
() -> checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2"),
"Check should have failed, since some characters are not available in the specified encoding");
}

/**
* <p>testEncodingAttribute.</p>
*
* @throws java.io.IOException if any.
*/
@Test
public void testEncodingAttribute() throws IOException {
String xml = "<?xml version='1.0' encoding='US-ASCII'?><element encoding='attribute value'/>";
checkXmlContent(xml, "US-ASCII");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* <p>XmlStreamWriterTest class.</p>
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@

import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

/**
* Test the {@link org.codehaus.plexus.util.xml.XmlUtil} class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import java.io.Writer;

import org.codehaus.plexus.util.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

/**
* <p>XmlWriterUtilTest class.</p>
Expand All @@ -47,7 +46,7 @@ public class XmlWriterUtilTest {
*
* @throws java.lang.Exception if any.
*/
@Before
@BeforeEach
public void setUp() throws Exception {
output = new ByteArrayOutputStream();
writer = WriterFactory.newXmlWriter(output);
Expand All @@ -59,7 +58,7 @@ public void setUp() throws Exception {
*
* @throws java.lang.Exception if any.
*/
@After
@AfterEach
public void tearDown() throws Exception {
xmlWriter = null;
writer = null;
Expand Down
41 changes: 18 additions & 23 deletions src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

/**
* Test the Xpp3DomBuilder.
Expand All @@ -52,7 +50,7 @@ public void testBuildFromReader() throws Exception {

Xpp3Dom expectedDom = createExpectedDom();

assertEquals("check DOMs match", expectedDom, dom);
assertEquals(expectedDom, dom, "check DOMs match");
}

/**
Expand All @@ -66,12 +64,11 @@ public void testBuildTrimming() throws Exception {

Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true);

assertEquals("test with trimming on", "element1", dom.getChild("el1").getValue());
assertEquals("element1", dom.getChild("el1").getValue(), "test with trimming on");

dom = Xpp3DomBuilder.build(new StringReader(domString), false);

assertEquals(
"test with trimming off", " element1\n ", dom.getChild("el1").getValue());
assertEquals(" element1\n ", dom.getChild("el1").getValue(), "test with trimming off");
}

/**
Expand Down Expand Up @@ -116,10 +113,10 @@ public void testBuildFromXpp3Dom() throws Exception {
eventType = parser.next();
}

assertEquals("Check DOM matches", expectedDom, dom);
assertFalse("Check closing root was consumed", rootClosed);
assertTrue("Check continued to parse configuration", configurationClosed);
assertTrue("Check continued to parse newRoot", newRootClosed);
assertEquals(expectedDom, dom, "Check DOM matches");
assertFalse(rootClosed, "Check closing root was consumed");
assertTrue(configurationClosed, "Check continued to parse configuration");
assertTrue(newRootClosed, "Check continued to parse newRoot");
}

/**
Expand Down Expand Up @@ -149,15 +146,13 @@ public void testUnclosedXml() {
public void testEscapingInContent() throws IOException, XmlPullParserException {
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString()));

assertEquals("Check content value", "\"text\"", dom.getChild("el").getValue());
assertEquals(
"Check content value", "<b>\"text\"</b>", dom.getChild("ela").getValue());
assertEquals(
"Check content value", "<b>\"text\"</b>", dom.getChild("elb").getValue());
assertEquals("\"text\"", dom.getChild("el").getValue(), "Check content value");
assertEquals("<b>\"text\"</b>", dom.getChild("ela").getValue(), "Check content value");
assertEquals("<b>\"text\"</b>", dom.getChild("elb").getValue(), "Check content value");

StringWriter w = new StringWriter();
Xpp3DomWriter.write(w, dom);
assertEquals("Compare stringified DOMs", getExpectedString(), w.toString());
assertEquals(getExpectedString(), w.toString(), "Compare stringified DOMs");
}

/**
Expand All @@ -171,12 +166,12 @@ public void testEscapingInAttributes() throws IOException, XmlPullParserExceptio
String s = getAttributeEncodedString();
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s));

assertEquals("Check attribute value", "<foo>", dom.getChild("el").getAttribute("att"));
assertEquals("<foo>", dom.getChild("el").getAttribute("att"), "Check attribute value");

StringWriter w = new StringWriter();
Xpp3DomWriter.write(w, dom);
String newString = w.toString();
assertEquals("Compare stringified DOMs", newString, s);
assertEquals(newString, s, "Compare stringified DOMs");
}

/**
Expand All @@ -194,16 +189,16 @@ public Object toInputLocation(XmlPullParser parser) {
};
Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(createDomString()), true, ilb);
Xpp3Dom expectedDom = createExpectedDom();
assertEquals("root input location", expectedDom.getInputLocation(), dom.getInputLocation());
assertEquals(expectedDom.getInputLocation(), dom.getInputLocation(), "root input location");
for (int i = 0; i < dom.getChildCount(); i++) {
Xpp3Dom elt = dom.getChild(i);
Xpp3Dom expectedElt = expectedDom.getChild(i);
assertEquals(elt.getName() + " input location", expectedElt.getInputLocation(), elt.getInputLocation());
assertEquals(expectedElt.getInputLocation(), elt.getInputLocation(), elt.getName() + " input location");

if ("el2".equals(elt.getName())) {
Xpp3Dom el3 = elt.getChild(0);
Xpp3Dom expectedEl3 = expectedElt.getChild(0);
assertEquals(el3.getName() + " input location", expectedEl3.getInputLocation(), el3.getInputLocation());
assertEquals(expectedEl3.getInputLocation(), el3.getInputLocation(), el3.getName() + " input location");
}
}
}
Expand Down
Loading