Skip to content

Switch to junit 5 #2

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
Apr 17, 2023
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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ 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>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
* limitations under the License.
*/

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
Expand All @@ -30,9 +26,14 @@
import javax.swing.text.html.HTML.Tag;

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.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
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 @@ -51,7 +52,7 @@ public class PrettyPrintXMLWriterTest
/**
* <p>setUp.</p>
*/
@Before
@BeforeEach
public void setUp()
{
initWriter();
Expand All @@ -60,7 +61,7 @@ public void setUp()
/**
* <p>tearDown.</p>
*/
@After
@AfterEach
public void tearDown()
{
writer = null;
Expand Down Expand Up @@ -161,18 +162,12 @@ public void testEscapeXmlAttribute()
@Test
public void testendElementAlreadyClosed()
{
try
{
assertThrows(NoSuchElementException.class, () -> {
writer.startElement( Tag.DIV.toString() );
writer.addAttribute( "class", "someattribute" );
writer.endElement(); // Tag.DIV closed
writer.endElement(); // Tag.DIV already closed, and there is no other outer tag!
fail( "Should throw a NoSuchElementException" );
}
catch ( NoSuchElementException e )
{
assert ( true );
}
});
}

/**
Expand All @@ -190,16 +185,15 @@ public void testIssue51DetectJava7ConcatenationBug()
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" );
writer = new PrettyPrintXMLWriter( osw );

int iterations = 20000;

try
try ( OutputStreamWriter osw = new OutputStreamWriter( Files.newOutputStream( xmlFile.toPath() ), "UTF-8" ) )
{
writer = new PrettyPrintXMLWriter( osw );
for ( int i = 0; i < iterations; ++i )
{
writer.startElement( Tag.DIV.toString() + i );
Expand All @@ -214,13 +208,6 @@ public void testIssue51DetectJava7ConcatenationBug()
{
fail( "Should not throw a NoSuchElementException" );
}
finally
{
if ( osw != null )
{
osw.close();
}
}
}

private void writeXhtmlHead( XMLWriter writer )
Expand Down
36 changes: 24 additions & 12 deletions src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@

import org.codehaus.plexus.util.IOUtil;

import junit.framework.ComparisonFailure;
import junit.framework.TestCase;
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;
import static org.junit.jupiter.api.Assertions.fail;

/**
* <p>XmlStreamReaderTest class.</p>
Expand All @@ -34,7 +38,6 @@
* @since 3.4.0
*/
public class XmlStreamReaderTest
extends TestCase
{
/** french */
private static final String TEXT_LATIN1 = "eacute: \u00E9";
Expand Down Expand Up @@ -127,6 +130,7 @@ private static void checkXmlStreamReader( String text, String encoding, String e
*
* @throws java.io.IOException if any.
*/
@Test
public void testNoXmlHeader()
throws IOException
{
Expand All @@ -140,6 +144,7 @@ public void testNoXmlHeader()
*
* @throws java.io.IOException if any.
*/
@Test
public void testDefaultEncoding()
throws IOException
{
Expand All @@ -152,6 +157,7 @@ public void testDefaultEncoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testUTF8Encoding()
throws IOException
{
Expand All @@ -164,6 +170,7 @@ public void testUTF8Encoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testUTF16Encoding()
throws IOException
{
Expand All @@ -177,6 +184,7 @@ public void testUTF16Encoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testUTF16BEEncoding()
throws IOException
{
Expand All @@ -188,6 +196,7 @@ public void testUTF16BEEncoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testUTF16LEEncoding()
throws IOException
{
Expand All @@ -199,6 +208,7 @@ public void testUTF16LEEncoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testLatin1Encoding()
throws IOException
{
Expand All @@ -210,6 +220,7 @@ public void testLatin1Encoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testLatin7Encoding()
throws IOException
{
Expand All @@ -221,6 +232,7 @@ public void testLatin7Encoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testLatin15Encoding()
throws IOException
{
Expand All @@ -232,6 +244,7 @@ public void testLatin15Encoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testEUC_JPEncoding()
throws IOException
{
Expand All @@ -243,6 +256,7 @@ public void testEUC_JPEncoding()
*
* @throws java.io.IOException if any.
*/
@Test
public void testEBCDICEncoding()
throws IOException
{
Expand All @@ -254,25 +268,23 @@ public void testEBCDICEncoding()
*
* @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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.codehaus.plexus.util.xml;

import static org.junit.Assert.assertEquals;

/*
* Copyright The Codehaus Foundation.
*
Expand All @@ -21,7 +19,9 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;

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

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

/**
* <p>XmlStreamWriterTest class.</p>
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
* limitations under the License.
*/

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -30,7 +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.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 @@ -16,17 +16,16 @@
* limitations under the License.
*/

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
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.jupiter.api.Assertions.*;

/**
* <p>XmlWriterUtilTest class.</p>
Expand All @@ -48,7 +47,7 @@ public class XmlWriterUtilTest
*
* @throws java.lang.Exception if any.
*/
@Before
@BeforeEach
public void setUp()
throws Exception
{
Expand All @@ -62,7 +61,7 @@ public void setUp()
*
* @throws java.lang.Exception if any.
*/
@After
@AfterEach
public void tearDown()
throws Exception
{
Expand Down
Loading