Skip to content

Migrate from JUnit 4 to JUnit 5 #30

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
Jun 10, 2025
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 @@ -73,9 +73,9 @@
<scope>compile</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.11.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
42 changes: 17 additions & 25 deletions src/test/java/com/dataliquid/commons/xml/DomUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
import javax.xml.xpath.XPathFactory;

import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Comment;
Expand Down Expand Up @@ -86,14 +88,14 @@ public void testParse()
assertThat(document.getElementsByTagName("element").item(0).getTextContent(), equalTo("Value"));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testParseInvalid()
{
// Given
String xml = "no xml content";

// When
DomUtils.parse(xml);
// When & Then
assertThrows(IllegalArgumentException.class, () -> DomUtils.parse(xml));
}

@Test
Expand Down Expand Up @@ -128,17 +130,14 @@ public void testParseWithoutNamespaceAware()
assertThat(document.getElementsByTagName("element").item(0).getTextContent(), equalTo("Value"));
}

@Test(expected = FileNotFoundException.class)
public void testParseFileNotFound() throws FileNotFoundException
@Test
public void testParseFileNotFound()
{
// Given
File nonExistentFile = new File("path/to/nonexistent.xml");

// When
DomUtils.parse(nonExistentFile);

// Then
// Expecting FileNotFoundException to be thrown
// When & Then
assertThrows(FileNotFoundException.class, () -> DomUtils.parse(nonExistentFile));
}

@Test
Expand All @@ -157,17 +156,14 @@ public void testParseFile() throws FileNotFoundException
assertThat(document.getElementsByTagName("element").item(0).getTextContent(), equalTo("Value"));
}

@Test(expected = FileNotFoundException.class)
public void testParseFileWithNamespaceAwareNotFound() throws FileNotFoundException
@Test
public void testParseFileWithNamespaceAwareNotFound()
{
// Given
File nonExistentFile = new File("path/to/nonexistent.xml");

// When
DomUtils.parse(nonExistentFile, true);

// Then
// Expecting FileNotFoundException to be thrown
// When & Then
assertThrows(FileNotFoundException.class, () -> DomUtils.parse(nonExistentFile, true));
}

@Test
Expand Down Expand Up @@ -1009,7 +1005,7 @@ public void testEnforceNoNamespaceMixes() throws Exception
assertThat(rootElement2.getNamespaceURI(), is("http://example.com"));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testEnforceNoNamespaceMixesFails() throws Exception
{
// Given
Expand All @@ -1020,12 +1016,8 @@ public void testEnforceNoNamespaceMixesFails() throws Exception
Element rootElement1 = document1.getDocumentElement();
Element rootElement2 = document2.getDocumentElement();

// When
DomUtils.enforceNoNamespaceMixes(rootElement1, rootElement2);

// Then
assertThat(rootElement1.getNamespaceURI(), is("http://example.com"));
assertThat(rootElement2.getNamespaceURI(), is("http://example.org"));
// When & Then
assertThrows(IllegalArgumentException.class, () -> DomUtils.enforceNoNamespaceMixes(rootElement1, rootElement2));
}

@Test
Expand Down
Loading