From 46be1c5d6b9b2c904b05dffe57a95c0579e9218b Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Fri, 2 Jan 2026 12:13:00 +0100 Subject: [PATCH 1/2] Migrate from TestNG to JUnit 6 --- pom.xml | 37 ++++++++-- .../org/weakref/jmx/AbstractMbeanTest.java | 42 ++++++----- src/test/java/org/weakref/jmx/Assert.java | 70 +++++++++++++++++++ .../java/org/weakref/jmx/TestExporter.java | 13 ++-- .../java/org/weakref/jmx/TestExports.java | 15 ++-- .../org/weakref/jmx/TestInheritanceBase.java | 5 +- .../weakref/jmx/TestObjectNameBuilder.java | 4 +- .../java/org/weakref/jmx/TestObjectNames.java | 16 +++-- .../weakref/jmx/TestTestingMBeanServer.java | 7 +- .../java/org/weakref/jmx/TestUnexporter.java | 21 +++--- .../weakref/jmx/guice/TestMBeanModule.java | 4 +- 11 files changed, 174 insertions(+), 60 deletions(-) create mode 100644 src/test/java/org/weakref/jmx/Assert.java diff --git a/pom.xml b/pom.xml index bcfa51c..7d11fb8 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ org.weakref.jmx.\$internal 0.8.7 + 6.0.1 @@ -47,12 +48,6 @@ - - org.testng - testng - 6.2.1 - test - com.google.inject @@ -73,7 +68,37 @@ 3.0.0 true + + + org.junit.jupiter + junit-jupiter-api + ${dep.junit.version} + test + + + + org.junit.jupiter + junit-jupiter-engine + ${dep.junit.version} + test + + + + org.junit.jupiter + junit-jupiter-params + ${dep.junit.version} + test + + + + org.assertj + assertj-core + 3.27.6 + test + + + diff --git a/src/test/java/org/weakref/jmx/AbstractMbeanTest.java b/src/test/java/org/weakref/jmx/AbstractMbeanTest.java index 4cd0ff4..689b2c5 100644 --- a/src/test/java/org/weakref/jmx/AbstractMbeanTest.java +++ b/src/test/java/org/weakref/jmx/AbstractMbeanTest.java @@ -1,23 +1,28 @@ package org.weakref.jmx; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import javax.management.AttributeNotFoundException; import javax.management.MBeanAttributeInfo; import javax.management.MBeanInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanParameterInfo; + import java.lang.reflect.Method; import java.util.List; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +import static org.weakref.jmx.Assert.assertEquals; +import static org.weakref.jmx.Assert.assertFalse; +import static org.weakref.jmx.Assert.assertNotNull; +import static org.weakref.jmx.Assert.assertNull; +import static org.weakref.jmx.Assert.assertTrue; +import static org.weakref.jmx.Assert.fail; +@TestInstance(PER_CLASS) public abstract class AbstractMbeanTest { protected List objects; @@ -36,7 +41,8 @@ protected abstract void setAttribute(T t, String attributeName, Object value) protected abstract Object invoke(T t, Object value, String operationName) throws Exception; - @Test(dataProvider = "fixtures") + @ParameterizedTest + @MethodSource("getFixtures") public void testGetterAttributeInfo(String attribute, boolean isIs, Object[] values, Class clazz) throws Exception { @@ -56,7 +62,8 @@ public void testGetterAttributeInfo(String attribute, boolean isIs, Object[] val } } - @Test(dataProvider = "fixtures") + @ParameterizedTest + @MethodSource("getFixtures") public void testSetterAttributeInfo(String attribute, boolean isIs, Object[] values, Class clazz) throws Exception { @@ -132,7 +139,8 @@ private static MBeanAttributeInfo getAttributeInfo(MBeanInfo info, String attrib return null; } - @Test(dataProvider = "fixtures") + @ParameterizedTest + @MethodSource("getFixtures") public void testOperationInfo(String attribute, boolean isIs, Object[] values, Class clazz) throws Exception { @@ -158,7 +166,8 @@ public void testOperationInfo(String attribute, boolean isIs, Object[] values, C } } - @Test(dataProvider = "fixtures") + @ParameterizedTest + @MethodSource("getFixtures") public void testGet(String attribute, boolean isIs, Object[] values, Class clazz) throws Exception { @@ -176,7 +185,8 @@ public void testGet(String attribute, boolean isIs, Object[] values, Class cl } } - @Test(dataProvider = "fixtures") + @ParameterizedTest + @MethodSource("getFixtures") public void testSet(String attribute, boolean isIs, Object[] values, Class clazz) throws Exception { @@ -285,7 +295,8 @@ public void testDescription() } } - @Test(dataProvider = "fixtures") + @ParameterizedTest + @MethodSource("getFixtures") public void testOperation(String attribute, boolean isIs, Object[] values, Class clazz) throws Exception { @@ -297,8 +308,7 @@ public void testOperation(String attribute, boolean isIs, Object[] values, Class } } - @DataProvider(name = "fixtures") - Object[][] getFixtures() + static Object[][] getFixtures() { return new Object[][] { diff --git a/src/test/java/org/weakref/jmx/Assert.java b/src/test/java/org/weakref/jmx/Assert.java new file mode 100644 index 0000000..2c56cba --- /dev/null +++ b/src/test/java/org/weakref/jmx/Assert.java @@ -0,0 +1,70 @@ +package org.weakref.jmx; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * TestNG compatible Assert API to aid migration to JUnit + * + * @deprecated for migration period only + */ +// TODO all these methods to be inlined or migrated separately +@Deprecated +public final class Assert +{ + private Assert() {} + + public static void assertEquals(T actual, T expected) + { + assertThat(actual).isEqualTo(expected); + } + + public static void assertEquals(T actual, T expected, String message) + { + assertThat(actual).describedAs(message).isEqualTo(expected); + } + + public static void fail(String message) + { + throw new AssertionError(message); + } + + public static void assertFalse(boolean actual) + { + assertThat(actual).isFalse(); + } + + public static void assertFalse(boolean actual, String message) + { + assertThat(actual).describedAs(message).isFalse(); + } + + public static void assertTrue(boolean actual) + { + assertThat(actual).isTrue(); + } + + public static void assertTrue(boolean actual, String message) + { + assertThat(actual).describedAs(message).isTrue(); + } + + public static void assertNull(Object actual) + { + assertThat(actual).isNull(); + } + + public static void assertNull(Object actual, String message) + { + assertThat(actual).describedAs(message).isNull(); + } + + public static void assertNotNull(Object actual) + { + assertThat(actual).isNotNull(); + } + + public static void assertNotNull(Object actual, String message) + { + assertThat(actual).describedAs(message).isNotNull(); + } +} diff --git a/src/test/java/org/weakref/jmx/TestExporter.java b/src/test/java/org/weakref/jmx/TestExporter.java index 46eda2c..f4f6461 100644 --- a/src/test/java/org/weakref/jmx/TestExporter.java +++ b/src/test/java/org/weakref/jmx/TestExporter.java @@ -16,8 +16,9 @@ package org.weakref.jmx; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.weakref.jmx.testing.TestingMBeanServer; import javax.management.AttributeNotFoundException; @@ -32,8 +33,8 @@ import java.util.ArrayList; import java.util.Map; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.weakref.jmx.Assert.assertEquals; +import static org.weakref.jmx.Assert.assertTrue; import static org.weakref.jmx.Util.getUniqueObjectName; public class TestExporter extends AbstractMbeanTest @@ -93,7 +94,7 @@ protected Object invoke(NamedObject namedObject, Object value, String operationN new String[] { Object.class.getName() }); } - @BeforeMethod + @BeforeEach void setup() { server = new TestingMBeanServer(); @@ -146,5 +147,3 @@ void testDuplicateKey() assertEquals(exporter.getExportedObjects().size(), 1); } } - - diff --git a/src/test/java/org/weakref/jmx/TestExports.java b/src/test/java/org/weakref/jmx/TestExports.java index 90344c9..0236afd 100644 --- a/src/test/java/org/weakref/jmx/TestExports.java +++ b/src/test/java/org/weakref/jmx/TestExports.java @@ -1,15 +1,18 @@ package org.weakref.jmx; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import javax.management.MBeanServer; import javax.management.ObjectName; import java.lang.management.ManagementFactory; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; + +@TestInstance(PER_CLASS) public class TestExports { private MBeanServer server; @@ -18,7 +21,7 @@ public class TestExports private ObjectName objectName; private String name; - @BeforeMethod + @BeforeEach public void setUp() { Assert.assertNull(name); @@ -33,7 +36,7 @@ public void setUp() Assert.assertNotNull(name); } - @AfterMethod + @AfterEach public void tearDown() { Assert.assertNotNull(name); diff --git a/src/test/java/org/weakref/jmx/TestInheritanceBase.java b/src/test/java/org/weakref/jmx/TestInheritanceBase.java index 0387a35..1c73770 100644 --- a/src/test/java/org/weakref/jmx/TestInheritanceBase.java +++ b/src/test/java/org/weakref/jmx/TestInheritanceBase.java @@ -15,12 +15,11 @@ */ package org.weakref.jmx; +import org.junit.jupiter.api.Test; + import java.lang.reflect.Method; import java.util.Map; -import org.testng.Assert; -import org.testng.annotations.Test; - public abstract class TestInheritanceBase { protected final Class target; diff --git a/src/test/java/org/weakref/jmx/TestObjectNameBuilder.java b/src/test/java/org/weakref/jmx/TestObjectNameBuilder.java index 5263bf9..3549752 100755 --- a/src/test/java/org/weakref/jmx/TestObjectNameBuilder.java +++ b/src/test/java/org/weakref/jmx/TestObjectNameBuilder.java @@ -1,11 +1,11 @@ package org.weakref.jmx; import com.google.inject.name.Names; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.lang.annotation.Annotation; -import static org.testng.Assert.assertEquals; +import static org.weakref.jmx.Assert.assertEquals; public class TestObjectNameBuilder { diff --git a/src/test/java/org/weakref/jmx/TestObjectNames.java b/src/test/java/org/weakref/jmx/TestObjectNames.java index 07d6a96..262dd6a 100755 --- a/src/test/java/org/weakref/jmx/TestObjectNames.java +++ b/src/test/java/org/weakref/jmx/TestObjectNames.java @@ -1,16 +1,18 @@ package org.weakref.jmx; import com.google.inject.name.Names; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; + import java.lang.annotation.Annotation; import java.util.ArrayList; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.weakref.jmx.Assert.assertEquals; +import static org.weakref.jmx.Assert.assertTrue; import static org.weakref.jmx.ObjectNames.generatedNameOf; public class TestObjectNames { @@ -68,7 +70,8 @@ public void testGeneratedNameOfStringWithQuoting() { "org.weakref.jmx:type=SimpleObject,name=\"bar,baz\""); } - @Test(dataProvider = "names") + @ParameterizedTest + @MethodSource("getNames") public void testQuotesName(String name, boolean shouldQuote) throws MalformedObjectNameException { @@ -102,8 +105,7 @@ public void testQuotesName(String name, boolean shouldQuote) } } - @DataProvider(name = "names") - public Object[][] getNames() + public static Object[][] getNames() { ArrayList names = new ArrayList<>(); for (char c = 0; c < 500; ++c) { diff --git a/src/test/java/org/weakref/jmx/TestTestingMBeanServer.java b/src/test/java/org/weakref/jmx/TestTestingMBeanServer.java index 8975bd8..7d2ac3d 100644 --- a/src/test/java/org/weakref/jmx/TestTestingMBeanServer.java +++ b/src/test/java/org/weakref/jmx/TestTestingMBeanServer.java @@ -1,18 +1,19 @@ package org.weakref.jmx; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import org.weakref.jmx.testing.TestingMBeanServer; import javax.management.InstanceAlreadyExistsException; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.Query; + import java.util.Map; import java.util.Set; import static java.util.Collections.emptySet; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.weakref.jmx.Assert.assertEquals; +import static org.weakref.jmx.Assert.assertTrue; public class TestTestingMBeanServer { diff --git a/src/test/java/org/weakref/jmx/TestUnexporter.java b/src/test/java/org/weakref/jmx/TestUnexporter.java index 0f382aa..fc1230f 100644 --- a/src/test/java/org/weakref/jmx/TestUnexporter.java +++ b/src/test/java/org/weakref/jmx/TestUnexporter.java @@ -1,9 +1,9 @@ package org.weakref.jmx; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import javax.management.InstanceNotFoundException; import javax.management.IntrospectionException; @@ -11,13 +11,17 @@ import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.ReflectionException; + import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.List; import java.util.Map; import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; +@TestInstance(PER_CLASS) public class TestUnexporter { private MBeanServer server; @@ -25,7 +29,7 @@ public class TestUnexporter private List objectNames; - @BeforeMethod + @BeforeEach public void setUp() { server = ManagementFactory.getPlatformMBeanServer(); @@ -42,7 +46,7 @@ public void setUp() Assert.assertNotNull(exporter); } - @AfterMethod + @AfterEach public void tearDown() { Assert.assertNotNull(server); @@ -58,14 +62,15 @@ public void tearDown() } } - @Test(expectedExceptions = InstanceNotFoundException.class) + @Test public void testUnexportOk() throws Exception { ObjectName name = objectNames.get(0); Assert.assertEquals("Hello!", server.getAttribute(name, "Hello")); exporter.unexport(name.getCanonicalName()); - server.getAttribute(name, "Hello"); + assertThatThrownBy(() -> server.getAttribute(name, "Hello")) + .isInstanceOf(InstanceNotFoundException.class); } @Test diff --git a/src/test/java/org/weakref/jmx/guice/TestMBeanModule.java b/src/test/java/org/weakref/jmx/guice/TestMBeanModule.java index 0ee8bfe..0731b09 100644 --- a/src/test/java/org/weakref/jmx/guice/TestMBeanModule.java +++ b/src/test/java/org/weakref/jmx/guice/TestMBeanModule.java @@ -21,8 +21,8 @@ import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.multibindings.Multibinder; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; +import org.weakref.jmx.Assert; import org.weakref.jmx.MBeanExporter; import org.weakref.jmx.ObjectNameBuilder; import org.weakref.jmx.ObjectNameGenerator; From e95424e2421290c3ce3566ae8bc440f96e1a038a Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 25 Mar 2026 20:08:17 +0100 Subject: [PATCH 2/2] Remove TestNG compatible Assert Inline. --- .../org/weakref/jmx/AbstractMbeanTest.java | 85 +++++++++---------- src/test/java/org/weakref/jmx/Assert.java | 70 --------------- .../java/org/weakref/jmx/TestExporter.java | 13 ++- .../java/org/weakref/jmx/TestExports.java | 25 +++--- .../org/weakref/jmx/TestInheritanceBase.java | 4 +- .../weakref/jmx/TestObjectNameBuilder.java | 42 ++++----- .../java/org/weakref/jmx/TestObjectNames.java | 43 ++++------ .../weakref/jmx/TestTestingMBeanServer.java | 35 ++++---- .../java/org/weakref/jmx/TestUnexporter.java | 26 +++--- .../weakref/jmx/guice/TestMBeanModule.java | 24 +++--- 10 files changed, 140 insertions(+), 227 deletions(-) delete mode 100644 src/test/java/org/weakref/jmx/Assert.java diff --git a/src/test/java/org/weakref/jmx/AbstractMbeanTest.java b/src/test/java/org/weakref/jmx/AbstractMbeanTest.java index 689b2c5..ba54ce0 100644 --- a/src/test/java/org/weakref/jmx/AbstractMbeanTest.java +++ b/src/test/java/org/weakref/jmx/AbstractMbeanTest.java @@ -15,12 +15,7 @@ import java.util.List; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; -import static org.weakref.jmx.Assert.assertEquals; -import static org.weakref.jmx.Assert.assertFalse; -import static org.weakref.jmx.Assert.assertNotNull; -import static org.weakref.jmx.Assert.assertNull; -import static org.weakref.jmx.Assert.assertTrue; -import static org.weakref.jmx.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; @TestInstance(PER_CLASS) public abstract class AbstractMbeanTest @@ -54,11 +49,11 @@ public void testGetterAttributeInfo(String attribute, boolean isIs, Object[] val MBeanInfo info = getMBeanInfo(t); MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName); - assertNotNull(attributeInfo, "AttributeInfo for " + attributeName); - assertEquals(attributeInfo.getName(), attributeName, "Attribute Name for " + attributeName); - assertEquals(attributeInfo.getType(), setter.getParameterTypes()[0].getName(), "Attribute type for " + attributeName); - assertEquals(attributeInfo.isIs(), isIs, "Attribute isIs for " + attributeName); - assertTrue(attributeInfo.isReadable(), "Attribute Readable for " + attributeName); + assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNotNull(); + assertThat(attributeInfo.getName()).describedAs("Attribute Name for " + attributeName).isEqualTo(attributeName); + assertThat(attributeInfo.getType()).describedAs("Attribute type for " + attributeName).isEqualTo(setter.getParameterTypes()[0].getName()); + assertThat(attributeInfo.isIs()).describedAs("Attribute isIs for " + attributeName).isEqualTo(isIs); + assertThat(attributeInfo.isReadable()).describedAs("Attribute Readable for " + attributeName).isTrue(); } } @@ -76,10 +71,10 @@ public void testSetterAttributeInfo(String attribute, boolean isIs, Object[] val MBeanInfo info = getMBeanInfo(t); MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName); - assertNotNull(attributeInfo, "AttributeInfo for " + attributeName); - assertEquals(attributeInfo.getName(), attributeName, "Attribute Name for " + attributeName); - assertEquals(attributeInfo.getType(), getter.getReturnType().getName(), "Attribute Type for " + attributeName); - assertTrue(attributeInfo.isWritable(), "Attribute Writable for " + attributeName); + assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNotNull(); + assertThat(attributeInfo.getName()).describedAs("Attribute Name for " + attributeName).isEqualTo(attributeName); + assertThat(attributeInfo.getType()).describedAs("Attribute Type for " + attributeName).isEqualTo(getter.getReturnType().getName()); + assertThat(attributeInfo.isWritable()).describedAs("Attribute Writable for " + attributeName).isTrue(); } } @@ -92,7 +87,7 @@ public void testNotManagedAttributeInfo() MBeanInfo info = getMBeanInfo(t); String attributeName = toFeatureName("NotManaged", t); MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName); - assertNull(attributeInfo, "AttributeInfo for " + attributeName); + assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNull(); } } @@ -105,11 +100,11 @@ public void testReadOnlyAttributeInfo() String attributeName = toFeatureName("ReadOnly", t); MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName); - assertNotNull(attributeInfo, "AttributeInfo for " + attributeName); - assertEquals(attributeInfo.getName(), attributeName, "Attribute Name for " + attributeName); - assertEquals(attributeInfo.getType(), "int", "Attribute Type for " + attributeName); - assertTrue(attributeInfo.isReadable(), "Attribute Readable for " + attributeName); - assertFalse(attributeInfo.isWritable(), "Attribute Writable for " + attributeName); + assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNotNull(); + assertThat(attributeInfo.getName()).describedAs("Attribute Name for " + attributeName).isEqualTo(attributeName); + assertThat(attributeInfo.getType()).describedAs("Attribute Type for " + attributeName).isEqualTo("int"); + assertThat(attributeInfo.isReadable()).describedAs("Attribute Readable for " + attributeName).isTrue(); + assertThat(attributeInfo.isWritable()).describedAs("Attribute Writable for " + attributeName).isFalse(); } } @@ -121,11 +116,11 @@ public void testWriteOnlyAttributeInfo() MBeanInfo info = getMBeanInfo(t); String attributeName = toFeatureName("WriteOnly", t); MBeanAttributeInfo attributeInfo = getAttributeInfo(info, attributeName); - assertNotNull(attributeInfo, "AttributeInfo for " + attributeName); - assertEquals(attributeInfo.getName(), attributeName, "Attribute Name for " + attributeName); - assertEquals(attributeInfo.getType(), "int", "Attribute Type for " + attributeName); - assertFalse(attributeInfo.isReadable(), "Attribute Readable for " + attributeName); - assertTrue(attributeInfo.isWritable(), "Attribute Writable for " + attributeName); + assertThat(attributeInfo).describedAs("AttributeInfo for " + attributeName).isNotNull(); + assertThat(attributeInfo.getName()).describedAs("Attribute Name for " + attributeName).isEqualTo(attributeName); + assertThat(attributeInfo.getType()).describedAs("Attribute Type for " + attributeName).isEqualTo("int"); + assertThat(attributeInfo.isReadable()).describedAs("Attribute Readable for " + attributeName).isFalse(); + assertThat(attributeInfo.isWritable()).describedAs("Attribute Writable for " + attributeName).isTrue(); } } @@ -155,14 +150,14 @@ public void testOperationInfo(String attribute, boolean isIs, Object[] values, C } } - assertNotNull(operationInfo, "OperationInfo for " + operationName); - assertEquals(operationInfo.getName(), operationName, "Operation Name for " + operationName); - assertEquals(operationInfo.getImpact(), MBeanOperationInfo.UNKNOWN, "Operation Impact for " + operationName); - assertEquals(operationInfo.getReturnType(), Object.class.getName(), "Operation Return Type for " + operationName); - assertEquals(operationInfo.getSignature().length, 1, "Operation Parameter Length for " + operationName); + assertThat(operationInfo).describedAs("OperationInfo for " + operationName).isNotNull(); + assertThat(operationInfo.getName()).describedAs("Operation Name for " + operationName).isEqualTo(operationName); + assertThat(operationInfo.getImpact()).describedAs("Operation Impact for " + operationName).isEqualTo(MBeanOperationInfo.UNKNOWN); + assertThat(operationInfo.getReturnType()).describedAs("Operation Return Type for " + operationName).isEqualTo(Object.class.getName()); + assertThat(operationInfo.getSignature().length).describedAs("Operation Parameter Length for " + operationName).isEqualTo(1); MBeanParameterInfo parameterInfo = operationInfo.getSignature()[0]; - assertEquals(parameterInfo.getName(), "value", "Operation Parameter[0] Name for " + operationName); - assertEquals(parameterInfo.getType(), Object.class.getName(), "Operation Parameter[0] Type for " + operationName); + assertThat(parameterInfo.getName()).describedAs("Operation Parameter[0] Name for " + operationName).isEqualTo("value"); + assertThat(parameterInfo.getType()).describedAs("Operation Parameter[0] Type for " + operationName).isEqualTo(Object.class.getName()); } } @@ -180,7 +175,7 @@ public void testGet(String attribute, boolean isIs, Object[] values, Class cl for (Object value : values) { setter.invoke(simpleObject, value); - assertEquals(getAttribute(t, attributeName), value); + assertThat(getAttribute(t, attributeName)).isEqualTo(value); } } } @@ -200,7 +195,7 @@ public void testSet(String attribute, boolean isIs, Object[] values, Class cl for (Object value : values) { setAttribute(t, attributeName, value); - assertEquals(getter.invoke(simpleObject), value); + assertThat(getter.invoke(simpleObject)).isEqualTo(value); } } } @@ -215,13 +210,13 @@ public void testSetFailsOnNotManaged() simpleObject.setNotManaged(1); try { setAttribute(t, "NotManaged", 2); - fail("Should not allow setting unmanaged attribute"); + throw new AssertionError("Should not allow setting unmanaged attribute"); } catch (AttributeNotFoundException e) { // ignore } - assertEquals(simpleObject.getNotManaged(), 1); + assertThat(simpleObject.getNotManaged()).isEqualTo(1); } } @@ -233,7 +228,7 @@ public void testGetFailsOnNotManaged() for (T t : objects) { try { getAttribute(t, "NotManaged"); - fail("Should not allow getting unmanaged attribute"); + throw new AssertionError("Should not allow getting unmanaged attribute"); } catch (AttributeNotFoundException e) { // ignore @@ -248,7 +243,7 @@ public void testGetFailsOnWriteOnly() for (T t : objects) { try { getAttribute(t, "WriteOnly"); - fail("Should not allow getting write-only attribute"); + throw new AssertionError("Should not allow getting write-only attribute"); } catch (AttributeNotFoundException e) { // ignore @@ -265,13 +260,13 @@ public void testSetFailsOnReadOnly() simpleObject.setReadOnly(1); try { setAttribute(t, "ReadOnly", 2); - fail("Should not allow setting read-only attribute"); + throw new AssertionError("Should not allow setting read-only attribute"); } catch (AttributeNotFoundException e) { // ignore } - assertEquals(simpleObject.getReadOnly(), 1); + assertThat(simpleObject.getReadOnly()).isEqualTo(1); } } @@ -284,14 +279,14 @@ public void testDescription() for (MBeanAttributeInfo info : getMBeanInfo(t).getAttributes()) { String attributeName = toFeatureName("DescribedInt", t); if (info.getName().equals(attributeName)) { - assertEquals("epic description", info.getDescription()); + assertThat(info.getDescription()).isEqualTo("epic description"); described = true; } else { - assertEquals("", info.getDescription()); + assertThat(info.getDescription()).isEqualTo(""); } } - assertTrue(described); + assertThat(described).isTrue(); } } @@ -303,7 +298,7 @@ public void testOperation(String attribute, boolean isIs, Object[] values, Class for (T t : objects) { for (Object value : values) { String operationName = toFeatureName("echo", t); - assertEquals(invoke(t, value, operationName), value); + assertThat(invoke(t, value, operationName)).isEqualTo(value); } } } diff --git a/src/test/java/org/weakref/jmx/Assert.java b/src/test/java/org/weakref/jmx/Assert.java deleted file mode 100644 index 2c56cba..0000000 --- a/src/test/java/org/weakref/jmx/Assert.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.weakref.jmx; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * TestNG compatible Assert API to aid migration to JUnit - * - * @deprecated for migration period only - */ -// TODO all these methods to be inlined or migrated separately -@Deprecated -public final class Assert -{ - private Assert() {} - - public static void assertEquals(T actual, T expected) - { - assertThat(actual).isEqualTo(expected); - } - - public static void assertEquals(T actual, T expected, String message) - { - assertThat(actual).describedAs(message).isEqualTo(expected); - } - - public static void fail(String message) - { - throw new AssertionError(message); - } - - public static void assertFalse(boolean actual) - { - assertThat(actual).isFalse(); - } - - public static void assertFalse(boolean actual, String message) - { - assertThat(actual).describedAs(message).isFalse(); - } - - public static void assertTrue(boolean actual) - { - assertThat(actual).isTrue(); - } - - public static void assertTrue(boolean actual, String message) - { - assertThat(actual).describedAs(message).isTrue(); - } - - public static void assertNull(Object actual) - { - assertThat(actual).isNull(); - } - - public static void assertNull(Object actual, String message) - { - assertThat(actual).describedAs(message).isNull(); - } - - public static void assertNotNull(Object actual) - { - assertThat(actual).isNotNull(); - } - - public static void assertNotNull(Object actual, String message) - { - assertThat(actual).describedAs(message).isNotNull(); - } -} diff --git a/src/test/java/org/weakref/jmx/TestExporter.java b/src/test/java/org/weakref/jmx/TestExporter.java index f4f6461..62a07ec 100644 --- a/src/test/java/org/weakref/jmx/TestExporter.java +++ b/src/test/java/org/weakref/jmx/TestExporter.java @@ -33,8 +33,7 @@ import java.util.ArrayList; import java.util.Map; -import static org.weakref.jmx.Assert.assertEquals; -import static org.weakref.jmx.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.weakref.jmx.Util.getUniqueObjectName; public class TestExporter extends AbstractMbeanTest @@ -120,14 +119,14 @@ void testManagedClasses() for(NamedObject namedObject : objects) { String name = namedObject.objectName.getCanonicalName(); - assertTrue(managedClasses.containsKey(name)); + assertThat(managedClasses.containsKey(name)).isTrue(); ManagedClass managedClass = managedClasses.get(name); - assertEquals(namedObject.object, managedClass.getTarget()); + assertThat(managedClass.getTarget()).isEqualTo(namedObject.object); if(namedObject.object instanceof NestedObject || namedObject.object instanceof FlattenObject) { - assertEquals(managedClass.getChildren().size(), 1); - assertEquals(managedClass.getChildren().get("SimpleObject").getTargetClass(), SimpleObject.class); + assertThat(managedClass.getChildren().size()).isEqualTo(1); + assertThat(managedClass.getChildren().get("SimpleObject").getTargetClass()).isEqualTo(SimpleObject.class); } } } @@ -144,6 +143,6 @@ void testDuplicateKey() catch(JmxException e) { // do nothing } - assertEquals(exporter.getExportedObjects().size(), 1); + assertThat(exporter.getExportedObjects().size()).isEqualTo(1); } } diff --git a/src/test/java/org/weakref/jmx/TestExports.java b/src/test/java/org/weakref/jmx/TestExports.java index 0236afd..9965972 100644 --- a/src/test/java/org/weakref/jmx/TestExports.java +++ b/src/test/java/org/weakref/jmx/TestExports.java @@ -10,6 +10,7 @@ import java.lang.management.ManagementFactory; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; @TestInstance(PER_CLASS) @@ -24,25 +25,25 @@ public class TestExports @BeforeEach public void setUp() { - Assert.assertNull(name); + assertThat(name).isNull(); objectName = Util.getUniqueObjectName(); name = objectName.getCanonicalName(); server = ManagementFactory.getPlatformMBeanServer(); exporter = new MBeanExporter(server); - Assert.assertNotNull(server); - Assert.assertNotNull(exporter); - Assert.assertNotNull(objectName); - Assert.assertNotNull(name); + assertThat(server).isNotNull(); + assertThat(exporter).isNotNull(); + assertThat(objectName).isNotNull(); + assertThat(name).isNotNull(); } @AfterEach public void tearDown() { - Assert.assertNotNull(name); - Assert.assertNotNull(server); - Assert.assertNotNull(exporter); - Assert.assertNotNull(objectName); + assertThat(name).isNotNull(); + assertThat(server).isNotNull(); + assertThat(exporter).isNotNull(); + assertThat(objectName).isNotNull(); exporter.unexport(name); @@ -57,7 +58,7 @@ public void testExportOk() throws Exception { exporter.export(name, new TestBean()); - Assert.assertEquals("Hello!", server.getAttribute(objectName, "Hello")); + assertThat(server.getAttribute(objectName, "Hello")).isEqualTo("Hello!"); } @Test @@ -65,13 +66,13 @@ public void testExportDouble() throws Throwable { exporter.export(name, new TestBean()); - Assert.assertEquals("Hello!", server.getAttribute(objectName, "Hello")); + assertThat(server.getAttribute(objectName, "Hello")).isEqualTo("Hello!"); try { exporter.export(name, new TestBean()); } catch (JmxException e) { - Assert.assertEquals(e.getReason(), JmxException.Reason.INSTANCE_ALREADY_EXISTS); + assertThat(e.getReason()).isEqualTo(JmxException.Reason.INSTANCE_ALREADY_EXISTS); } } diff --git a/src/test/java/org/weakref/jmx/TestInheritanceBase.java b/src/test/java/org/weakref/jmx/TestInheritanceBase.java index 1c73770..808d86c 100644 --- a/src/test/java/org/weakref/jmx/TestInheritanceBase.java +++ b/src/test/java/org/weakref/jmx/TestInheritanceBase.java @@ -20,6 +20,8 @@ import java.lang.reflect.Method; import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; + public abstract class TestInheritanceBase { protected final Class target; @@ -55,6 +57,6 @@ public void testResolver() throws NoSuchMethodException { Map map = AnnotationUtils.findManagedMethods(getTargetClass()); Method annotatedMethod = map.get(getTargetMethod()); - Assert.assertEquals(annotatedMethod, expected()); + assertThat(annotatedMethod).isEqualTo(expected()); } } diff --git a/src/test/java/org/weakref/jmx/TestObjectNameBuilder.java b/src/test/java/org/weakref/jmx/TestObjectNameBuilder.java index 3549752..725a414 100755 --- a/src/test/java/org/weakref/jmx/TestObjectNameBuilder.java +++ b/src/test/java/org/weakref/jmx/TestObjectNameBuilder.java @@ -5,7 +5,7 @@ import java.lang.annotation.Annotation; -import static org.weakref.jmx.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestObjectNameBuilder { @@ -30,64 +30,56 @@ static class Inner @Test public void testObjectNameBuilder1() { - assertEquals( - ObjectNames.builder(SimpleObject.class).build(), - "org.weakref.jmx:name=SimpleObject"); + assertThat(ObjectNames.builder(SimpleObject.class).build()) + .isEqualTo("org.weakref.jmx:name=SimpleObject"); } @Test public void testObjectNameBuilder2() { - assertEquals( - ObjectNames.builder(SimpleObject.class, Names.named("1")).build(), - "org.weakref.jmx:type=SimpleObject,name=1"); + assertThat(ObjectNames.builder(SimpleObject.class, Names.named("1")).build()) + .isEqualTo("org.weakref.jmx:type=SimpleObject,name=1"); } @Test public void testObjectNameBuilder3() { - assertEquals( - ObjectNames.builder(SimpleObject.class, Ann.class).build(), - "org.weakref.jmx:type=SimpleObject,name=Ann"); + assertThat(ObjectNames.builder(SimpleObject.class, Ann.class).build()) + .isEqualTo("org.weakref.jmx:type=SimpleObject,name=Ann"); } @Test public void testObjectNameBuilder4() { - assertEquals( - ObjectNames.builder(SimpleObject.class, new AnnImpl()).build(), - "org.weakref.jmx:type=SimpleObject,name=Ann"); + assertThat(ObjectNames.builder(SimpleObject.class, new AnnImpl()).build()) + .isEqualTo("org.weakref.jmx:type=SimpleObject,name=Ann"); } @Test public void testObjectNameBuilder5() { - assertEquals( - ObjectNames.builder(Inner.class).build(), - "org.weakref.jmx:name=Inner"); + assertThat(ObjectNames.builder(Inner.class).build()) + .isEqualTo("org.weakref.jmx:name=Inner"); } @Test public void testObjectNameBuilderWithString() { - assertEquals( - ObjectNames.builder(SimpleObject.class, "foo").build(), - "org.weakref.jmx:type=SimpleObject,name=foo"); + assertThat(ObjectNames.builder(SimpleObject.class, "foo").build()) + .isEqualTo("org.weakref.jmx:type=SimpleObject,name=foo"); } @Test public void testObjectNameBuilderWithProperty() { - assertEquals( - ObjectNames.builder(SimpleObject.class).withProperty("id", "5").build(), - "org.weakref.jmx:name=SimpleObject,id=5"); + assertThat(ObjectNames.builder(SimpleObject.class).withProperty("id", "5").build()) + .isEqualTo("org.weakref.jmx:name=SimpleObject,id=5"); } @Test public void testObjectNameBuilderQuotesPropertyNames() { - assertEquals( - ObjectNames.builder(SimpleObject.class).withProperty("foo", "bar,baz").build(), - "org.weakref.jmx:name=SimpleObject,foo=\"bar,baz\""); + assertThat(ObjectNames.builder(SimpleObject.class).withProperty("foo", "bar,baz").build()) + .isEqualTo("org.weakref.jmx:name=SimpleObject,foo=\"bar,baz\""); } } diff --git a/src/test/java/org/weakref/jmx/TestObjectNames.java b/src/test/java/org/weakref/jmx/TestObjectNames.java index 262dd6a..315ec00 100755 --- a/src/test/java/org/weakref/jmx/TestObjectNames.java +++ b/src/test/java/org/weakref/jmx/TestObjectNames.java @@ -11,8 +11,7 @@ import java.lang.annotation.Annotation; import java.util.ArrayList; -import static org.weakref.jmx.Assert.assertEquals; -import static org.weakref.jmx.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import static org.weakref.jmx.ObjectNames.generatedNameOf; public class TestObjectNames { @@ -30,44 +29,38 @@ static class Inner {} @Test public void testGeneratedNameOf1() { - assertEquals( - generatedNameOf(SimpleObject.class), - "org.weakref.jmx:name=SimpleObject"); + assertThat(generatedNameOf(SimpleObject.class)) + .isEqualTo("org.weakref.jmx:name=SimpleObject"); } @Test public void testGeneratedNameOf2() { - assertEquals( - generatedNameOf(SimpleObject.class, Names.named("1")), - "org.weakref.jmx:type=SimpleObject,name=1"); + assertThat(generatedNameOf(SimpleObject.class, Names.named("1"))) + .isEqualTo("org.weakref.jmx:type=SimpleObject,name=1"); } @Test public void testGeneratedNameOf3() { - assertEquals( - generatedNameOf(SimpleObject.class, Ann.class), - "org.weakref.jmx:type=SimpleObject,name=Ann"); + assertThat(generatedNameOf(SimpleObject.class, Ann.class)) + .isEqualTo("org.weakref.jmx:type=SimpleObject,name=Ann"); } @Test public void testGeneratedNameOf4() { - assertEquals( - generatedNameOf(SimpleObject.class, new AnnImpl()), - "org.weakref.jmx:type=SimpleObject,name=Ann"); + assertThat(generatedNameOf(SimpleObject.class, new AnnImpl())) + .isEqualTo("org.weakref.jmx:type=SimpleObject,name=Ann"); } @Test public void testGeneratedNameOf5() { - assertEquals( - generatedNameOf(Inner.class), - "org.weakref.jmx:name=Inner"); + assertThat(generatedNameOf(Inner.class)) + .isEqualTo("org.weakref.jmx:name=Inner"); } @Test public void testGeneratedNameOfStringWithQuoting() { - assertEquals( - generatedNameOf(SimpleObject.class, "bar,baz"), - "org.weakref.jmx:type=SimpleObject,name=\"bar,baz\""); + assertThat(generatedNameOf(SimpleObject.class, "bar,baz")) + .isEqualTo("org.weakref.jmx:type=SimpleObject,name=\"bar,baz\""); } @ParameterizedTest @@ -80,12 +73,12 @@ public void testQuotesName(String name, boolean shouldQuote) String quotedName = objectName.getKeyProperty("name"); int index = 0; StringBuilder builder = new StringBuilder(); - assertEquals(quotedName.charAt(index++), '\"'); + assertThat(quotedName.charAt(index++)).isEqualTo('\"'); char c; while ((c = quotedName.charAt(index++)) != '\"') { if (c == '\\') { c = quotedName.charAt(index++); - assertTrue("*?n\\\"".indexOf(c) != -1, "valid character '" + c + "' after backslash"); + assertThat("*?n\\\"".indexOf(c) != -1).describedAs("valid character '" + c + "' after backslash").isTrue(); if (c == 'n') { builder.append('\n'); } @@ -97,11 +90,11 @@ public void testQuotesName(String name, boolean shouldQuote) builder.append(c); } } - assertEquals(index, quotedName.length()); - assertEquals(builder.toString(), name); + assertThat(index).isEqualTo(quotedName.length()); + assertThat(builder.toString()).isEqualTo(name); } else { - assertEquals(objectName.getKeyProperty("name"), name); + assertThat(objectName.getKeyProperty("name")).isEqualTo(name); } } diff --git a/src/test/java/org/weakref/jmx/TestTestingMBeanServer.java b/src/test/java/org/weakref/jmx/TestTestingMBeanServer.java index 7d2ac3d..ff270f6 100644 --- a/src/test/java/org/weakref/jmx/TestTestingMBeanServer.java +++ b/src/test/java/org/weakref/jmx/TestTestingMBeanServer.java @@ -12,8 +12,7 @@ import java.util.Set; import static java.util.Collections.emptySet; -import static org.weakref.jmx.Assert.assertEquals; -import static org.weakref.jmx.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestTestingMBeanServer { @@ -26,7 +25,7 @@ public void testUnsupportedQueryExp() server.queryNames(makeObjectName("test", Map.of("type", "Test")), Query.eq(Query.attr("a"), Query.value("a"))); } catch (Exception e) { - assertTrue(e instanceof UnsupportedOperationException); + assertThat(e instanceof UnsupportedOperationException).isTrue(); } } @@ -37,7 +36,7 @@ public void testNonMatchingQuery() TestingMBeanServer server = new TestingMBeanServer(); server.registerMBean(BEAN, makeObjectName("test", Map.of("type", "Other"))); - assertEquals(server.queryNames(makeObjectName("test", Map.of("type", "Test")), null), Set.of()); + assertThat(server.queryNames(makeObjectName("test", Map.of("type", "Test")), null)).isEqualTo(Set.of()); } @Test @@ -50,8 +49,8 @@ public void testMatchingWildcard() server.registerMBean(BEAN, makeObjectName("test3", Map.of("type", "Other"))); server.registerMBean(BEAN, makeObjectName("test4", Map.of("type", "Other"))); - assertEquals(server.queryNames(ObjectName.WILDCARD, null).size(), 4); - assertEquals(server.queryNames(ObjectName.WILDCARD, null), Set.of( + assertThat(server.queryNames(ObjectName.WILDCARD, null).size()).isEqualTo(4); + assertThat(server.queryNames(ObjectName.WILDCARD, null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other")), makeObjectName("test2", Map.of("type", "Other")), makeObjectName("test3", Map.of("type", "Other")), @@ -70,7 +69,7 @@ public void testMatchingSpecificDomain() server.registerMBean(BEAN, makeObjectName("test4", Map.of("type", "Other"))); server.registerMBean(BEAN, makeObjectName("test4", Map.of("type", "Other2"))); - assertEquals(server.queryNames(new ObjectName("test1:*"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:*"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other")), makeObjectName("test1", Map.of("type", "Other2")))); } @@ -87,13 +86,13 @@ public void testMatchingSpecificDomainAndProperty() server.registerMBean(BEAN, makeObjectName("test4", Map.of("type", "Other"))); server.registerMBean(BEAN, makeObjectName("test4", Map.of("type", "Other2"))); - assertEquals(server.queryNames(new ObjectName("test1:type=*"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:type=*"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other")), makeObjectName("test1", Map.of("type", "Other2")))); - assertEquals(server.queryNames( - new ObjectName("test1:type=Other2"), null), - Set.of(makeObjectName("test1", Map.of("type", "Other2")))); + assertThat(server.queryNames( + new ObjectName("test1:type=Other2"), null)) + .isEqualTo(Set.of(makeObjectName("test1", Map.of("type", "Other2")))); } @Test @@ -106,34 +105,34 @@ public void testMatchingByProperty() server.registerMBean(BEAN, makeObjectName("test1", Map.of("type", "Another"))); server.registerMBean(BEAN, makeObjectName("test1", Map.of("type", "Another2"))); - assertEquals(server.queryNames(new ObjectName("test1:type=*"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:type=*"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other")), makeObjectName("test1", Map.of("type", "Other2")), makeObjectName("test1", Map.of("type", "Another")), makeObjectName("test1", Map.of("type", "Another2")))); - assertEquals(server.queryNames(new ObjectName("test1:type=Other"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:type=Other"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other")))); - assertEquals(server.queryNames(new ObjectName("test1:type=Other*"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:type=Other*"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other")), makeObjectName("test1", Map.of("type", "Other2")))); - assertEquals(server.queryNames(new ObjectName("test1:type=Another*"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:type=Another*"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Another")), makeObjectName("test1", Map.of("type", "Another2")))); - assertEquals(server.queryNames(new ObjectName("test1:type=*ther*"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:type=*ther*"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other")), makeObjectName("test1", Map.of("type", "Other2")), makeObjectName("test1", Map.of("type", "Another")), makeObjectName("test1", Map.of("type", "Another2")))); - assertEquals(server.queryNames(new ObjectName("test1:type=*ther"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:type=*ther"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other")), makeObjectName("test1", Map.of("type", "Another")))); - assertEquals(server.queryNames(new ObjectName("test1:type=*ther?"), null), Set.of( + assertThat(server.queryNames(new ObjectName("test1:type=*ther?"), null)).isEqualTo(Set.of( makeObjectName("test1", Map.of("type", "Other2")), makeObjectName("test1", Map.of("type", "Another2")))); } diff --git a/src/test/java/org/weakref/jmx/TestUnexporter.java b/src/test/java/org/weakref/jmx/TestUnexporter.java index fc1230f..d164a6c 100644 --- a/src/test/java/org/weakref/jmx/TestUnexporter.java +++ b/src/test/java/org/weakref/jmx/TestUnexporter.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import static org.assertj.core.api.Assertions.assertThat; + import javax.management.InstanceNotFoundException; import javax.management.IntrospectionException; import javax.management.MBeanRegistrationException; @@ -42,15 +44,15 @@ public void setUp() exporter.export(name.getCanonicalName(), new TestBean()); } - Assert.assertNotNull(server); - Assert.assertNotNull(exporter); + assertThat(server).isNotNull(); + assertThat(exporter).isNotNull(); } @AfterEach public void tearDown() { - Assert.assertNotNull(server); - Assert.assertNotNull(exporter); + assertThat(server).isNotNull(); + assertThat(exporter).isNotNull(); for (ObjectName name : objectNames) { try { @@ -67,7 +69,7 @@ public void testUnexportOk() throws Exception { ObjectName name = objectNames.get(0); - Assert.assertEquals("Hello!", server.getAttribute(name, "Hello")); + assertThat(server.getAttribute(name, "Hello")).isEqualTo("Hello!"); exporter.unexport(name.getCanonicalName()); assertThatThrownBy(() -> server.getAttribute(name, "Hello")) .isInstanceOf(InstanceNotFoundException.class); @@ -78,14 +80,14 @@ public void testUnexportDouble() throws Throwable { ObjectName name = objectNames.get(0); - Assert.assertEquals("Hello!", server.getAttribute(name, "Hello")); + assertThat(server.getAttribute(name, "Hello")).isEqualTo("Hello!"); exporter.unexport(name.getCanonicalName()); try { exporter.unexport(name.getCanonicalName()); } catch (JmxException e) { - Assert.assertEquals(e.getReason(), JmxException.Reason.INSTANCE_NOT_FOUND); + assertThat(e.getReason()).isEqualTo(JmxException.Reason.INSTANCE_NOT_FOUND); } } @@ -98,7 +100,7 @@ public void testUnexportAll() for (ObjectName name : objectNames) { try { server.getMBeanInfo(name); - Assert.fail(format("failed to unexport %s", name.getCanonicalName())); + throw new AssertionError(format("failed to unexport %s", name.getCanonicalName())); } catch (InstanceNotFoundException e) { // success @@ -115,7 +117,7 @@ public void testUnexportAllIdempotent() for (ObjectName name : objectNames) { try { server.getMBeanInfo(name); - Assert.fail(format("failed to unexport %s", name.getCanonicalName())); + throw new AssertionError(format("failed to unexport %s", name.getCanonicalName())); } catch (InstanceNotFoundException e) { // success @@ -123,7 +125,7 @@ public void testUnexportAllIdempotent() } Map errors = exporter.unexportAllAndReportMissing(); - Assert.assertTrue(errors.isEmpty()); + assertThat(errors.isEmpty()).isTrue(); } @Test @@ -133,12 +135,12 @@ public void testUnexportAllIgnoresMissing() server.unregisterMBean(objectNames.get(0)); Map errors = exporter.unexportAllAndReportMissing(); - Assert.assertTrue(errors.isEmpty()); + assertThat(errors.isEmpty()).isTrue(); for (ObjectName name : objectNames) { try { server.getMBeanInfo(name); - Assert.fail(format("failed to unexport %s", name.getCanonicalName())); + throw new AssertionError(format("failed to unexport %s", name.getCanonicalName())); } catch (InstanceNotFoundException e) { // success diff --git a/src/test/java/org/weakref/jmx/guice/TestMBeanModule.java b/src/test/java/org/weakref/jmx/guice/TestMBeanModule.java index 0731b09..fc64191 100644 --- a/src/test/java/org/weakref/jmx/guice/TestMBeanModule.java +++ b/src/test/java/org/weakref/jmx/guice/TestMBeanModule.java @@ -22,7 +22,7 @@ import com.google.inject.Module; import com.google.inject.multibindings.Multibinder; import org.junit.jupiter.api.Test; -import org.weakref.jmx.Assert; +import static org.assertj.core.api.Assertions.assertThat; import org.weakref.jmx.MBeanExporter; import org.weakref.jmx.ObjectNameBuilder; import org.weakref.jmx.ObjectNameGenerator; @@ -66,7 +66,7 @@ protected void configure() }); MBeanServer server = injector.getInstance(MBeanServer.class); - Assert.assertNotNull(server.getMBeanInfo(name)); + assertThat(server.getMBeanInfo(name)).isNotNull(); } @Test @@ -91,7 +91,7 @@ protected void configure() MBeanServer server = injector.getInstance(MBeanServer.class); - Assert.assertNotNull(server.getMBeanInfo(name)); + assertThat(server.getMBeanInfo(name)).isNotNull(); server.unregisterMBean(name); } @@ -130,7 +130,7 @@ protected void configure() MBeanServer server = injector.getInstance(MBeanServer.class); - Assert.assertNotNull(server.getMBeanInfo(name)); + assertThat(server.getMBeanInfo(name)).isNotNull(); server.unregisterMBean(name); } @@ -169,7 +169,7 @@ protected void configure() MBeanServer server = injector.getInstance(MBeanServer.class); - Assert.assertNotNull(server.getMBeanInfo(name)); + assertThat(server.getMBeanInfo(name)).isNotNull(); server.unregisterMBean(name); } @@ -195,7 +195,7 @@ protected void configure() MBeanServer server = injector.getInstance(MBeanServer.class); - Assert.assertNotNull(server.getMBeanInfo(objectName)); + assertThat(server.getMBeanInfo(objectName)).isNotNull(); server.unregisterMBean(objectName); } @@ -226,8 +226,8 @@ protected void configure() MBeanServer server = injector.getInstance(MBeanServer.class); - Assert.assertNotNull(server.getMBeanInfo(objectName1)); - Assert.assertNotNull(server.getMBeanInfo(objectName2)); + assertThat(server.getMBeanInfo(objectName1)).isNotNull(); + assertThat(server.getMBeanInfo(objectName2)).isNotNull(); server.unregisterMBean(objectName1); server.unregisterMBean(objectName2); @@ -262,8 +262,8 @@ protected void configure() MBeanServer server = injector.getInstance(MBeanServer.class); - Assert.assertNotNull(server.getMBeanInfo(objectName1)); - Assert.assertNotNull(server.getMBeanInfo(objectName2)); + assertThat(server.getMBeanInfo(objectName1)).isNotNull(); + assertThat(server.getMBeanInfo(objectName2)).isNotNull(); server.unregisterMBean(objectName1); server.unregisterMBean(objectName2); @@ -333,8 +333,8 @@ protected void configure() MBeanServer server = injector.getInstance(MBeanServer.class); - Assert.assertNotNull(server.getMBeanInfo(name1)); - Assert.assertNotNull(server.getMBeanInfo(name2)); + assertThat(server.getMBeanInfo(name1)).isNotNull(); + assertThat(server.getMBeanInfo(name2)).isNotNull(); server.unregisterMBean(name1); server.unregisterMBean(name2);