This is an automated email from the ASF dual-hosted git repository.
veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
The following commit(s) were added to refs/heads/master by this push:
new 0475970a7 Refactor @test(expected=...) to AssertJ assertThatThrownBy
per ADR 0004
0475970a7 is described below
commit 0475970a752bd22e16b5fc60ae0ba05568e884f8
Author: Andreas Veithen-Knowles <[email protected]>
AuthorDate: Sun Mar 1 21:23:16 2026 +0000
Refactor @test(expected=...) to AssertJ assertThatThrownBy per ADR 0004
---
.../core/stream/NamespaceRepairingFilterTest.java | 10 ++---
.../core/stream/serializer/SerializerTest.java | 51 ++++++++++------------
.../stream/stax/pull/output/StAXPivotTest.java | 36 ++++++++++-----
testing/xml-truth/pom.xml | 5 +++
.../org/apache/axiom/truth/xml/XMLSubjectTest.java | 14 +++---
5 files changed, 67 insertions(+), 49 deletions(-)
diff --git
a/components/core-streams/src/test/java/org/apache/axiom/core/stream/NamespaceRepairingFilterTest.java
b/components/core-streams/src/test/java/org/apache/axiom/core/stream/NamespaceRepairingFilterTest.java
index 9e20fe6a3..bca64fd99 100644
---
a/components/core-streams/src/test/java/org/apache/axiom/core/stream/NamespaceRepairingFilterTest.java
+++
b/components/core-streams/src/test/java/org/apache/axiom/core/stream/NamespaceRepairingFilterTest.java
@@ -18,19 +18,19 @@
*/
package org.apache.axiom.core.stream;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
import org.junit.Test;
public class NamespaceRepairingFilterTest {
- @Test(expected = ConflictingNamespaceDeclarationException.class)
+ @Test
public void testNamespaceDeclarationConflictingWithElementName() throws
StreamException {
XmlHandler handler =
new NamespaceRepairingFilter(null, false)
.createFilterHandler(NullXmlHandler.INSTANCE);
handler.startFragment();
handler.startElement("urn:ns1", "test", "p");
- handler.processNamespaceDeclaration("p", "urn:ns2");
- handler.attributesCompleted();
- handler.endElement();
- handler.completed();
+ assertThatThrownBy(() -> handler.processNamespaceDeclaration("p",
"urn:ns2"))
+ .isInstanceOf(ConflictingNamespaceDeclarationException.class);
}
}
diff --git
a/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerTest.java
b/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerTest.java
index ef740c03a..504288fff 100644
---
a/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerTest.java
+++
b/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerTest.java
@@ -19,6 +19,7 @@
package org.apache.axiom.core.stream.serializer;
import static com.google.common.truth.Truth.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
@@ -112,75 +113,67 @@ public class SerializerTest {
.isEqualTo("<x y=\"𣎴 - 𠘨\"/>");
}
- @Test(expected = StreamException.class)
+ @Test
public void testUnmappableCharacterInComment() throws Exception {
Serializer handler = new Serializer(NullOutputStream.INSTANCE,
"iso-8859-1");
handler.startFragment();
handler.startComment();
- handler.processCharacterData("\u20AC", false);
- handler.endComment();
- handler.completed();
+ assertThatThrownBy(() -> handler.processCharacterData("\u20AC", false))
+ .isInstanceOf(StreamException.class);
}
- @Test(expected = StreamException.class)
+ @Test
public void testUnmappableCharacterInCDATASection() throws Exception {
Serializer handler = new Serializer(NullOutputStream.INSTANCE,
"ascii");
handler.startFragment();
handler.startCDATASection();
- handler.processCharacterData("c'est la fête!", false);
- handler.endCDATASection();
- handler.completed();
+ assertThatThrownBy(() -> handler.processCharacterData("c'est la
fête!", false))
+ .isInstanceOf(StreamException.class);
}
- @Test(expected = StreamException.class)
+ @Test
public void testUnmappableCharacterInProcessingInstruction() throws
Exception {
Serializer handler = new Serializer(NullOutputStream.INSTANCE,
"ascii");
handler.startFragment();
handler.startProcessingInstruction("test");
- handler.processCharacterData("c'est la fête!", false);
- handler.endProcessingInstruction();
- handler.completed();
+ assertThatThrownBy(() -> handler.processCharacterData("c'est la
fête!", false))
+ .isInstanceOf(StreamException.class);
}
- @Test(expected = StreamException.class)
+ @Test
public void testUnmappableCharacterInName() throws Exception {
Serializer handler = new Serializer(NullOutputStream.INSTANCE,
"iso-8859-15");
handler.startFragment();
- handler.startElement("", "\u0370", "");
- handler.attributesCompleted();
- handler.endElement();
- handler.completed();
+ assertThatThrownBy(() -> handler.startElement("", "\u0370", ""))
+ .isInstanceOf(StreamException.class);
}
- @Test(expected = IllegalCharacterSequenceException.class)
+ @Test
public void testIllegalCharacterSequenceInComment() throws Exception {
Serializer handler = new Serializer(NullWriter.INSTANCE);
handler.startFragment();
handler.startComment();
- handler.processCharacterData("abc--def", false);
- handler.endComment();
- handler.completed();
+ assertThatThrownBy(() -> handler.processCharacterData("abc--def",
false))
+ .isInstanceOf(IllegalCharacterSequenceException.class);
}
- @Test(expected = IllegalCharacterSequenceException.class)
+ @Test
public void testIllegalCharacterSequenceInProcessingInstruction() throws
Exception {
Serializer handler = new Serializer(NullWriter.INSTANCE);
handler.startFragment();
handler.startProcessingInstruction("test");
- handler.processCharacterData("aaa???>bbb", false);
- handler.endProcessingInstruction();
- handler.completed();
+ assertThatThrownBy(() -> handler.processCharacterData("aaa???>bbb",
false))
+ .isInstanceOf(IllegalCharacterSequenceException.class);
}
- @Test(expected = IllegalCharacterSequenceException.class)
+ @Test
public void testIllegalCharacterSequenceInCDATASection() throws Exception {
Serializer handler = new Serializer(NullWriter.INSTANCE);
handler.startFragment();
handler.startCDATASection();
handler.processCharacterData("xxx]]]", false);
- handler.processCharacterData(">yyy", false);
- handler.endCDATASection();
- handler.completed();
+ assertThatThrownBy(() -> handler.processCharacterData(">yyy", false))
+ .isInstanceOf(IllegalCharacterSequenceException.class);
}
@Test
diff --git
a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTest.java
b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTest.java
index 208f30d77..707d6aee1 100644
---
a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTest.java
+++
b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTest.java
@@ -57,19 +57,21 @@ public class StAXPivotTest {
pivot.require(XMLStreamConstants.END_DOCUMENT, null, null);
}
- @Test(expected = XMLStreamException.class)
+ @Test
public void testEventTypeMismatch() throws Exception {
StAXPivot pivot = createStAXPivot(Action.DEFAULT_START_DOCUMENT);
- pivot.require(XMLStreamConstants.CHARACTERS, null, null);
+ assertThatThrownBy(() -> pivot.require(XMLStreamConstants.CHARACTERS,
null, null))
+ .isInstanceOf(XMLStreamException.class);
}
- @Test(expected = XMLStreamException.class)
+ @Test
public void testLocalNameOnStartDocument() throws Exception {
StAXPivot pivot = createStAXPivot(Action.DEFAULT_START_DOCUMENT);
- pivot.require(XMLStreamConstants.START_DOCUMENT, null, "test");
+ assertThatThrownBy(() ->
pivot.require(XMLStreamConstants.START_DOCUMENT, null, "test"))
+ .isInstanceOf(XMLStreamException.class);
}
- @Test(expected = XMLStreamException.class)
+ @Test
public void testLocalNameMismatchOnStartElement() throws Exception {
StAXPivot pivot =
createStAXPivot(
@@ -77,16 +79,26 @@ public class StAXPivotTest {
h -> h.startElement("urn:test", "test", "p"),
XmlHandler::attributesCompleted);
pivot.next();
- pivot.require(XMLStreamConstants.START_ELEMENT, "urn:test",
"wrong_name");
+ assertThatThrownBy(
+ () ->
+ pivot.require(
+ XMLStreamConstants.START_ELEMENT,
"urn:test", "wrong_name"))
+ .isInstanceOf(XMLStreamException.class);
}
- @Test(expected = XMLStreamException.class)
+ @Test
public void testNamespaceURIOnStartDocument() throws Exception {
StAXPivot pivot = createStAXPivot(Action.DEFAULT_START_DOCUMENT);
- pivot.require(XMLStreamConstants.START_DOCUMENT, "http://example.org",
null);
+ assertThatThrownBy(
+ () ->
+ pivot.require(
+ XMLStreamConstants.START_DOCUMENT,
+ "http://example.org",
+ null))
+ .isInstanceOf(XMLStreamException.class);
}
- @Test(expected = XMLStreamException.class)
+ @Test
public void testNamespaceURIMismatchOnStartElement() throws Exception {
StAXPivot pivot =
createStAXPivot(
@@ -94,7 +106,11 @@ public class StAXPivotTest {
h -> h.startElement("urn:test", "test", "p"),
XmlHandler::attributesCompleted);
pivot.next();
- pivot.require(XMLStreamConstants.START_ELEMENT, "urn:wrong_uri",
"test");
+ assertThatThrownBy(
+ () ->
+ pivot.require(
+ XMLStreamConstants.START_ELEMENT,
"urn:wrong_uri", "test"))
+ .isInstanceOf(XMLStreamException.class);
}
@Test
diff --git a/testing/xml-truth/pom.xml b/testing/xml-truth/pom.xml
index ae0050e90..d2a5d2500 100644
--- a/testing/xml-truth/pom.xml
+++ b/testing/xml-truth/pom.xml
@@ -57,6 +57,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLSubjectTest.java
b/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLSubjectTest.java
index 2cbfdfedd..710655c1f 100644
---
a/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLSubjectTest.java
+++
b/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLSubjectTest.java
@@ -20,6 +20,7 @@ package org.apache.axiom.truth.xml;
import static com.google.common.truth.Truth.assertAbout;
import static org.apache.axiom.truth.xml.XMLTruth.xml;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.Test;
@@ -32,12 +33,15 @@ public class XMLSubjectTest {
.hasSameContentAs("<a xmlns:p='#1'><b/></a>");
}
- @Test(expected = AssertionError.class)
+ @Test
public void testIgnoringRedundantNamespaceDeclarations2() {
- assertAbout(xml())
- .that("<a xmlns:p='#1'><b xmlns:p='#2'/></a>")
- .ignoringRedundantNamespaceDeclarations()
- .hasSameContentAs("<a xmlns:p='#1'><b/></a>");
+ assertThatThrownBy(
+ () ->
+ assertAbout(xml())
+ .that("<a xmlns:p='#1'><b
xmlns:p='#2'/></a>")
+
.ignoringRedundantNamespaceDeclarations()
+ .hasSameContentAs("<a
xmlns:p='#1'><b/></a>"))
+ .isInstanceOf(AssertionError.class);
}
@Test