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 0b6ff6385 Replace assertThrows with AssertJ's assertThatThrownBy
0b6ff6385 is described below
commit 0b6ff6385daa611144bf7537800719ce640593b5
Author: Andreas Veithen-Knowles <[email protected]>
AuthorDate: Sun Mar 1 15:32:04 2026 +0000
Replace assertThrows with AssertJ's assertThatThrownBy
Migrate all usages of JUnit's assertThrows to AssertJ's
assertThatThrownBy/isInstanceOf, as per ADR-0004. Where the returned
exception was used for further assertions, use isInstanceOfSatisfying
instead.
Add assertj-core dependency to modules that didn't have it yet:
axiom-api, axiom-legacy-attachments, axiom-weaver, components/blob,
components/core-streams, and testing/spring-ws-testsuite.
---
axiom-api/pom.xml | 5 ++
.../apache/axiom/mime/ContentTypeBuilderTest.java | 5 +-
.../org/apache/axiom/mime/ContentTypeTest.java | 29 ++++++-----
.../java/org/apache/axiom/mime/MediaTypeTest.java | 6 +--
.../org/apache/axiom/om/util/StAXUtilsTest.java | 25 +++++-----
.../apache/axiom/util/base64/Base64UtilsTest.java | 17 ++++---
.../dialect/IllegalStateExceptionTestCase.java | 4 +-
.../TestCreateXMLEventWriterWithNullEncoding.java | 5 +-
.../TestCreateXMLStreamWriterWithNullEncoding.java | 5 +-
.../dialect/TestGetCharacterEncodingScheme.java | 5 +-
.../axiom/util/stax/dialect/TestGetEncoding.java | 4 +-
.../axiom/util/stax/dialect/TestGetVersion.java | 4 +-
.../axiom/util/stax/dialect/TestIsStandalone.java | 4 +-
.../axiom/util/stax/dialect/TestStandaloneSet.java | 4 +-
.../TestWriteStartDocumentWithNullEncoding.java | 5 +-
.../util/activation/DataHandlerUtilsTest.java | 26 +++++-----
axiom-legacy-attachments/pom.xml | 5 ++
.../apache/axiom/attachments/AttachmentsTest.java | 57 ++++++++++++----------
axiom-weaver/pom.xml | 5 ++
.../weaver/noabstract/NoAbstractMethodTest.java | 7 ++-
components/blob/pom.xml | 5 ++
.../blob/suite/TestGetInputStreamIllegalState.java | 4 +-
.../suite/TestGetOutputStreamIllegalState.java | 4 +-
.../axiom/blob/suite/TestGetSizeIllegalState.java | 4 +-
.../axiom/blob/suite/TestReadFromIllegalState.java | 5 +-
.../axiom/blob/suite/TestReadFromWithError.java | 14 ++++--
.../axiom/blob/suite/TestWriteToIllegalState.java | 5 +-
.../axiom/blob/suite/TestWriteToWithError.java | 15 +++---
components/core-streams/pom.xml | 5 ++
.../stream/stax/pull/output/StAXPivotTest.java | 4 +-
.../org/apache/axiom/util/xml/QNameMapTest.java | 6 +--
docs/adr/0004-prefer-assertj-over-google-truth.md | 3 +-
.../attr/TestSetPrefixNotNullWithoutNamespace.java | 14 ++----
.../axiom/ts/dom/document/TestAllowedChildren.java | 38 +++++----------
.../TestAppendChildForeignImplementation.java | 14 ++----
.../dom/document/TestAppendChildWrongDocument.java | 14 ++----
.../dom/document/TestCreateAttributeNSInvalid.java | 20 ++++----
.../TestCreateElementNSWithInvalidName.java | 14 ++----
.../ts/dom/element/TestAppendChildCyclic.java | 14 ++----
.../axiom/ts/dom/element/TestAppendChildSelf.java | 14 ++----
.../dom/element/TestAppendChildWrongDocument.java | 14 ++----
...stRemoveAttributeNodeForeignImplementation.java | 14 ++----
.../element/TestRemoveAttributeNodeNotOwner.java | 14 ++----
.../ts/dom/element/TestReplaceChildCyclic.java | 14 ++----
.../ts/dom/element/TestReplaceChildNotFound.java | 14 ++----
.../dom/element/TestReplaceChildNullNewChild.java | 8 +--
.../dom/element/TestReplaceChildWrongDocument.java | 14 ++----
.../ts/dom/element/TestSetAttributeNSInvalid.java | 22 ++++-----
...estSetAttributeNodeNSForeignImplementation.java | 14 ++----
.../dom/element/TestSetAttributeNodeNSInUse.java | 14 ++----
.../TestSetAttributeNodeNSWrongDocument.java | 14 ++----
.../element/TestSetAttributeNodeWrongDocument.java | 14 ++----
.../TestSetPrefixNotNullWithoutNamespace.java | 14 ++----
.../TestSetNamedItemNSWrongDocument.java | 14 ++----
.../attributes/TestSetNamedItemWrongDocument.java | 14 ++----
.../apache/axiom/ts/dom/text/TestSetPrefix.java | 14 ++----
testing/spring-ws-testsuite/pom.xml | 4 ++
.../scenario/broker/BrokerScenarioTest.java | 14 ++++--
.../scenario/validation/ValidationTest.java | 25 ++++++----
...rviceMessageFromInputStreamVersionMismatch.java | 15 +++---
60 files changed, 350 insertions(+), 377 deletions(-)
diff --git a/axiom-api/pom.xml b/axiom-api/pom.xml
index 6267c0920..20f4f4ea3 100644
--- a/axiom-api/pom.xml
+++ b/axiom-api/pom.xml
@@ -82,6 +82,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>com.fasterxml.woodstox</groupId>
<artifactId>woodstox-core</artifactId>
diff --git
a/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeBuilderTest.java
b/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeBuilderTest.java
index 048fcc57d..bd7572d4e 100644
--- a/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeBuilderTest.java
+++ b/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeBuilderTest.java
@@ -19,7 +19,7 @@
package org.apache.axiom.mime;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import junit.framework.TestCase;
@@ -76,7 +76,8 @@ public class ContentTypeBuilderTest extends TestCase {
public void testNullParameterName() {
ContentType.Builder builder = ContentType.builder();
- assertThrows(NullPointerException.class, () ->
builder.setParameter(null, "value"));
+ assertThatThrownBy(() -> builder.setParameter(null, "value"))
+ .isInstanceOf(NullPointerException.class);
}
public void testNullParameterValue() {
diff --git a/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java
b/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java
index 00592a8f7..b1cef7e25 100644
--- a/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java
+++ b/axiom-api/src/test/java/org/apache/axiom/mime/ContentTypeTest.java
@@ -19,7 +19,7 @@
package org.apache.axiom.mime;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.text.ParseException;
@@ -27,13 +27,13 @@ import junit.framework.TestCase;
public class ContentTypeTest extends TestCase {
public void testNullMediaType() {
- assertThrows(NullPointerException.class, () -> new
ContentType((MediaType) null));
+ assertThatThrownBy(() -> new ContentType((MediaType) null))
+ .isInstanceOf(NullPointerException.class);
}
public void testNullParameter() {
- assertThrows(
- NullPointerException.class,
- () -> new ContentType(MediaType.TEXT_PLAIN, "charset", null));
+ assertThatThrownBy(() -> new ContentType(MediaType.TEXT_PLAIN,
"charset", null))
+ .isInstanceOf(NullPointerException.class);
}
public void testImmutable() {
@@ -87,31 +87,36 @@ public class ContentTypeTest extends TestCase {
}
public void testParseInvalid1() {
- assertThrows(ParseException.class, () -> new ContentType("text/xml;
?"));
+ assertThatThrownBy(() -> new ContentType("text/xml;
?")).isInstanceOf(ParseException.class);
}
public void testParseInvalid2() {
- assertThrows(ParseException.class, () -> new ContentType("text/"));
+ assertThatThrownBy(() -> new
ContentType("text/")).isInstanceOf(ParseException.class);
}
public void testParseInvalid3() {
- assertThrows(ParseException.class, () -> new ContentType("text/xml;
charset="));
+ assertThatThrownBy(() -> new ContentType("text/xml; charset="))
+ .isInstanceOf(ParseException.class);
}
public void testParseInvalid4() {
- assertThrows(ParseException.class, () -> new ContentType("text/xml;
charset=\"asc"));
+ assertThatThrownBy(() -> new ContentType("text/xml; charset=\"asc"))
+ .isInstanceOf(ParseException.class);
}
public void testParseInvalid5() {
- assertThrows(ParseException.class, () -> new ContentType("text/xml;
param=\"test\\"));
+ assertThatThrownBy(() -> new ContentType("text/xml; param=\"test\\"))
+ .isInstanceOf(ParseException.class);
}
public void testParseInvalid6() {
- assertThrows(ParseException.class, () -> new ContentType("text/xml;
param;"));
+ assertThatThrownBy(() -> new ContentType("text/xml; param;"))
+ .isInstanceOf(ParseException.class);
}
public void testParseInvalid7() {
- assertThrows(ParseException.class, () -> new ContentType("text/xml;
param"));
+ assertThatThrownBy(() -> new ContentType("text/xml; param"))
+ .isInstanceOf(ParseException.class);
}
public void testToString() {
diff --git a/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
b/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
index abbbe11db..c9e2a4d9f 100644
--- a/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
+++ b/axiom-api/src/test/java/org/apache/axiom/mime/MediaTypeTest.java
@@ -19,7 +19,7 @@
package org.apache.axiom.mime;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.text.ParseException;
@@ -79,11 +79,11 @@ public class MediaTypeTest extends TestCase {
}
public void testParseInvalid1() {
- assertThrows(ParseException.class, () -> new MediaType("text/"));
+ assertThatThrownBy(() -> new
MediaType("text/")).isInstanceOf(ParseException.class);
}
public void testParseInvalid2() {
- assertThrows(ParseException.class, () -> new MediaType("text/xml;"));
+ assertThatThrownBy(() -> new
MediaType("text/xml;")).isInstanceOf(ParseException.class);
}
public void testIsXML() throws Exception {
diff --git
a/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
b/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
index 25adc8391..94ab3364e 100644
--- a/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
+++ b/axiom-api/src/test/java/org/apache/axiom/om/util/StAXUtilsTest.java
@@ -19,25 +19,26 @@
package org.apache.axiom.om.util;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import junit.framework.TestCase;
public class StAXUtilsTest extends TestCase {
public void testInputFactoryIsImmutable() throws Exception {
- assertThrows(
- IllegalStateException.class,
- () ->
- StAXUtils.getXMLInputFactory()
- .setProperty("javax.xml.stream.isValidating",
Boolean.TRUE));
+ assertThatThrownBy(
+ () ->
+ StAXUtils.getXMLInputFactory()
+
.setProperty("javax.xml.stream.isValidating", Boolean.TRUE))
+ .isInstanceOf(IllegalStateException.class);
}
public void testOutputFactoryIsImmutable() throws Exception {
- assertThrows(
- IllegalStateException.class,
- () ->
- StAXUtils.getXMLOutputFactory()
- .setProperty(
-
"javax.xml.stream.isRepairingNamespaces", Boolean.TRUE));
+ assertThatThrownBy(
+ () ->
+ StAXUtils.getXMLOutputFactory()
+ .setProperty(
+
"javax.xml.stream.isRepairingNamespaces",
+ Boolean.TRUE))
+ .isInstanceOf(IllegalStateException.class);
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/base64/Base64UtilsTest.java
b/axiom-api/src/test/java/org/apache/axiom/util/base64/Base64UtilsTest.java
index e9e1d2f7c..a0d85c5ee 100644
--- a/axiom-api/src/test/java/org/apache/axiom/util/base64/Base64UtilsTest.java
+++ b/axiom-api/src/test/java/org/apache/axiom/util/base64/Base64UtilsTest.java
@@ -20,7 +20,7 @@
package org.apache.axiom.util.base64;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.nio.charset.StandardCharsets;
import java.util.Random;
@@ -40,15 +40,18 @@ public class Base64UtilsTest extends TestCase {
}
public void testMissingPadding() {
- assertThrows(IllegalArgumentException.class, () ->
Base64Utils.decode("cw"));
+ assertThatThrownBy(() -> Base64Utils.decode("cw"))
+ .isInstanceOf(IllegalArgumentException.class);
}
public void testTooMuchPadding() {
- assertThrows(IllegalArgumentException.class, () ->
Base64Utils.decode("cw==="));
+ assertThatThrownBy(() -> Base64Utils.decode("cw==="))
+ .isInstanceOf(IllegalArgumentException.class);
}
public void testNonZeroRemainder() {
- assertThrows(IllegalArgumentException.class, () ->
Base64Utils.decode("//=="));
+ assertThatThrownBy(() -> Base64Utils.decode("//=="))
+ .isInstanceOf(IllegalArgumentException.class);
}
public void testSpace() throws Exception {
@@ -60,10 +63,12 @@ public class Base64UtilsTest extends TestCase {
}
public void testInvalidCharacter() {
- assertThrows(IllegalArgumentException.class, () ->
Base64Utils.decode("//-/"));
+ assertThatThrownBy(() -> Base64Utils.decode("//-/"))
+ .isInstanceOf(IllegalArgumentException.class);
}
public void testInvalidPadding() {
- assertThrows(IllegalArgumentException.class, () ->
Base64Utils.decode("//=/"));
+ assertThatThrownBy(() -> Base64Utils.decode("//=/"))
+ .isInstanceOf(IllegalArgumentException.class);
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java
index 283563036..ade4d0aaf 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/IllegalStateExceptionTestCase.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@@ -35,7 +35,7 @@ public abstract class IllegalStateExceptionTestCase extends
EventSpecificTestCas
@Override
protected final void runTest(XMLStreamReader reader) throws Throwable {
if (expectException) {
- assertThrows(IllegalStateException.class, () -> invoke(reader));
+ assertThatThrownBy(() ->
invoke(reader)).isInstanceOf(IllegalStateException.class);
} else {
invoke(reader);
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestCreateXMLEventWriterWithNullEncoding.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestCreateXMLEventWriterWithNullEncoding.java
index 5f3c3406e..c4e19f558 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestCreateXMLEventWriterWithNullEncoding.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestCreateXMLEventWriterWithNullEncoding.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.stream.XMLOutputFactory;
@@ -31,6 +31,7 @@ public class TestCreateXMLEventWriterWithNullEncoding extends
DialectTestCase {
protected void runTest() throws Throwable {
XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory();
// This should cause an exception
- assertThrows(Throwable.class, () ->
factory.createXMLEventWriter(System.out, null));
+ assertThatThrownBy(() -> factory.createXMLEventWriter(System.out,
null))
+ .isInstanceOf(Throwable.class);
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestCreateXMLStreamWriterWithNullEncoding.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestCreateXMLStreamWriterWithNullEncoding.java
index c656fe6ed..cb03db52e 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestCreateXMLStreamWriterWithNullEncoding.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestCreateXMLStreamWriterWithNullEncoding.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.stream.XMLOutputFactory;
@@ -31,6 +31,7 @@ public class TestCreateXMLStreamWriterWithNullEncoding
extends DialectTestCase {
protected void runTest() throws Throwable {
XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory();
// This should cause an exception
- assertThrows(Throwable.class, () ->
factory.createXMLStreamWriter(System.out, null));
+ assertThatThrownBy(() -> factory.createXMLStreamWriter(System.out,
null))
+ .isInstanceOf(Throwable.class);
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetCharacterEncodingScheme.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetCharacterEncodingScheme.java
index c4ceb6b80..84359d0b1 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetCharacterEncodingScheme.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetCharacterEncodingScheme.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.ByteArrayInputStream;
@@ -40,7 +40,8 @@ public class TestGetCharacterEncodingScheme extends
DialectTestCase {
.getBytes("iso-8859-15")));
assertEquals("iso-8859-15", reader.getCharacterEncodingScheme());
reader.next();
- assertThrows(IllegalStateException.class,
reader::getCharacterEncodingScheme);
+ assertThatThrownBy(reader::getCharacterEncodingScheme)
+ .isInstanceOf(IllegalStateException.class);
reader.close();
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetEncoding.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetEncoding.java
index ba38364ed..7c4ba6e70 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetEncoding.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetEncoding.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.ByteArrayInputStream;
@@ -40,7 +40,7 @@ public class TestGetEncoding extends DialectTestCase {
.getBytes("iso-8859-15")));
assertEquals("iso-8859-15", reader.getEncoding());
reader.next();
- assertThrows(IllegalStateException.class, reader::getEncoding);
+
assertThatThrownBy(reader::getEncoding).isInstanceOf(IllegalStateException.class);
reader.close();
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetVersion.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetVersion.java
index 33e2b2a76..b8d0cdd53 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetVersion.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestGetVersion.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.StringReader;
@@ -37,7 +37,7 @@ public class TestGetVersion extends DialectTestCase {
factory.createXMLStreamReader(new StringReader("<?xml
version='1.0'?><root/>"));
assertEquals("1.0", reader.getVersion());
reader.next();
- assertThrows(IllegalStateException.class, reader::getVersion);
+
assertThatThrownBy(reader::getVersion).isInstanceOf(IllegalStateException.class);
reader.close();
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestIsStandalone.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestIsStandalone.java
index d71aad708..63ed0432e 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestIsStandalone.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestIsStandalone.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.StringReader;
@@ -38,7 +38,7 @@ public class TestIsStandalone extends DialectTestCase {
new StringReader("<?xml version='1.0'
standalone='no'?><root/>"));
assertEquals(false, reader.isStandalone());
reader.next();
- assertThrows(IllegalStateException.class, reader::isStandalone);
+
assertThatThrownBy(reader::isStandalone).isInstanceOf(IllegalStateException.class);
reader.close();
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneSet.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneSet.java
index d7a9ae3dc..c589c5e66 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneSet.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestStandaloneSet.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.StringReader;
@@ -37,7 +37,7 @@ public class TestStandaloneSet extends DialectTestCase {
factory.createXMLStreamReader(new StringReader("<?xml
version='1.0'?><root/>"));
assertEquals(false, reader.standaloneSet());
reader.next();
- assertThrows(IllegalStateException.class, reader::standaloneSet);
+
assertThatThrownBy(reader::standaloneSet).isInstanceOf(IllegalStateException.class);
reader.close();
}
}
diff --git
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestWriteStartDocumentWithNullEncoding.java
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestWriteStartDocumentWithNullEncoding.java
index 5ec84aa64..8bafbcfdd 100644
---
a/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestWriteStartDocumentWithNullEncoding.java
+++
b/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/TestWriteStartDocumentWithNullEncoding.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.util.stax.dialect;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.stream.XMLStreamWriter;
@@ -31,6 +31,7 @@ public class TestWriteStartDocumentWithNullEncoding extends
DialectTestCase {
protected void runTest() throws Throwable {
XMLStreamWriter writer =
staxImpl.newNormalizedXMLOutputFactory().createXMLStreamWriter(System.out,
"UTF-8");
- assertThrows(Throwable.class, () -> writer.writeStartDocument(null,
"1.0"));
+ assertThatThrownBy(() -> writer.writeStartDocument(null, "1.0"))
+ .isInstanceOf(Throwable.class);
}
}
diff --git
a/axiom-jakarta-activation/src/test/java/org/apache/axiom/util/activation/DataHandlerUtilsTest.java
b/axiom-jakarta-activation/src/test/java/org/apache/axiom/util/activation/DataHandlerUtilsTest.java
index 5e7475bda..e2540ce9c 100644
---
a/axiom-jakarta-activation/src/test/java/org/apache/axiom/util/activation/DataHandlerUtilsTest.java
+++
b/axiom-jakarta-activation/src/test/java/org/apache/axiom/util/activation/DataHandlerUtilsTest.java
@@ -19,7 +19,7 @@
package org.apache.axiom.util.activation;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.IOException;
import java.io.InputStream;
@@ -38,9 +38,7 @@ public class DataHandlerUtilsTest {
@Test
public void testToBlobWriteError() {
ExceptionOutputStream out = new ExceptionOutputStream(0);
- StreamCopyException ex =
- assertThrows(
- StreamCopyException.class,
+ assertThatThrownBy(
() -> {
DataHandlerUtils.toBlob(
new DataHandler(
@@ -48,9 +46,13 @@ public class DataHandlerUtilsTest {
new byte[10],
"application/octet-stream")))
.writeTo(out);
+ })
+ .isInstanceOfSatisfying(
+ StreamCopyException.class,
+ ex -> {
+
assertThat(ex.getOperation()).isEqualTo(StreamCopyException.WRITE);
+
assertThat(ex.getCause()).isSameAs(out.getException());
});
- assertThat(ex.getOperation()).isEqualTo(StreamCopyException.WRITE);
- assertThat(ex.getCause()).isSameAs(out.getException());
}
@Test
@@ -77,14 +79,16 @@ public class DataHandlerUtilsTest {
throw new UnsupportedOperationException();
}
};
- StreamCopyException ex =
- assertThrows(
- StreamCopyException.class,
+ assertThatThrownBy(
() -> {
DataHandlerUtils.toBlob(new DataHandler(ds))
.writeTo(NullOutputStream.INSTANCE);
+ })
+ .isInstanceOfSatisfying(
+ StreamCopyException.class,
+ ex -> {
+
assertThat(ex.getOperation()).isEqualTo(StreamCopyException.READ);
+
assertThat(ex.getCause().getMessage()).isEqualTo("Read error");
});
- assertThat(ex.getOperation()).isEqualTo(StreamCopyException.READ);
- assertThat(ex.getCause().getMessage()).isEqualTo("Read error");
}
}
diff --git a/axiom-legacy-attachments/pom.xml b/axiom-legacy-attachments/pom.xml
index b8eb7c280..1e7492b4c 100644
--- a/axiom-legacy-attachments/pom.xml
+++ b/axiom-legacy-attachments/pom.xml
@@ -62,6 +62,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
diff --git
a/axiom-legacy-attachments/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
b/axiom-legacy-attachments/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
index 78be3c647..9119cb44f 100644
---
a/axiom-legacy-attachments/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
+++
b/axiom-legacy-attachments/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
@@ -19,7 +19,7 @@
package org.apache.axiom.attachments;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -243,13 +243,14 @@ public class AttachmentsTest extends AbstractTestCase {
"multipart/related; boundary=\""
+ MTOMSample.SAMPLE1.getBoundary()
+ "\"; type=\"text/xml\";
start=\"<[email protected]>\"";
- assertThrows(
- MIMEException.class,
- () -> {
- Attachments attachments =
- new
Attachments(MTOMSample.SAMPLE1.getInputStream(), contentType);
- attachments.getRootPartContentType();
- });
+ assertThatThrownBy(
+ () -> {
+ Attachments attachments =
+ new Attachments(
+
MTOMSample.SAMPLE1.getInputStream(), contentType);
+ attachments.getRootPartContentType();
+ })
+ .isInstanceOf(MIMEException.class);
}
public void testGetIncomingAttachmentStreams() throws Exception {
@@ -329,7 +330,8 @@ public class AttachmentsTest extends AbstractTestCase {
attachments.getDataHandler("2.urn:uuid:[email protected]");
// This should throw an error
- assertThrows(IllegalStateException.class,
attachments::getIncomingAttachmentStreams);
+ assertThatThrownBy(attachments::getIncomingAttachmentStreams)
+ .isInstanceOf(IllegalStateException.class);
inStream.close();
}
@@ -350,22 +352,22 @@ public class AttachmentsTest extends AbstractTestCase {
attachments.getRootPartInputStream();
// These should throw an error
- assertThrows(
- IllegalStateException.class,
- () ->
- attachments.getDataHandler(
-
"2.urn:uuid:[email protected]"));
+ assertThatThrownBy(
+ () ->
+ attachments.getDataHandler(
+
"2.urn:uuid:[email protected]"))
+ .isInstanceOf(IllegalStateException.class);
// Additionally, we also need to ensure mutual exclusion if someone
// tries to access part data directly
- assertThrows(IllegalStateException.class,
attachments::getAllContentIDs);
+
assertThatThrownBy(attachments::getAllContentIDs).isInstanceOf(IllegalStateException.class);
- assertThrows(
- IllegalStateException.class,
- () ->
- attachments.getDataHandler(
-
"2.urn:uuid:[email protected]"));
+ assertThatThrownBy(
+ () ->
+ attachments.getDataHandler(
+
"2.urn:uuid:[email protected]"))
+ .isInstanceOf(IllegalStateException.class);
}
public void testRemoveDataHandlerAfterParsing() {
@@ -721,7 +723,8 @@ public class AttachmentsTest extends AbstractTestCase {
}
public void testGetAttachmentSpecTypeWithoutStream() {
- assertThrows(OMException.class, () -> new
Attachments().getAttachmentSpecType());
+ assertThatThrownBy(() -> new Attachments().getAttachmentSpecType())
+ .isInstanceOf(OMException.class);
}
private void testGetSizeOnDataSource(boolean useFiles) throws Exception {
@@ -766,11 +769,11 @@ public class AttachmentsTest extends AbstractTestCase {
new ExceptionInputStream(in, 1050),
MTOMSample.SAMPLE1.getContentType());
// TODO: decide what exception should be thrown exactly here
- assertThrows(
- MIMEException.class,
- () ->
- attachments.getDataHandler(
-
"1.urn:uuid:[email protected]"));
+ assertThatThrownBy(
+ () ->
+ attachments.getDataHandler(
+
"1.urn:uuid:[email protected]"))
+ .isInstanceOf(MIMEException.class);
} finally {
in.close();
}
@@ -787,7 +790,7 @@ public class AttachmentsTest extends AbstractTestCase {
attachments.getDataHandler(
"1.urn:uuid:[email protected]");
// TODO: decide what exception should be thrown exactly here
- assertThrows(MIMEException.class, dh::getInputStream);
+
assertThatThrownBy(dh::getInputStream).isInstanceOf(MIMEException.class);
} finally {
in.close();
}
diff --git a/axiom-weaver/pom.xml b/axiom-weaver/pom.xml
index f56237d89..7003c8b54 100644
--- a/axiom-weaver/pom.xml
+++ b/axiom-weaver/pom.xml
@@ -72,6 +72,11 @@
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/axiom-weaver/src/test/java/org/apache/axiom/weaver/noabstract/NoAbstractMethodTest.java
b/axiom-weaver/src/test/java/org/apache/axiom/weaver/noabstract/NoAbstractMethodTest.java
index 9113886bb..dd0920a64 100644
---
a/axiom-weaver/src/test/java/org/apache/axiom/weaver/noabstract/NoAbstractMethodTest.java
+++
b/axiom-weaver/src/test/java/org/apache/axiom/weaver/noabstract/NoAbstractMethodTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.weaver.noabstract;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.axiom.weaver.SimpleImplementationClassNameMapper;
import org.apache.axiom.weaver.Weaver;
@@ -31,8 +31,7 @@ public class NoAbstractMethodTest {
public void testMixinWithAbstractMethod() {
ClassLoader cl = InnerClassTest.class.getClassLoader();
Weaver weaver = new Weaver(cl, new
SimpleImplementationClassNameMapper("impl"));
- assertThrows(
- MixinFactoryException.class,
- () ->
weaver.loadWeavablePackage("org.apache.axiom.weaver.noabstract"));
+ assertThatThrownBy(() ->
weaver.loadWeavablePackage("org.apache.axiom.weaver.noabstract"))
+ .isInstanceOf(MixinFactoryException.class);
}
}
diff --git a/components/blob/pom.xml b/components/blob/pom.xml
index c3962cd28..b63361b2a 100644
--- a/components/blob/pom.xml
+++ b/components/blob/pom.xml
@@ -45,6 +45,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>testutils</artifactId>
diff --git
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetInputStreamIllegalState.java
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetInputStreamIllegalState.java
index 6413cb4c4..40dc42578 100644
---
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetInputStreamIllegalState.java
+++
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetInputStreamIllegalState.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.blob.suite;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.axiom.blob.WritableBlob;
import org.apache.axiom.blob.WritableBlobFactory;
@@ -31,6 +31,6 @@ public class TestGetInputStreamIllegalState extends
WritableBlobTestCase {
@Override
protected void runTest(WritableBlob blob) throws Throwable {
- assertThrows(IllegalStateException.class, blob::getInputStream);
+
assertThatThrownBy(blob::getInputStream).isInstanceOf(IllegalStateException.class);
}
}
diff --git
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetOutputStreamIllegalState.java
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetOutputStreamIllegalState.java
index 0b3b7f501..1e1fc7da1 100644
---
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetOutputStreamIllegalState.java
+++
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetOutputStreamIllegalState.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.blob.suite;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.axiom.blob.WritableBlob;
import org.apache.axiom.blob.WritableBlobFactory;
@@ -31,6 +31,6 @@ public class TestGetOutputStreamIllegalState extends
WritableBlobTestCase {
@Override
protected void runTest(WritableBlob blob) throws Throwable {
- assertThrows(IllegalStateException.class, blob::getOutputStream);
+
assertThatThrownBy(blob::getOutputStream).isInstanceOf(IllegalStateException.class);
}
}
diff --git
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetSizeIllegalState.java
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetSizeIllegalState.java
index fc621beb8..f2e0d7759 100644
---
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetSizeIllegalState.java
+++
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestGetSizeIllegalState.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.blob.suite;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.axiom.blob.WritableBlob;
import org.apache.axiom.blob.WritableBlobFactory;
@@ -31,6 +31,6 @@ public class TestGetSizeIllegalState extends
WritableBlobTestCase {
@Override
protected void runTest(WritableBlob blob) throws Throwable {
- assertThrows(IllegalStateException.class, blob::getSize);
+
assertThatThrownBy(blob::getSize).isInstanceOf(IllegalStateException.class);
}
}
diff --git
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestReadFromIllegalState.java
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestReadFromIllegalState.java
index 3e7c80bbc..6d6cfb0af 100644
---
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestReadFromIllegalState.java
+++
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestReadFromIllegalState.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.blob.suite;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.axiom.blob.WritableBlob;
import org.apache.axiom.blob.WritableBlobFactory;
@@ -32,6 +32,7 @@ public class TestReadFromIllegalState extends
WritableBlobTestCase {
@Override
protected void runTest(WritableBlob blob) throws Throwable {
- assertThrows(IllegalStateException.class, () -> blob.readFrom(new
NullInputStream(0)));
+ assertThatThrownBy(() -> blob.readFrom(new NullInputStream(0)))
+ .isInstanceOf(IllegalStateException.class);
}
}
diff --git
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestReadFromWithError.java
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestReadFromWithError.java
index 071af55a1..2893629ca 100644
---
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestReadFromWithError.java
+++
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestReadFromWithError.java
@@ -18,8 +18,8 @@
*/
package org.apache.axiom.blob.suite;
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.axiom.blob.WritableBlob;
import org.apache.axiom.blob.WritableBlobFactory;
@@ -35,8 +35,12 @@ public class TestReadFromWithError extends
WritableBlobTestCase {
@Override
protected void runTest(WritableBlob blob) throws Throwable {
ExceptionInputStream in = new ExceptionInputStream(new
NullInputStream(1000), 500);
- StreamCopyException ex = assertThrows(StreamCopyException.class, () ->
blob.readFrom(in));
- assertThat(ex.getOperation()).isEqualTo(StreamCopyException.READ);
- assertThat(ex.getCause()).isSameInstanceAs(in.getException());
+ assertThatThrownBy(() -> blob.readFrom(in))
+ .isInstanceOfSatisfying(
+ StreamCopyException.class,
+ ex -> {
+
assertThat(ex.getOperation()).isEqualTo(StreamCopyException.READ);
+
assertThat(ex.getCause()).isSameAs(in.getException());
+ });
}
}
diff --git
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestWriteToIllegalState.java
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestWriteToIllegalState.java
index 5ac4458b5..4187c2e55 100644
---
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestWriteToIllegalState.java
+++
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestWriteToIllegalState.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.blob.suite;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.axiom.blob.WritableBlob;
import org.apache.axiom.blob.WritableBlobFactory;
@@ -32,6 +32,7 @@ public class TestWriteToIllegalState extends
WritableBlobTestCase {
@Override
protected void runTest(WritableBlob blob) throws Throwable {
- assertThrows(IllegalStateException.class, () ->
blob.writeTo(NullOutputStream.INSTANCE));
+ assertThatThrownBy(() -> blob.writeTo(NullOutputStream.INSTANCE))
+ .isInstanceOf(IllegalStateException.class);
}
}
diff --git
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestWriteToWithError.java
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestWriteToWithError.java
index b99e3baf4..62d4026d3 100644
---
a/components/blob/src/test/java/org/apache/axiom/blob/suite/TestWriteToWithError.java
+++
b/components/blob/src/test/java/org/apache/axiom/blob/suite/TestWriteToWithError.java
@@ -18,14 +18,14 @@
*/
package org.apache.axiom.blob.suite;
-import static com.google.common.truth.Truth.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.axiom.blob.WritableBlob;
import org.apache.axiom.blob.WritableBlobFactory;
import org.apache.axiom.ext.io.StreamCopyException;
import org.apache.axiom.testutils.io.ExceptionOutputStream;
import org.apache.commons.io.input.NullInputStream;
-import org.junit.Assert;
public class TestWriteToWithError extends SizeSensitiveWritableBlobTestCase {
public TestWriteToWithError(WritableBlobFactory<?> factory, int size) {
@@ -36,9 +36,12 @@ public class TestWriteToWithError extends
SizeSensitiveWritableBlobTestCase {
protected void runTest(WritableBlob blob) throws Throwable {
blob.readFrom(new NullInputStream(size));
ExceptionOutputStream out = new ExceptionOutputStream(size / 2);
- StreamCopyException ex =
- Assert.assertThrows(StreamCopyException.class, () ->
blob.writeTo(out));
- assertThat(ex.getOperation()).isEqualTo(StreamCopyException.WRITE);
- assertThat(ex.getCause()).isSameInstanceAs(out.getException());
+ assertThatThrownBy(() -> blob.writeTo(out))
+ .isInstanceOfSatisfying(
+ StreamCopyException.class,
+ ex -> {
+
assertThat(ex.getOperation()).isEqualTo(StreamCopyException.WRITE);
+
assertThat(ex.getCause()).isSameAs(out.getException());
+ });
}
}
diff --git a/components/core-streams/pom.xml b/components/core-streams/pom.xml
index 42ed71da0..9b0d36e4b 100644
--- a/components/core-streams/pom.xml
+++ b/components/core-streams/pom.xml
@@ -50,6 +50,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>testutils</artifactId>
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 4a51c5bd3..208f30d77 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
@@ -19,7 +19,7 @@
package org.apache.axiom.core.stream.stax.pull.output;
import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
@@ -164,6 +164,6 @@ public class StAXPivotTest {
XmlHandler::attributesCompleted);
assertThat(pivot.getEventType()).isEqualTo(XMLStreamReader.START_DOCUMENT);
assertThat(pivot.next()).isEqualTo(XMLStreamReader.START_ELEMENT);
- assertThrows(XMLStreamException.class, () -> pivot.getElementText());
+ assertThatThrownBy(() ->
pivot.getElementText()).isInstanceOf(XMLStreamException.class);
}
}
diff --git
a/components/xml-utils/src/test/java/org/apache/axiom/util/xml/QNameMapTest.java
b/components/xml-utils/src/test/java/org/apache/axiom/util/xml/QNameMapTest.java
index cb43fd180..5c3b16fef 100644
---
a/components/xml-utils/src/test/java/org/apache/axiom/util/xml/QNameMapTest.java
+++
b/components/xml-utils/src/test/java/org/apache/axiom/util/xml/QNameMapTest.java
@@ -19,7 +19,7 @@
package org.apache.axiom.util.xml;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.namespace.QName;
@@ -35,8 +35,8 @@ public class QNameMapTest {
@Test
public void testGetWithNullLocalPart() {
- assertThrows(
- IllegalArgumentException.class, () -> new
QNameMap<Object>().get("urn:test", null));
+ assertThatThrownBy(() -> new QNameMap<Object>().get("urn:test", null))
+ .isInstanceOf(IllegalArgumentException.class);
}
@Test
diff --git a/docs/adr/0004-prefer-assertj-over-google-truth.md
b/docs/adr/0004-prefer-assertj-over-google-truth.md
index ea1cf7c08..44f04932b 100644
--- a/docs/adr/0004-prefer-assertj-over-google-truth.md
+++ b/docs/adr/0004-prefer-assertj-over-google-truth.md
@@ -24,7 +24,8 @@ Prefer AssertJ over Google Truth
New test code must use [AssertJ](https://assertj.github.io/doc/) as the
assertion library.
Existing usages of Google Truth and plain JUnit assertions (`assertTrue`,
`assertEquals`,
-`assertSame`, etc.) should be migrated to AssertJ when the opportunity arises.
+`assertSame`, `assertThrows`, etc.) should be migrated to AssertJ when the
opportunity arises.
+For `assertThrows`, use AssertJ's `assertThatThrownBy` or
`assertThatExceptionOfType` instead.
## Rationale
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/attr/TestSetPrefixNotNullWithoutNamespace.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/attr/TestSetPrefixNotNullWithoutNamespace.java
index b5cf64d01..2da9c8cfa 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/attr/TestSetPrefixNotNullWithoutNamespace.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/attr/TestSetPrefixNotNullWithoutNamespace.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.attr;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,13 +42,9 @@ public class TestSetPrefixNotNullWithoutNamespace extends
DOMTestCase {
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
Attr attr = document.createAttributeNS(null, "test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- attr.setPrefix("p");
- })
- .code)
- .isEqualTo(DOMException.NAMESPACE_ERR);
+ assertThatThrownBy(() -> attr.setPrefix("p"))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.NAMESPACE_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAllowedChildren.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAllowedChildren.java
index 989cc376f..543a983e6 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAllowedChildren.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAllowedChildren.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.document;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -41,39 +41,27 @@ public class TestAllowedChildren extends DOMTestCase {
// Document Object Model (DOM) Level 3 Core Specification, section
1.1.1
// says that text nodes are not allowed as children of a document.
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
-
doc.appendChild(doc.createTextNode(" "));
- })
- .code)
- .isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
+ assertThatThrownBy(() -> doc.appendChild(doc.createTextNode(" ")))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR));
doc.appendChild(doc.createElement("root1"));
// Multiple document elements are not allowed
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
-
doc.appendChild(doc.createElement("root2"));
- })
- .code)
- .isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
+ assertThatThrownBy(() -> doc.appendChild(doc.createElement("root2")))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR));
// PIs and comments after the document element are allowed
doc.appendChild(doc.createProcessingInstruction("pi", "data"));
doc.appendChild(doc.createComment("some comment"));
// Again, text nodes are not allowed
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
-
doc.appendChild(doc.createTextNode(" "));
- })
- .code)
- .isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
+ assertThatThrownBy(() -> doc.appendChild(doc.createTextNode(" ")))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java
index 94039a990..ca3ab5393 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildForeignImplementation.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.document;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -38,13 +38,9 @@ public class TestAppendChildForeignImplementation extends
DOMTestCase {
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
Element element = mock(Element.class);
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- document.appendChild(element);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> document.appendChild(element))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java
index 597c9d705..508fedcca 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.document;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -45,13 +45,9 @@ public class TestAppendChildWrongDocument extends
DOMTestCase {
Document document1 = documentBuilder.newDocument();
Document document2 = documentBuilder.newDocument();
Element element = document2.createElementNS(null, "element");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- document1.appendChild(element);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> document1.appendChild(element))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
index 7127e4c5f..e00c3f314 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNSInvalid.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.document;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,15 +42,13 @@ public class TestCreateAttributeNSInvalid extends
DOMTestCase {
@Override
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- document.createAttributeNS(
-
DOMUtils.getNamespaceURI(qname),
-
DOMUtils.getQualifiedName(qname));
- })
- .code)
- .isEqualTo(DOMException.NAMESPACE_ERR);
+ assertThatThrownBy(
+ () ->
+ document.createAttributeNS(
+ DOMUtils.getNamespaceURI(qname),
+ DOMUtils.getQualifiedName(qname)))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.NAMESPACE_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateElementNSWithInvalidName.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateElementNSWithInvalidName.java
index db87866df..9c8c5d4f7 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateElementNSWithInvalidName.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateElementNSWithInvalidName.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.document;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -35,13 +35,9 @@ public class TestCreateElementNSWithInvalidName extends
DOMTestCase {
@Override
protected void runTest() throws Throwable {
Document doc = dbf.newDocumentBuilder().newDocument();
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- doc.createElementNS("urn:ns",
"IN|/ALID");
- })
- .code)
- .isEqualTo(DOMException.INVALID_CHARACTER_ERR);
+ assertThatThrownBy(() -> doc.createElementNS("urn:ns", "IN|/ALID"))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.INVALID_CHARACTER_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java
index 36c2b4943..ec600e9d1 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -47,13 +47,9 @@ public class TestAppendChildCyclic extends DOMTestCase {
grandparent.appendChild(parent);
Element element = document.createElementNS(null, "element");
parent.appendChild(element);
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.appendChild(grandparent);
- })
- .code)
- .isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
+ assertThatThrownBy(() -> element.appendChild(grandparent))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java
index 0956c6863..167ea6a99 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,13 +42,9 @@ public class TestAppendChildSelf extends DOMTestCase {
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
Element element = document.createElementNS("urn:test", "test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.appendChild(element);
- })
- .code)
- .isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
+ assertThatThrownBy(() -> element.appendChild(element))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.java
index 50ca4db75..39b534333 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -47,13 +47,9 @@ public class TestAppendChildWrongDocument extends
DOMTestCase {
Document document2 = documentBuilder.newDocument();
Element element = document1.createElementNS(null, "element");
Text text = document2.createTextNode("test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.appendChild(text);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> element.appendChild(text))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java
index fc1d1eb2c..6cf7a088c 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeForeignImplementation.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -40,13 +40,9 @@ public class TestRemoveAttributeNodeForeignImplementation
extends DOMTestCase {
Document document = dbf.newDocumentBuilder().newDocument();
Element element = document.createElementNS(null, "test");
Attr attr = mock(Attr.class);
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.removeAttributeNode(attr);
- })
- .code)
- .isEqualTo(DOMException.NOT_FOUND_ERR);
+ assertThatThrownBy(() -> element.removeAttributeNode(attr))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.NOT_FOUND_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java
index a6efa994e..8e548a022 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestRemoveAttributeNodeNotOwner.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -47,13 +47,9 @@ public class TestRemoveAttributeNodeNotOwner extends
DOMTestCase {
Element element2 = document.createElementNS(null, "test");
Attr attr2 = document.createAttributeNS(null, "attr");
element2.setAttributeNodeNS(attr2);
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
-
element1.removeAttributeNode(attr2);
- })
- .code)
- .isEqualTo(DOMException.NOT_FOUND_ERR);
+ assertThatThrownBy(() -> element1.removeAttributeNode(attr2))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.NOT_FOUND_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java
index 42532ccd5..dcc79b673 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildCyclic.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -46,13 +46,9 @@ public class TestReplaceChildCyclic extends DOMTestCase {
ancestor.appendChild(element);
Element child = document.createElementNS(null, "child");
element.appendChild(child);
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.replaceChild(ancestor,
child);
- })
- .code)
- .isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
+ assertThatThrownBy(() -> element.replaceChild(ancestor, child))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.java
index 66950f094..784636e03 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNotFound.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -46,13 +46,9 @@ public class TestReplaceChildNotFound extends DOMTestCase {
root.appendChild(document.createElementNS(null, "child"));
Text node1 = document.createTextNode("test1");
Text node2 = document.createTextNode("test2");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- root.replaceChild(node2, node1);
- })
- .code)
- .isEqualTo(DOMException.NOT_FOUND_ERR);
+ assertThatThrownBy(() -> root.replaceChild(node2, node1))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.NOT_FOUND_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.java
index bd7a2a46b..b12d379cc 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildNullNewChild.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.ts.dom.element;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -43,10 +43,6 @@ public class TestReplaceChildNullNewChild extends
DOMTestCase {
Element root = document.createElementNS(null, "root");
Element child = document.createElementNS(null, "child");
root.appendChild(child);
- assertThrows(
- Exception.class,
- () -> {
- root.replaceChild(null, child);
- });
+ assertThatThrownBy(() -> root.replaceChild(null,
child)).isInstanceOf(Exception.class);
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWrongDocument.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWrongDocument.java
index 3e9c3b936..c5bfa53b5 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWrongDocument.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildWrongDocument.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -47,13 +47,9 @@ public class TestReplaceChildWrongDocument extends
DOMTestCase {
parent.appendChild(child2);
parent.appendChild(child3);
Element replacementChild = document2.createElementNS(null, "newchild");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
-
parent.replaceChild(replacementChild, child2);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> parent.replaceChild(replacementChild, child2))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.java
index 4ed5f7742..218d7fda3 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNSInvalid.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -44,16 +44,14 @@ public class TestSetAttributeNSInvalid extends DOMTestCase {
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
Element element = document.createElementNS(null, "test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.setAttributeNS(
-
DOMUtils.getNamespaceURI(qname),
-
DOMUtils.getQualifiedName(qname),
- "value");
- })
- .code)
- .isEqualTo(DOMException.NAMESPACE_ERR);
+ assertThatThrownBy(
+ () ->
+ element.setAttributeNS(
+ DOMUtils.getNamespaceURI(qname),
+ DOMUtils.getQualifiedName(qname),
+ "value"))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.NAMESPACE_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java
index 4752fcf67..e8e0793bd 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSForeignImplementation.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -40,13 +40,9 @@ public class TestSetAttributeNodeNSForeignImplementation
extends DOMTestCase {
Document document = dbf.newDocumentBuilder().newDocument();
Element element = document.createElementNS(null, "test");
Attr attr = mock(Attr.class);
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.setAttributeNodeNS(attr);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> element.setAttributeNodeNS(attr))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSInUse.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSInUse.java
index 40c35d5d0..768b3a209 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSInUse.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSInUse.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -41,13 +41,9 @@ public class TestSetAttributeNodeNSInUse extends DOMTestCase
{
Element element2 = document.createElementNS(null, "test");
Attr attr = document.createAttributeNS(null, "test");
element1.setAttributeNodeNS(attr);
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element2.setAttributeNodeNS(attr);
- })
- .code)
- .isEqualTo(DOMException.INUSE_ATTRIBUTE_ERR);
+ assertThatThrownBy(() -> element2.setAttributeNodeNS(attr))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.INUSE_ATTRIBUTE_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSWrongDocument.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSWrongDocument.java
index c56ca2aa9..ce5469dd5 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSWrongDocument.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeNSWrongDocument.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,13 +42,9 @@ public class TestSetAttributeNodeNSWrongDocument extends
DOMTestCase {
Document document2 = db.newDocument();
Element element = document1.createElementNS(null, "test");
Attr attr = document2.createAttributeNS(null, "test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.setAttributeNodeNS(attr);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> element.setAttributeNodeNS(attr))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeWrongDocument.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeWrongDocument.java
index 5274742ed..9e2addbb4 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeWrongDocument.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNodeWrongDocument.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,13 +42,9 @@ public class TestSetAttributeNodeWrongDocument extends
DOMTestCase {
Document document2 = db.newDocument();
Element element = document1.createElementNS(null, "test");
Attr attr = document2.createAttributeNS(null, "test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.setAttributeNode(attr);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> element.setAttributeNode(attr))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetPrefixNotNullWithoutNamespace.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetPrefixNotNullWithoutNamespace.java
index dbd75db53..94c118407 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetPrefixNotNullWithoutNamespace.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetPrefixNotNullWithoutNamespace.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,13 +42,9 @@ public class TestSetPrefixNotNullWithoutNamespace extends
DOMTestCase {
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
Element element = document.createElementNS(null, "test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- element.setPrefix("p");
- })
- .code)
- .isEqualTo(DOMException.NAMESPACE_ERR);
+ assertThatThrownBy(() -> element.setPrefix("p"))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.NAMESPACE_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/attributes/TestSetNamedItemNSWrongDocument.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/attributes/TestSetNamedItemNSWrongDocument.java
index c860e15b8..61fb70871 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/attributes/TestSetNamedItemNSWrongDocument.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/attributes/TestSetNamedItemNSWrongDocument.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element.attributes;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,13 +42,9 @@ public class TestSetNamedItemNSWrongDocument extends
DOMTestCase {
Document document2 = db.newDocument();
Element element = document1.createElementNS(null, "test");
Attr attr = document2.createAttributeNS(null, "test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
-
element.getAttributes().setNamedItemNS(attr);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> element.getAttributes().setNamedItemNS(attr))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/attributes/TestSetNamedItemWrongDocument.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/attributes/TestSetNamedItemWrongDocument.java
index ce1b38e29..9db4ff6f6 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/attributes/TestSetNamedItemWrongDocument.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/attributes/TestSetNamedItemWrongDocument.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.element.attributes;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,13 +42,9 @@ public class TestSetNamedItemWrongDocument extends
DOMTestCase {
Document document2 = db.newDocument();
Element element = document1.createElementNS(null, "test");
Attr attr = document2.createAttributeNS(null, "test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
-
element.getAttributes().setNamedItem(attr);
- })
- .code)
- .isEqualTo(DOMException.WRONG_DOCUMENT_ERR);
+ assertThatThrownBy(() -> element.getAttributes().setNamedItem(attr))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.WRONG_DOCUMENT_ERR));
}
}
diff --git
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestSetPrefix.java
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestSetPrefix.java
index df5bb25a4..b20f47e24 100644
---
a/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestSetPrefix.java
+++
b/testing/dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestSetPrefix.java
@@ -19,7 +19,7 @@
package org.apache.axiom.ts.dom.text;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -39,13 +39,9 @@ public class TestSetPrefix extends DOMTestCase {
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
Text text = document.createTextNode("test");
- assertThat(
- assertThrows(
- DOMException.class,
- () -> {
- text.setPrefix("p");
- })
- .code)
- .isEqualTo(DOMException.NAMESPACE_ERR);
+ assertThatThrownBy(() -> text.setPrefix("p"))
+ .isInstanceOfSatisfying(
+ DOMException.class,
+ ex ->
assertThat(ex.code).isEqualTo(DOMException.NAMESPACE_ERR));
}
}
diff --git a/testing/spring-ws-testsuite/pom.xml
b/testing/spring-ws-testsuite/pom.xml
index c441db57d..78bf585aa 100644
--- a/testing/spring-ws-testsuite/pom.xml
+++ b/testing/spring-ws-testsuite/pom.xml
@@ -66,6 +66,10 @@
<artifactId>soap-testsuite</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ </dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
diff --git
a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/broker/BrokerScenarioTest.java
b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/broker/BrokerScenarioTest.java
index 305b42907..45c094cd2 100644
---
a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/broker/BrokerScenarioTest.java
+++
b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/broker/BrokerScenarioTest.java
@@ -18,7 +18,8 @@
*/
package org.apache.axiom.ts.springws.scenario.broker;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Locale;
@@ -75,10 +76,13 @@ public class BrokerScenarioTest extends ScenarioTestCase {
Locale oldLocale = Locale.getDefault();
Locale.setDefault(Locale.ENGLISH);
try {
- SoapFaultClientException ex =
- assertThrows(SoapFaultClientException.class, () ->
client.order(order));
- assertEquals(spec.getSenderFaultCode(), ex.getFaultCode());
- assertEquals("Customer 23629 unknown", ex.getMessage());
+ assertThatThrownBy(() -> client.order(order))
+ .isInstanceOfSatisfying(
+ SoapFaultClientException.class,
+ ex -> {
+
assertThat(ex.getFaultCode()).isEqualTo(spec.getSenderFaultCode());
+
assertThat(ex.getMessage()).isEqualTo("Customer 23629 unknown");
+ });
} finally {
Locale.setDefault(oldLocale);
}
diff --git
a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/validation/ValidationTest.java
b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/validation/ValidationTest.java
index 133fd5d08..a07405474 100644
---
a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/validation/ValidationTest.java
+++
b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/validation/ValidationTest.java
@@ -18,7 +18,8 @@
*/
package org.apache.axiom.ts.springws.scenario.validation;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Iterator;
@@ -41,13 +42,19 @@ public class ValidationTest extends ScenarioTestCase {
assertEquals(105.37, client.getQuote("GOOG"), 0.001);
- SoapFaultClientException ex =
- assertThrows(SoapFaultClientException.class, () ->
client.getQuote("TOOLONG"));
- assertEquals(spec.getSenderFaultCode(), ex.getFaultCode());
- Iterator<SoapFaultDetailElement> it =
ex.getSoapFault().getFaultDetail().getDetailEntries();
- assertTrue(it.hasNext());
- assertEquals(
- new QName("http://springframework.org/spring-ws",
"ValidationError"),
- it.next().getName());
+ assertThatThrownBy(() -> client.getQuote("TOOLONG"))
+ .isInstanceOfSatisfying(
+ SoapFaultClientException.class,
+ ex -> {
+
assertThat(ex.getFaultCode()).isEqualTo(spec.getSenderFaultCode());
+ Iterator<SoapFaultDetailElement> it =
+
ex.getSoapFault().getFaultDetail().getDetailEntries();
+ assertThat(it.hasNext()).isTrue();
+ assertThat(it.next().getName())
+ .isEqualTo(
+ new QName(
+
"http://springframework.org/spring-ws",
+ "ValidationError"));
+ });
}
}
diff --git
a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/soap/messagefactory/TestCreateWebServiceMessageFromInputStreamVersionMismatch.java
b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/soap/messagefactory/TestCreateWebServiceMessageFromInputStreamVersionMismatch.java
index 2e55eff0f..eeacf5b3f 100644
---
a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/soap/messagefactory/TestCreateWebServiceMessageFromInputStreamVersionMismatch.java
+++
b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/soap/messagefactory/TestCreateWebServiceMessageFromInputStreamVersionMismatch.java
@@ -18,7 +18,7 @@
*/
package org.apache.axiom.ts.springws.soap.messagefactory;
-import static org.junit.Assert.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.InputStream;
@@ -42,11 +42,12 @@ public class
TestCreateWebServiceMessageFromInputStreamVersionMismatch extends S
@Override
protected void runTest(SoapMessageFactory messageFactory) throws Throwable
{
- assertThrows(
- SoapMessageCreationException.class,
- () ->
- messageFactory.createWebServiceMessage(
- new TransportInputStreamImpl(
-
SOAPSampleSet.NO_HEADER.getMessage(spec.getAltSpec()))));
+ assertThatThrownBy(
+ () ->
+ messageFactory.createWebServiceMessage(
+ new TransportInputStreamImpl(
+
SOAPSampleSet.NO_HEADER.getMessage(
+ spec.getAltSpec()))))
+ .isInstanceOf(SoapMessageCreationException.class);
}
}