You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/08/31 14:47:59 UTC
(commons-beanutils) branch master updated: Port some tests to JUnit 5
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/master by this push:
new 61143fe3 Port some tests to JUnit 5
61143fe3 is described below
commit 61143fe3052813dada1a0d580212630d01bfd1fc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 31 10:40:19 2024 -0400
Port some tests to JUnit 5
---
.../beanutils2/IndexedPropertyTestCase.java | 10 ++++-----
.../commons/beanutils2/bugs/Jira422TestCase.java | 6 +++---
.../commons/beanutils2/bugs/Jira422bTestCase.java | 2 +-
.../commons/beanutils2/bugs/Jira492TestCase.java | 6 +++---
.../commons/beanutils2/bugs/Jira493TestCase.java | 2 +-
.../commons/beanutils2/bugs/Jira509TestCase.java | 14 ++++++-------
.../converters/ColorConverterTestCase.java | 24 ++++++++++++----------
.../converters/DimensionConverterTestCase.java | 20 ++++++++++--------
.../converters/InetAddressConverterTestCase.java | 16 ++++++++-------
.../converters/LocaleConverterTestCase.java | 6 +++---
.../beanutils2/converters/MemoryTestCase.java | 2 +-
.../converters/PatternConverterTestCase.java | 6 +++---
.../converters/PointConverterTestCase.java | 6 +++---
.../converters/URLConverterTestCase.java | 6 +++---
.../memoryleaktests/MemoryLeakTestCase.java | 2 +-
15 files changed, 67 insertions(+), 61 deletions(-)
diff --git a/src/test/java/org/apache/commons/beanutils2/IndexedPropertyTestCase.java b/src/test/java/org/apache/commons/beanutils2/IndexedPropertyTestCase.java
index d8505103..cb4e0094 100644
--- a/src/test/java/org/apache/commons/beanutils2/IndexedPropertyTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/IndexedPropertyTestCase.java
@@ -27,9 +27,9 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils2.bugs.other.Jira492IndexedListsSupport;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* <p>
@@ -54,7 +54,7 @@ public class IndexedPropertyTestCase {
/**
* Sets up instance variables required by this test case.
*/
- @Before
+ @BeforeEach
public void setUp() {
// BeanUtils
@@ -90,7 +90,7 @@ public class IndexedPropertyTestCase {
/**
* Tear down instance variables required by this test case.
*/
- @After
+ @AfterEach
public void tearDown() {
bean = null;
}
diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira422TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira422TestCase.java
index eb2304d6..e5fbc89c 100644
--- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira422TestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira422TestCase.java
@@ -28,8 +28,8 @@ import java.util.List;
import org.apache.commons.beanutils2.PropertyUtils;
import org.junit.Assert;
import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
final class FirstChildBean extends RootBean {
}
@@ -49,7 +49,7 @@ public class Jira422TestCase {
*
* @see <a href="https://issues.apache.org/jira/browse/BEANUTILS-492">BEANUTILS-492</a>
*/
- @BeforeClass
+ @BeforeAll
public static void assumeSupportsIndexedLists() throws IntrospectionException {
final BeanInfo beanInfo = Introspector.getBeanInfo(RootBean.class);
for (final PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira422bTestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira422bTestCase.java
index bc992986..bd50f8ef 100644
--- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira422bTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira422bTestCase.java
@@ -19,7 +19,7 @@ package org.apache.commons.beanutils2.bugs;
import static org.junit.Assert.assertEquals;
import org.apache.commons.beanutils2.PropertyUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
final class FirstChildBeanB extends RootBeanB {
}
diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira492TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira492TestCase.java
index c305e819..4e43b132 100644
--- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira492TestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira492TestCase.java
@@ -29,8 +29,8 @@ import java.util.Map;
import org.apache.commons.beanutils2.BeanUtilsBean;
import org.apache.commons.beanutils2.PropertyUtilsBean;
import org.apache.commons.beanutils2.bugs.other.Jira492IndexedListsSupport.IndexedBean;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* This test verifies that although BEANUTILS-492 means {@link IndexedPropertyDescriptor}s are not returned for properties of type {@link List}, they can still
@@ -103,7 +103,7 @@ public class Jira492TestCase {
assertTrue("Did not retrieve list", someList instanceof List);
}
- @Before
+ @BeforeEach
public void makeBean() {
bean = new IndexedBean();
bean.setSomeList(Arrays.asList("item0", "item1"));
diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira493TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira493TestCase.java
index 3e262aa9..21091677 100644
--- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira493TestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira493TestCase.java
@@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
import org.apache.commons.beanutils2.BeanUtilsBean;
import org.apache.commons.beanutils2.LazyDynaBean;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test setting indexed properties on dynabeans
diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira509TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira509TestCase.java
index 481fb37b..3a5b07fd 100644
--- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira509TestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira509TestCase.java
@@ -32,15 +32,16 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.commons.beanutils2.WrapDynaClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
/**
* Tests Jira issue# BEANUTILS-509.
*
* The bug causes an infinite loop in WeakHashMap.get which was not accessed in a thread safe manner. This originates with WrapDynaClass.createDynaClass().
*/
-@Ignore("https://issues.apache.org/jira/browse/BEANUTILS-509.")
+@Disabled("https://issues.apache.org/jira/browse/BEANUTILS-509.")
public class Jira509TestCase {
protected int random(final int max) {
@@ -51,22 +52,22 @@ public class Jira509TestCase {
* The bug makes the {@link WrapDynaClass#createDynaClass} method run in an infinite loop and acquire locks. The test case adds a timeout. The test case may
* pass even without this fix because this is a rare scenario.
*/
- @Test(timeout = 60_000)
+ @Timeout(value = 60, unit = TimeUnit.SECONDS)
+ @Test
public void test_concurrent() throws InterruptedException {
final List<Class<?>> classList = Arrays.asList(Map.class, HashMap.class, Collections.class, Arrays.class, Collection.class, Set.class, ArrayList.class,
List.class, HashSet.class);
-
// All daemon threads.
final ExecutorService executor = Executors.newFixedThreadPool(100, r -> {
final Thread thread = new Thread(r);
thread.setDaemon(true);
return thread;
});
-
try {
// Loop _may_ hang without fix.
for (int i = 1; i < 10_000_000; i++) {
executor.submit(new Runnable() {
+
final Class<?> clazz = classList.get(random(classList.size()));
@Override
@@ -80,7 +81,6 @@ public class Jira509TestCase {
} finally {
executor.shutdown();
executor.awaitTermination(3500, TimeUnit.MILLISECONDS);
-
}
}
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTestCase.java
index a3773586..31aae3f0 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTestCase.java
@@ -18,12 +18,14 @@
*/
package org.apache.commons.beanutils2.converters;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.awt.Color;
import org.apache.commons.beanutils2.ConversionException;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests {@link ColorConverter}.
@@ -34,19 +36,19 @@ public class ColorConverterTestCase {
private ColorConverter converter;
- @Before
+ @BeforeEach
public void before() {
converter = new ColorConverter();
}
- @Test(expected = ConversionException.class)
+ @Test
public void testColorBlank() {
- converter.convert(Color.class, "#");
+ assertThrows(ConversionException.class, () -> converter.convert(Color.class, "#"));
}
- @Test(expected = ConversionException.class)
+ @Test
public void testColorInvalidLength() {
- converter.convert(Color.class, "#F");
+ assertThrows(ConversionException.class, () -> converter.convert(Color.class, "#F"));
}
@Test
@@ -149,13 +151,13 @@ public class ColorConverterTestCase {
Assert.assertEquals(expected, actual);
}
- @Test(expected = ConversionException.class)
+ @Test
public void testInvalidNumber3() {
- converter.convert(Color.class, "#FFZ");
+ assertThrows(ConversionException.class, () -> converter.convert(Color.class, "#FFZ"));
}
- @Test(expected = ConversionException.class)
+ @Test
public void testInvalidNumber4() {
- converter.convert(Color.class, "#FFFY");
+ assertThrows(ConversionException.class, () -> converter.convert(Color.class, "#FFFY"));
}
}
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/DimensionConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/DimensionConverterTestCase.java
index 619b5208..257c18b8 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/DimensionConverterTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/DimensionConverterTestCase.java
@@ -18,12 +18,14 @@
*/
package org.apache.commons.beanutils2.converters;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.awt.Dimension;
import org.apache.commons.beanutils2.ConversionException;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests {@link DimensionConverter}.
@@ -34,7 +36,7 @@ public class DimensionConverterTestCase {
private DimensionConverter converter;
- @Before
+ @BeforeEach
public void before() {
converter = new DimensionConverter();
}
@@ -55,18 +57,18 @@ public class DimensionConverterTestCase {
Assert.assertEquals(expected, actual);
}
- @Test(expected = ConversionException.class)
+ @Test
public void testInvalidDimensions() {
- converter.convert(Dimension.class, "512n512");
+ assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "512n512"));
}
- @Test(expected = ConversionException.class)
+ @Test
public void testInvalidNumberFormatException() {
- converter.convert(Dimension.class, "3000000000x100");
+ assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "3000000000x100"));
}
- @Test(expected = ConversionException.class)
+ @Test
public void testNegativeDimension() {
- converter.convert(Dimension.class, "-512x512");
+ assertThrows(ConversionException.class, () -> converter.convert(Dimension.class, "-512x512"));
}
}
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTestCase.java
index 4f1905c2..1f9ab4ec 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTestCase.java
@@ -18,13 +18,15 @@
*/
package org.apache.commons.beanutils2.converters;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.apache.commons.beanutils2.ConversionException;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests {@link InetAddressConverter}.
@@ -35,7 +37,7 @@ public class InetAddressConverterTestCase {
private InetAddressConverter converter;
- @Before
+ @BeforeEach
public void before() {
converter = new InetAddressConverter();
}
@@ -64,13 +66,13 @@ public class InetAddressConverterTestCase {
Assert.assertEquals(expected, actual);
}
- @Test(expected = ConversionException.class)
+ @Test
public void testInvalidIp() {
- converter.convert(InetAddress.class, "512.512.512.512");
+ assertThrows(ConversionException.class, () -> converter.convert(InetAddress.class, "512.512.512.512"));
}
- @Test(expected = ConversionException.class)
+ @Test
public void testText() {
- converter.convert(InetAddress.class, "Hello, world!");
+ assertThrows(ConversionException.class, () -> converter.convert(InetAddress.class, "Hello, world!"));
}
}
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTestCase.java
index bc423421..92724bcf 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTestCase.java
@@ -21,8 +21,8 @@ package org.apache.commons.beanutils2.converters;
import java.util.Locale;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests {@link LocaleConverter}.
@@ -33,7 +33,7 @@ public class LocaleConverterTestCase {
private LocaleConverter converter;
- @Before
+ @BeforeEach
public void before() {
converter = new LocaleConverter();
}
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/MemoryTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/MemoryTestCase.java
index 32e64afa..ffa405ee 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/MemoryTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/MemoryTestCase.java
@@ -27,7 +27,7 @@ import java.lang.ref.WeakReference;
import org.apache.commons.beanutils2.ConvertUtils;
import org.apache.commons.beanutils2.Converter;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* This class provides a number of unit tests related to class loaders and garbage collection, particularly in j2ee-like situations.
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/PatternConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/PatternConverterTestCase.java
index 36780441..793345c1 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/PatternConverterTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/PatternConverterTestCase.java
@@ -21,8 +21,8 @@ package org.apache.commons.beanutils2.converters;
import java.util.regex.Pattern;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests {@link PatternConverter}.
@@ -33,7 +33,7 @@ public class PatternConverterTestCase {
private PatternConverter converter;
- @Before
+ @BeforeEach
public void before() {
converter = new PatternConverter();
}
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/PointConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/PointConverterTestCase.java
index 33d883fd..4bcc6860 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/PointConverterTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/PointConverterTestCase.java
@@ -21,8 +21,8 @@ package org.apache.commons.beanutils2.converters;
import java.awt.Point;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Tests {@link PointConverter}.
@@ -33,7 +33,7 @@ public class PointConverterTestCase {
private PointConverter converter;
- @Before
+ @BeforeEach
public void before() {
converter = new PointConverter();
}
diff --git a/src/test/java/org/apache/commons/beanutils2/converters/URLConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/URLConverterTestCase.java
index 0e06784b..131ee34c 100644
--- a/src/test/java/org/apache/commons/beanutils2/converters/URLConverterTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/converters/URLConverterTestCase.java
@@ -21,8 +21,8 @@ import static org.junit.Assert.assertEquals;
import java.net.URL;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test Case for the URLConverter class.
@@ -31,7 +31,7 @@ public class URLConverterTestCase {
private URLConverter converter;
- @Before
+ @BeforeEach
public void before() {
converter = new URLConverter();
}
diff --git a/src/test/java/org/apache/commons/beanutils2/memoryleaktests/MemoryLeakTestCase.java b/src/test/java/org/apache/commons/beanutils2/memoryleaktests/MemoryLeakTestCase.java
index 243f6dfc..9b3c28a1 100644
--- a/src/test/java/org/apache/commons/beanutils2/memoryleaktests/MemoryLeakTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/memoryleaktests/MemoryLeakTestCase.java
@@ -41,7 +41,7 @@ import org.apache.commons.beanutils2.locale.LocaleBeanUtilsBean;
import org.apache.commons.beanutils2.locale.LocaleConvertUtils;
import org.apache.commons.beanutils2.locale.converters.IntegerLocaleConverter;
import org.junit.Assume;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests BeanUtils memory leaks.