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..ba54ce0 100644
--- a/src/test/java/org/weakref/jmx/AbstractMbeanTest.java
+++ b/src/test/java/org/weakref/jmx/AbstractMbeanTest.java
@@ -1,23 +1,23 @@
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.assertj.core.api.Assertions.assertThat;
+@TestInstance(PER_CLASS)
public abstract class AbstractMbeanTest
{
protected List objects;
@@ -36,7 +36,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
{
@@ -48,15 +49,16 @@ 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();
}
}
- @Test(dataProvider = "fixtures")
+ @ParameterizedTest
+ @MethodSource("getFixtures")
public void testSetterAttributeInfo(String attribute, boolean isIs, Object[] values, Class> clazz)
throws Exception
{
@@ -69,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();
}
}
@@ -85,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();
}
}
@@ -98,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();
}
}
@@ -114,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();
}
}
@@ -132,7 +134,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
{
@@ -147,18 +150,19 @@ 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());
}
}
- @Test(dataProvider = "fixtures")
+ @ParameterizedTest
+ @MethodSource("getFixtures")
public void testGet(String attribute, boolean isIs, Object[] values, Class> clazz)
throws Exception
{
@@ -171,12 +175,13 @@ 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);
}
}
}
- @Test(dataProvider = "fixtures")
+ @ParameterizedTest
+ @MethodSource("getFixtures")
public void testSet(String attribute, boolean isIs, Object[] values, Class> clazz)
throws Exception
{
@@ -190,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);
}
}
}
@@ -205,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);
}
}
@@ -223,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
@@ -238,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
@@ -255,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);
}
}
@@ -274,31 +279,31 @@ 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();
}
}
- @Test(dataProvider = "fixtures")
+ @ParameterizedTest
+ @MethodSource("getFixtures")
public void testOperation(String attribute, boolean isIs, Object[] values, Class> clazz)
throws Exception
{
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);
}
}
}
- @DataProvider(name = "fixtures")
- Object[][] getFixtures()
+ static Object[][] getFixtures()
{
return new Object[][] {
diff --git a/src/test/java/org/weakref/jmx/TestExporter.java b/src/test/java/org/weakref/jmx/TestExporter.java
index 46eda2c..62a07ec 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,7 @@
import java.util.ArrayList;
import java.util.Map;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.weakref.jmx.Util.getUniqueObjectName;
public class TestExporter extends AbstractMbeanTest
@@ -93,7 +93,7 @@ protected Object invoke(NamedObject namedObject, Object value, String operationN
new String[] { Object.class.getName() });
}
- @BeforeMethod
+ @BeforeEach
void setup()
{
server = new TestingMBeanServer();
@@ -119,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);
}
}
}
@@ -143,8 +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 90344c9..9965972 100644
--- a/src/test/java/org/weakref/jmx/TestExports.java
+++ b/src/test/java/org/weakref/jmx/TestExports.java
@@ -1,15 +1,19 @@
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.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
+
+@TestInstance(PER_CLASS)
public class TestExports
{
private MBeanServer server;
@@ -18,28 +22,28 @@ public class TestExports
private ObjectName objectName;
private String name;
- @BeforeMethod
+ @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();
}
- @AfterMethod
+ @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);
@@ -54,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
@@ -62,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 0387a35..808d86c 100644
--- a/src/test/java/org/weakref/jmx/TestInheritanceBase.java
+++ b/src/test/java/org/weakref/jmx/TestInheritanceBase.java
@@ -15,11 +15,12 @@
*/
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;
+import static org.assertj.core.api.Assertions.assertThat;
public abstract class TestInheritanceBase
{
@@ -56,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 5263bf9..725a414 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.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 07d6a96..315ec00 100755
--- a/src/test/java/org/weakref/jmx/TestObjectNames.java
+++ b/src/test/java/org/weakref/jmx/TestObjectNames.java
@@ -1,16 +1,17 @@
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.assertj.core.api.Assertions.assertThat;
import static org.weakref.jmx.ObjectNames.generatedNameOf;
public class TestObjectNames {
@@ -28,47 +29,42 @@ 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\"");
}
- @Test(dataProvider = "names")
+ @ParameterizedTest
+ @MethodSource("getNames")
public void testQuotesName(String name, boolean shouldQuote)
throws MalformedObjectNameException
{
@@ -77,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');
}
@@ -94,16 +90,15 @@ 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);
}
}
- @DataProvider(name = "names")
- public Object[][] getNames()
+ public static Object[][] getNames()
{
ArrayList