This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
The following commit(s) were added to refs/heads/1.X by this push:
new 67e8ade9 Isolate locale test state with a JUnit Jupiter extension
(#451)
67e8ade9 is described below
commit 67e8ade97f90ca551c4ff71fb66604ef81ffc23d
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Nov 30 16:42:20 2026 -0500
Isolate locale test state with a JUnit Jupiter extension (#451)
Add @IsolatedLocaleBeanUtils to capture and restore the default
locale, locale categories, and cached LocaleBeanUtilsBean instance.
This prevents locale state from leaking between tests when Surefire
reuses forks.
Migrate the affected tests to JUnit Jupiter and add 10 extension
regression tests covering restoration after success, failure,
abortion, and setup failure.
Remove the empty testNothing method and its 11 executions. All
substantive existing tests remain.
---
pom.xml | 8 +-
.../beanutils/locale/IsolatedLocaleBeanUtils.java | 53 ++++
.../beanutils/locale/LocaleBeanUtilsExtension.java | 139 +++++++++
.../locale/LocaleBeanUtilsExtensionTest.java | 330 +++++++++++++++++++++
.../beanutils/locale/LocaleBeanificationTest.java | 118 ++++----
.../locale/converters/BaseLocaleConverterTest.java | 71 +----
.../converters/BigDecimalLocaleConverterTest.java | 29 +-
.../converters/BigIntegerLocaleConverterTest.java | 31 +-
.../locale/converters/ByteLocaleConverterTest.java | 28 +-
.../locale/converters/DateLocaleConverterTest.java | 50 ++--
.../converters/DecimalLocaleConverterTest.java | 11 +-
.../converters/DoubleLocaleConverterTest.java | 30 +-
.../converters/FloatLocaleConverterTest.java | 40 +--
.../converters/IntegerLocaleConverterTest.java | 30 +-
.../locale/converters/LongLocaleConverterTest.java | 29 +-
.../converters/ShortLocaleConverterTest.java | 28 +-
16 files changed, 757 insertions(+), 268 deletions(-)
diff --git a/pom.xml b/pom.xml
index 27317151..cbe871e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,6 +113,11 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-testkit</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
@@ -126,7 +131,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <forkMode>pertest</forkMode>
+ <forkCount>1</forkCount>
+ <reuseForks>true</reuseForks>
<!-- limit memory size see BEANUTILS-291 -->
<argLine>${surefire.argLine}</argLine>
<includes>
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/IsolatedLocaleBeanUtils.java
b/src/test/java/org/apache/commons/beanutils/locale/IsolatedLocaleBeanUtils.java
new file mode 100644
index 00000000..dc4b6ba8
--- /dev/null
+++
b/src/test/java/org/apache/commons/beanutils/locale/IsolatedLocaleBeanUtils.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.beanutils.locale;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.parallel.ResourceLock;
+import org.junit.jupiter.api.parallel.Resources;
+
+/**
+ * Gives each test a fresh locale BeanUtils instance and restores the original
instance and default locales afterward.
+ *
+ * <p>
+ * An optional language tag changes the default locale before the fresh
instance is created. Method annotations override class annotations.
+ * Participating Jupiter tests lock both the JVM locale and the BeanUtils
singleton; other tests that access these resources must use the same locks
+ * if parallel execution is enabled.
+ * </p>
+ */
+@Inherited
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
+@ExtendWith(LocaleBeanUtilsExtension.class)
+@ResourceLock(Resources.LOCALE)
+@ResourceLock("org.apache.commons.beanutils.locale.LocaleBeanUtilsBean")
+public @interface IsolatedLocaleBeanUtils {
+
+ /**
+ * Gets the language tag to apply for the test, or an empty string to keep
the current default locale.
+ *
+ * @return The language tag, or an empty string.
+ */
+ String value() default "";
+}
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsExtension.java
b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsExtension.java
new file mode 100644
index 00000000..aeca893f
--- /dev/null
+++
b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsExtension.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.beanutils.locale;
+
+import java.util.IllformedLocaleException;
+import java.util.Locale;
+
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionConfigurationException;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.platform.commons.support.AnnotationSupport;
+
+/**
+ * Isolates locale BeanUtils state for tests annotated with {@link
IsolatedLocaleBeanUtils}.
+ */
+public final class LocaleBeanUtilsExtension implements BeforeEachCallback,
AfterEachCallback {
+
+ /**
+ * Captures state before any locale change, including a lazily initialized
singleton.
+ */
+ private static final class State implements AutoCloseable {
+
+ /**
+ * The original default locale.
+ */
+ private final Locale locale = Locale.getDefault();
+
+ /**
+ * The original display locale.
+ */
+ private final Locale displayLocale =
Locale.getDefault(Locale.Category.DISPLAY);
+
+ /**
+ * The original formatting locale.
+ */
+ private final Locale formatLocale =
Locale.getDefault(Locale.Category.FORMAT);
+
+ /**
+ * The class loader whose singleton is being isolated.
+ */
+ private final ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
+
+ /**
+ * The original singleton, captured before the locale changes.
+ */
+ private LocaleBeanUtilsBean bean =
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance();
+
+ /**
+ * Whether restoration has completed.
+ */
+ private boolean closed;
+
+ @Override
+ public void close() {
+ if (closed) {
+ return;
+ }
+ final Thread thread = Thread.currentThread();
+ final ClassLoader currentClassLoader =
thread.getContextClassLoader();
+ try {
+ thread.setContextClassLoader(classLoader);
+ try {
+ Locale.setDefault(locale);
+ Locale.setDefault(Locale.Category.DISPLAY, displayLocale);
+ Locale.setDefault(Locale.Category.FORMAT, formatLocale);
+ } finally {
+ LocaleBeanUtilsBean.setInstance(bean);
+ }
+ } finally {
+ thread.setContextClassLoader(currentClassLoader);
+ }
+ closed = true;
+ bean = null;
+ }
+ }
+
+ /**
+ * The namespace for snapshots scoped to individual test invocations.
+ */
+ private static final ExtensionContext.Namespace NAMESPACE =
ExtensionContext.Namespace.create(LocaleBeanUtilsExtension.class);
+
+ /**
+ * Finds the nearest method, class, inherited, or enclosing annotation.
+ *
+ * @param context The test context.
+ * @return The isolation configuration.
+ * @throws ExtensionConfigurationException If no configuration is present.
+ */
+ private static IsolatedLocaleBeanUtils configuration(final
ExtensionContext context) {
+ for (ExtensionContext current = context; current != null; current =
current.getParent().orElse(null)) {
+ final IsolatedLocaleBeanUtils annotation =
AnnotationSupport.findAnnotation(current.getElement(),
IsolatedLocaleBeanUtils.class).orElse(null);
+ if (annotation != null) {
+ return annotation;
+ }
+ }
+ throw new ExtensionConfigurationException("LocaleBeanUtilsExtension
requires @IsolatedLocaleBeanUtils");
+ }
+
+ @Override
+ public void afterEach(final ExtensionContext context) {
+ final State state = context.getStore(NAMESPACE).get(State.class,
State.class);
+ if (state != null) {
+ state.close();
+ }
+ }
+
+ @Override
+ public void beforeEach(final ExtensionContext context) {
+ final String languageTag = configuration(context).value();
+ final Locale locale;
+ try {
+ locale = languageTag.isEmpty() ? null : new
Locale.Builder().setLanguageTag(languageTag).build();
+ } catch (final IllformedLocaleException e) {
+ throw new ExtensionConfigurationException("Invalid locale language
tag: " + languageTag, e);
+ }
+ // Store first so context closure can restore state even if setup
fails.
+ context.getStore(NAMESPACE).put(State.class, new State());
+ if (locale != null) {
+ Locale.setDefault(locale);
+ }
+ LocaleBeanUtilsBean.setInstance(new LocaleBeanUtilsBean());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsExtensionTest.java
b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsExtensionTest.java
new file mode 100644
index 00000000..ffb7ab7d
--- /dev/null
+++
b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanUtilsExtensionTest.java
@@ -0,0 +1,330 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.beanutils.locale;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import static
org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod;
+
+import java.util.Locale;
+
+import org.apache.commons.beanutils.locale.converters.IntegerLocaleConverter;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.ResourceLock;
+import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.testkit.engine.EngineExecutionResults;
+import org.junit.platform.testkit.engine.EngineTestKit;
+import org.junitpioneer.jupiter.DefaultLocale;
+
+/**
+ * Exercises isolation through Jupiter callbacks, including failing and
aborted test executions.
+ */
+@DefaultLocale("en")
+@ResourceLock("org.apache.commons.beanutils.locale.LocaleBeanUtilsBean")
+class LocaleBeanUtilsExtensionTest {
+
+ /**
+ * Fixtures selected explicitly by the test kit, rather than discovered as
nested tests.
+ */
+ @IsolatedLocaleBeanUtils("en-US")
+ static class UsFixture {
+
+ /**
+ * Checks that isolation takes effect before user setup.
+ */
+ @BeforeEach
+ void beforeEach() {
+ assertFreshState(Locale.US);
+ }
+
+ /**
+ * Aborts after the extension has installed fresh state.
+ */
+ @Test
+ void aborts() {
+ assumeTrue(false, "expected test abort");
+ }
+
+ /**
+ * Fails after the extension has installed fresh state.
+ */
+ @Test
+ void fails() {
+ fail("expected test failure");
+ }
+
+ /**
+ * Changes both resources to exercise restoration of the original
objects.
+ */
+ @Test
+ void succeeds() {
+ Locale.setDefault(Locale.GERMANY);
+ LocaleBeanUtilsBean.setInstance(new LocaleBeanUtilsBean());
+ }
+ }
+
+ /**
+ * Inherits both the configuration and the test lifecycle.
+ */
+ static class InheritedFixture extends UsFixture {
+ }
+
+ /**
+ * Fails in user setup, before the test method runs.
+ */
+ @IsolatedLocaleBeanUtils("en-US")
+ static class SetupFailureFixture {
+
+ /**
+ * Fails after verifying that the extension ran before setup.
+ */
+ @BeforeEach
+ void beforeEach() {
+ assertFreshState(Locale.US);
+ throw new IllegalStateException("expected setup failure");
+ }
+
+ /**
+ * Must not be reached when setup fails.
+ */
+ @Test
+ void test() {
+ fail("test body should not run");
+ }
+ }
+
+ /**
+ * Uses the ambient locale without applying an override.
+ */
+ @IsolatedLocaleBeanUtils
+ static class AmbientFixture {
+
+ /**
+ * Checks the fresh singleton's locale against the unchanged JVM
locale.
+ */
+ @Test
+ void test() {
+ assertFreshState(Locale.ENGLISH);
+ }
+ }
+
+ /**
+ * Overrides the inherited class configuration on a method.
+ */
+ @IsolatedLocaleBeanUtils("en-US")
+ static class MethodOverrideFixture {
+
+ /**
+ * Uses the method's locale.
+ */
+ @Test
+ @IsolatedLocaleBeanUtils("de-DE")
+ void test() {
+ assertFreshState(Locale.GERMANY);
+ }
+ }
+
+ /**
+ * Rejects a malformed language tag before changing any state.
+ */
+ @IsolatedLocaleBeanUtils("invalid_tag")
+ static class InvalidConfigurationFixture {
+
+ /**
+ * Must not be reached when configuration is invalid.
+ */
+ @Test
+ void test() {
+ fail("test body should not run");
+ }
+ }
+
+ /**
+ * Checks that a fresh singleton uses the configured locale and default
settings.
+ *
+ * @param expectedLocale The expected locale.
+ */
+ private static void assertFreshState(final Locale expectedLocale) {
+ assertEquals(expectedLocale, Locale.getDefault());
+ final LocaleBeanUtilsBean bean =
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance();
+ assertEquals(expectedLocale, bean.getDefaultLocale());
+ assertFalse(bean.getLocaleConvertUtils().getApplyLocalized());
+ }
+
+ /**
+ * Runs a fixture with the actual Jupiter engine.
+ *
+ * @param fixture The fixture class.
+ * @param method The method to execute.
+ * @return The execution results.
+ */
+ private static EngineExecutionResults execute(final Class<?> fixture,
final String method) {
+ return EngineTestKit.engine("junit-jupiter")
+ .selectors(selectMethod(fixture, method))
+
.configurationParameter("junit.jupiter.execution.parallel.enabled", "false")
+ .execute();
+ }
+
+ /**
+ * Verifies that failure comes from the intended lifecycle stage.
+ *
+ * @param results The fixture execution results.
+ * @param message The expected failure message.
+ */
+ private static void assertFailure(final EngineExecutionResults results,
final String message) {
+ results.testEvents().assertStatistics(statistics ->
statistics.started(1).failed(1));
+ final TestExecutionResult result =
results.testEvents().failed().list().get(0).getRequiredPayload(TestExecutionResult.class);
+ assertEquals(message, result.getThrowable().get().getMessage());
+ }
+
+ /**
+ * Verifies exact restoration of the original singleton, custom
converters, and all default locale categories.
+ *
+ * @param fixture The fixture class.
+ * @param method The method to execute.
+ * @return The execution results.
+ */
+ private static EngineExecutionResults verifyRestoration(final Class<?>
fixture, final String method) {
+ final Locale originalLocale = Locale.getDefault();
+ final Locale originalDisplayLocale =
Locale.getDefault(Locale.Category.DISPLAY);
+ final Locale originalFormatLocale =
Locale.getDefault(Locale.Category.FORMAT);
+ final LocaleBeanUtilsBean originalBean =
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance();
+ final LocaleBeanUtilsBean savedBean = new LocaleBeanUtilsBean();
+ final LocaleConverter converter = new
IntegerLocaleConverter(Locale.ITALY);
+ savedBean.getLocaleConvertUtils().setDefaultLocale(Locale.ITALY);
+ savedBean.getLocaleConvertUtils().setApplyLocalized(true);
+ savedBean.getLocaleConvertUtils().register(converter, Integer.class,
Locale.ITALY);
+ try {
+ LocaleBeanUtilsBean.setInstance(savedBean);
+ Locale.setDefault(Locale.Category.DISPLAY, Locale.JAPAN);
+ Locale.setDefault(Locale.Category.FORMAT, Locale.FRANCE);
+ final EngineExecutionResults results = execute(fixture, method);
+ // These checks run after both afterEach and store closure, so
cleanup must be idempotent.
+ assertEquals(originalLocale, Locale.getDefault());
+ assertEquals(Locale.JAPAN,
Locale.getDefault(Locale.Category.DISPLAY));
+ assertEquals(Locale.FRANCE,
Locale.getDefault(Locale.Category.FORMAT));
+ assertSame(savedBean,
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance());
+ assertEquals(Locale.ITALY, savedBean.getDefaultLocale());
+ assertSame(converter,
savedBean.getLocaleConvertUtils().lookup(Integer.class, Locale.ITALY));
+ assertTrue(savedBean.getLocaleConvertUtils().getApplyLocalized());
+ return results;
+ } finally {
+ Locale.setDefault(originalLocale);
+ Locale.setDefault(Locale.Category.DISPLAY, originalDisplayLocale);
+ Locale.setDefault(Locale.Category.FORMAT, originalFormatLocale);
+ LocaleBeanUtilsBean.setInstance(originalBean);
+ }
+ }
+
+ /**
+ * Preserves the ambient locale when no override is requested.
+ */
+ @Test
+ void testAmbientLocale() {
+ verifyRestoration(AmbientFixture.class,
"test").testEvents().assertStatistics(statistics ->
statistics.started(1).succeeded(1));
+ }
+
+ /**
+ * Leaves state untouched when the annotation is invalid.
+ */
+ @Test
+ void testInvalidConfiguration() {
+ assertFailure(verifyRestoration(InvalidConfigurationFixture.class,
"test"), "Invalid locale language tag: invalid_tag");
+ }
+
+ /**
+ * Uses method configuration in preference to class configuration.
+ */
+ @Test
+ void testMethodOverride() {
+ verifyRestoration(MethodOverrideFixture.class,
"test").testEvents().assertStatistics(statistics ->
statistics.started(1).succeeded(1));
+ }
+
+ /**
+ * Restores state after an aborted test.
+ */
+ @Test
+ void testRestoreAfterAbort() {
+ verifyRestoration(UsFixture.class,
"aborts").testEvents().assertStatistics(statistics ->
statistics.started(1).aborted(1));
+ }
+
+ /**
+ * Restores state after an assertion failure.
+ */
+ @Test
+ void testRestoreAfterFailure() {
+ assertFailure(verifyRestoration(UsFixture.class, "fails"), "expected
test failure");
+ }
+
+ /**
+ * Restores state after user setup fails.
+ */
+ @Test
+ void testRestoreAfterSetupFailure() {
+ assertFailure(verifyRestoration(SetupFailureFixture.class, "test"),
"expected setup failure");
+ }
+
+ /**
+ * Restores English state after a successful test changes both resources.
+ */
+ @Test
+ void testRestoreEnglishLocale() {
+ verifyRestoration(UsFixture.class,
"succeeds").testEvents().assertStatistics(statistics ->
statistics.started(1).succeeded(1));
+ }
+
+ /**
+ * Restores German state and honors configuration inherited from a
superclass.
+ */
+ @Test
+ @DefaultLocale("de-DE")
+ void testRestoreGermanLocale() {
+ verifyRestoration(InheritedFixture.class,
"succeeds").testEvents().assertStatistics(statistics ->
statistics.started(1).succeeded(1));
+ }
+
+ /**
+ * Restores state when the requested locale already matches the ambient
locale.
+ */
+ @Test
+ @DefaultLocale("en-US")
+ void testRestoreUsLocale() {
+ verifyRestoration(UsFixture.class,
"succeeds").testEvents().assertStatistics(statistics ->
statistics.started(1).succeeded(1));
+ }
+
+ /**
+ * Captures a previously uninitialized singleton before applying the test
locale.
+ */
+ @Test
+ @DefaultLocale("de-DE")
+ void testUninitializedSingleton() {
+ final Thread thread = Thread.currentThread();
+ final ClassLoader originalClassLoader = thread.getContextClassLoader();
+ try {
+ thread.setContextClassLoader(new ClassLoader(originalClassLoader)
{ });
+ execute(UsFixture.class,
"succeeds").testEvents().assertStatistics(statistics ->
statistics.started(1).succeeded(1));
+ assertEquals(Locale.GERMANY, Locale.getDefault());
+ assertEquals(Locale.GERMANY,
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getDefaultLocale());
+ } finally {
+ thread.setContextClassLoader(originalClassLoader);
+ }
+ }
+}
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTest.java
b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTest.java
index 32aea9d9..94200f80 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTest.java
@@ -17,6 +17,12 @@
package org.apache.commons.beanutils.locale;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.Locale;
@@ -30,8 +36,7 @@ import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.PrimitiveBean;
import org.apache.commons.beanutils.locale.converters.LongLocaleConverter;
import org.apache.commons.logging.LogFactory;
-
-import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
/**
* <p>
@@ -41,7 +46,8 @@ import junit.framework.TestCase;
*
*/
-public class LocaleBeanificationTest extends TestCase {
+@IsolatedLocaleBeanUtils
+public class LocaleBeanificationTest {
class Signal {
private Exception e;
@@ -101,34 +107,8 @@ public class LocaleBeanificationTest extends TestCase {
/** Maximum number of iterations before our test fails */
public static final int MAX_GC_ITERATIONS = 50;
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public LocaleBeanificationTest(final String name) {
- super(name);
- }
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() {
-
- LocaleConvertUtils.deregister();
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- // No action required
- }
-
/** Tests whether different threads can set beanutils instances correctly
*/
+ @Test
public void testBeanUtilsBeanSetInstance() throws Exception {
class SetInstanceTesterThread extends Thread {
@@ -164,17 +144,18 @@ public class LocaleBeanificationTest extends TestCase {
thread.setContextClassLoader(new TestClassLoader());
LocaleBeanUtilsBean.setInstance(beanOne);
- assertEquals("Start thread gets right instance", beanOne,
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance());
+ assertEquals(beanOne,
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance(), "Start thread gets right
instance");
thread.start();
thread.join();
- assertEquals("Signal not set by test thread", 21, signal.getSignal());
- assertEquals("Second thread preserves value", beanOne,
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance());
- assertEquals("Second thread gets value it set", beanTwo,
signal.getBean());
+ assertEquals(21, signal.getSignal(), "Signal not set by test thread");
+ assertEquals(beanOne,
LocaleBeanUtilsBean.getLocaleBeanUtilsInstance(), "Second thread preserves
value");
+ assertEquals(beanTwo, signal.getBean(), "Second thread gets value it
set");
}
/** Tests whether calls are independent for different classloaders */
+ @Test
public void testContextClassloaderIndependence() throws Exception {
class TestIndependenceThread extends Thread {
@@ -214,8 +195,8 @@ public class LocaleBeanificationTest extends TestCase {
}
final PrimitiveBean bean = new PrimitiveBean();
- LocaleBeanUtils.setProperty(bean, "int", new Integer(1));
- assertEquals("Wrong property value (1)", 1, bean.getInt());
+ LocaleBeanUtils.setProperty(bean, "int", Integer.valueOf(1));
+ assertEquals(1, bean.getInt(), "Wrong property value (1)");
LocaleConvertUtils.register(new LocaleConverter() {
@Override
@@ -228,7 +209,7 @@ public class LocaleBeanificationTest extends TestCase {
}
}, Integer.TYPE, Locale.getDefault());
LocaleBeanUtils.setProperty(bean, "int", "1");
- assertEquals("Wrong property value(2)", 5, bean.getInt());
+ assertEquals(5, bean.getInt(), "Wrong property value(2)");
final Signal signal = new Signal();
signal.setSignal(1);
@@ -238,9 +219,9 @@ public class LocaleBeanificationTest extends TestCase {
thread.start();
thread.join();
- assertNull("Exception thrown by test thread:" + signal.getException(),
signal.getException());
- assertEquals("Signal not set by test thread", 3, signal.getSignal());
- assertEquals("Wrong property value(3)", 9, bean.getInt());
+ assertNull(signal.getException(), "Exception thrown by test thread:" +
signal.getException());
+ assertEquals(3, signal.getSignal(), "Signal not set by test thread");
+ assertEquals(9, bean.getInt(), "Wrong property value(3)");
}
@@ -248,6 +229,7 @@ public class LocaleBeanificationTest extends TestCase {
* Tests whether difference instances are loaded by different
* context classloaders.
*/
+ @Test
public void testContextClassLoaderLocal() throws Exception {
class CCLLTesterThread extends Thread {
@@ -262,7 +244,7 @@ public class LocaleBeanificationTest extends TestCase {
@Override
public void run() {
- ccll.set(new Integer(1789));
+ ccll.set(Integer.valueOf(1789));
signal.setSignal(2);
signal.setMarkerObject(ccll.get());
}
@@ -275,7 +257,7 @@ public class LocaleBeanificationTest extends TestCase {
final ContextClassLoaderLocal<Integer> ccll = new
ContextClassLoaderLocal<>();
ccll.set(1776);
- assertEquals("Start thread sets value", new Integer(1776), ccll.get());
+ assertEquals(Integer.valueOf(1776), ccll.get(), "Start thread sets
value");
final Signal signal = new Signal();
signal.setSignal(1);
@@ -286,25 +268,27 @@ public class LocaleBeanificationTest extends TestCase {
thread.start();
thread.join();
- assertEquals("Signal not set by test thread", 2, signal.getSignal());
- assertEquals("Second thread preserves value", new Integer(1776),
ccll.get());
- assertEquals("Second thread gets value it set", new Integer(1789),
signal.getMarkerObject());
+ assertEquals(2, signal.getSignal(), "Signal not set by test thread");
+ assertEquals(Integer.valueOf(1776), ccll.get(), "Second thread
preserves value");
+ assertEquals(Integer.valueOf(1789), signal.getMarkerObject(), "Second
thread gets value it set");
}
/** Tests whether the unset method works*/
+ @Test
public void testContextClassLoaderUnset() throws Exception {
final LocaleBeanUtilsBean beanOne = new LocaleBeanUtilsBean();
final ContextClassLoaderLocal<LocaleBeanUtilsBean> ccll = new
ContextClassLoaderLocal<>();
ccll.set(beanOne);
- assertEquals("Start thread gets right instance", beanOne, ccll.get());
+ assertEquals(beanOne, ccll.get(), "Start thread gets right instance");
ccll.unset();
- assertTrue("Unset works", !beanOne.equals(ccll.get()));
+ assertTrue(!beanOne.equals(ccll.get()), "Unset works");
}
/**
* Tests whether difference instances are loaded by different
* context classloaders.
*/
+ @Test
public void testGetByContextClassLoader() throws Exception {
class GetBeanUtilsBeanThread extends Thread {
@@ -337,24 +321,21 @@ public class LocaleBeanificationTest extends TestCase {
thread.start();
thread.join();
- assertEquals("Signal not set by test thread", 2, signal.getSignal());
- assertTrue(
- "Different LocaleBeanUtilsBean instances per context
classloader",
- BeanUtilsBean.getInstance() != signal.getBean());
- assertTrue(
- "Different LocaleConvertUtilsBean instances per context
classloader",
- LocaleConvertUtilsBean.getInstance() !=
signal.getConvertUtils());
+ assertEquals(2, signal.getSignal(), "Signal not set by test thread");
+ assertTrue(BeanUtilsBean.getInstance() != signal.getBean(), "Different
LocaleBeanUtilsBean instances per context classloader");
+ assertTrue(LocaleConvertUtilsBean.getInstance() !=
signal.getConvertUtils(), "Different LocaleConvertUtilsBean instances per
context classloader");
}
/**
* Test registering a locale-aware converter with the standard
ConvertUtils.
*/
+ @Test
public void testLocaleAwareConverterInConvertUtils() throws Exception {
try {
// first use the default non-locale-aware converter
try {
final Long data = (Long) ConvertUtils.convert("777",
Long.class);
- assertEquals("Standard format long converted ok", 777,
data.longValue());
+ assertEquals(777, data.longValue(), "Standard format long
converted ok");
}
catch(final ConversionException ex) {
fail("Unable to convert non-locale-aware number 777");
@@ -366,7 +347,7 @@ public class LocaleBeanificationTest extends TestCase {
// Long converter is set up to return a default value of
// zero on error.
final Long data = (Long) ConvertUtils.convert("1.000.000",
Long.class);
- assertEquals("Standard format behaved as expected", 0,
data.longValue());
+ assertEquals(0, data.longValue(), "Standard format behaved as
expected");
}
catch(final ConversionException ex) {
fail("Unexpected exception from standard Long converter.");
@@ -383,7 +364,7 @@ public class LocaleBeanificationTest extends TestCase {
ConvertUtils.register(longLocaleConverter, Long.class);
final Long data = (Long) ConvertUtils.convert("1.000.000",
Long.class);
- assertEquals("German-format long converted ok", 1000000,
data.longValue());
+ assertEquals(1000000, data.longValue(), "German-format long
converted ok");
} catch(final ConversionException ex) {
fail("Unable to convert german-format number");
}
@@ -393,6 +374,7 @@ public class LocaleBeanificationTest extends TestCase {
}
/** Tests whether classloaders and beans are released from memory */
+ @Test
public void testMemoryLeak() throws Exception {
// many thanks to Juozas Baliuka for suggesting this methodology
TestClassLoader loader = new TestClassLoader();
@@ -430,9 +412,9 @@ public class LocaleBeanificationTest extends TestCase {
final WeakReference<LocaleBeanUtilsBean> beanUtilsReference = new
WeakReference<>(thread.beanUtils);
final WeakReference<LocaleConvertUtilsBean> convertUtilsReference =
new WeakReference<>(thread.convertUtils);
- assertNotNull("Weak reference released early (1)",
loaderReference.get());
- assertNotNull("Weak reference released early (2)",
beanUtilsReference.get());
- assertNotNull("Weak reference released early (4)",
convertUtilsReference.get());
+ assertNotNull(loaderReference.get(), "Weak reference released early
(1)");
+ assertNotNull(beanUtilsReference.get(), "Weak reference released early
(2)");
+ assertNotNull(convertUtilsReference.get(), "Weak reference released
early (4)");
// dereference strong references
loader = null;
@@ -462,22 +444,23 @@ public class LocaleBeanificationTest extends TestCase {
}
/** Tests whether classloaders and beans are released from memory by the
map used by beanutils */
+ @Test
public void testMemoryLeak2() throws Exception {
// tests when the map used by beanutils has the right behavior
// many thanks to Juozas Baliuka for suggesting this methodology
TestClassLoader loader = new TestClassLoader();
final ReferenceQueue<Object> queue = new ReferenceQueue<>();
final WeakReference<ClassLoader> loaderReference = new
WeakReference<>(loader, queue);
- Integer test = new Integer(1);
+ Object test = new Object();
- final WeakReference<Integer> testReference = new WeakReference<>(test,
queue);
+ final WeakReference<Object> testReference = new WeakReference<>(test,
queue);
//Map map = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD,
true);
- final Map<TestClassLoader, Integer> map = new WeakHashMap<>();
+ final Map<TestClassLoader, Object> map = new WeakHashMap<>();
map.put(loader, test);
- assertEquals("In map", test, map.get(loader));
- assertNotNull("Weak reference released early (1)",
loaderReference.get());
- assertNotNull("Weak reference released early (2)",
testReference.get());
+ assertEquals(test, map.get(loader), "In map");
+ assertNotNull(loaderReference.get(), "Weak reference released early
(1)");
+ assertNotNull(testReference.get(), "Weak reference released early
(2)");
// dereference strong references
loader = null;
@@ -505,6 +488,7 @@ public class LocaleBeanificationTest extends TestCase {
}
/** Test of the methodology we'll use for some of the later tests */
+ @Test
public void testMemoryTestMethodology() throws Exception {
// test methodology
// many thanks to Juozas Baliuka for suggesting this method
@@ -513,7 +497,7 @@ public class LocaleBeanificationTest extends TestCase {
final WeakReference<ClassLoader> reference = new
WeakReference<>(loader);
Class<?> myClass =
loader.loadClass("org.apache.commons.beanutils.BetaBean");
- assertNotNull("Weak reference released early", reference.get());
+ assertNotNull(reference.get(), "Weak reference released early");
// dereference class loader and class:
loader = null;
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/BaseLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/BaseLocaleConverterTest.java
index 6012f55e..979f34ea 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/BaseLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/BaseLocaleConverterTest.java
@@ -17,11 +17,15 @@
package org.apache.commons.beanutils.locale.converters;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.util.Locale;
import org.apache.commons.beanutils.locale.BaseLocaleConverter;
-
-import junit.framework.TestCase;
+import org.apache.commons.beanutils.locale.IsolatedLocaleBeanUtils;
+import org.junit.jupiter.api.BeforeEach;
/**
* Base Test Case for the DecimalLocaleConverter classes. This class doesn't
@@ -30,10 +34,8 @@ import junit.framework.TestCase;
*
*/
-public class BaseLocaleConverterTest extends TestCase {
-
- // Original Default Locale
- protected Locale origLocale;
+@IsolatedLocaleBeanUtils("en-US")
+public abstract class BaseLocaleConverterTest {
// Converter
protected BaseLocaleConverter converter;
@@ -59,10 +61,6 @@ public class BaseLocaleConverterTest extends TestCase {
protected String expectedDecimalValue;
protected String expectedIntegerValue;
- public BaseLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Test Converting an invalid value.
*/
@@ -88,7 +86,7 @@ public class BaseLocaleConverterTest extends TestCase {
}
if (expectedValue != null) {
- assertEquals("Check invalid conversion is default " + msgId,
expectedValue, result);
+ assertEquals(expectedValue, result, "Check invalid conversion is
default " + msgId);
}
}
@@ -113,9 +111,9 @@ public class BaseLocaleConverterTest extends TestCase {
}
if (expectedValue == null) {
- assertNull("Check null conversion is null " + msgId + "
result="+result, result);
+ assertNull(result, "Check null conversion is null " + msgId + "
result="+result);
} else {
- assertEquals("Check null conversion is default " + msgId,
expectedValue, result);
+ assertEquals(expectedValue, result, "Check null conversion is
default " + msgId);
}
}
@@ -138,7 +136,7 @@ public class BaseLocaleConverterTest extends TestCase {
} catch (final Exception e) {
fail("No Pattern conversion threw " + msgId + " threw " + e);
}
- assertEquals("Check conversion value without pattern " + msgId,
expectedValue, result);
+ assertEquals(expectedValue, result, "Check conversion value without
pattern " + msgId);
}
@@ -160,7 +158,7 @@ public class BaseLocaleConverterTest extends TestCase {
} catch (final Exception e) {
fail("Type conversion threw " + msgId + " threw " + e);
}
- assertEquals("Check conversion value to type " + msgId, expectedValue,
result);
+ assertEquals(expectedValue, result, "Check conversion value to type "
+ msgId);
}
@@ -182,15 +180,15 @@ public class BaseLocaleConverterTest extends TestCase {
} catch (final Exception e) {
fail("Pattern conversion threw " + msgId + " threw " + e);
}
- assertEquals("Check conversion value with pattern " + msgId,
expectedValue, result);
+ assertEquals(expectedValue, result, "Check conversion value with
pattern " + msgId);
}
/**
* Set up instance variables required by this test case.
*/
- @Override
- public void setUp() throws Exception {
+ @BeforeEach
+ public void setUpLocaleConverter() {
// Default Locale (Use US)
defaultLocale = Locale.US;
@@ -210,50 +208,13 @@ public class BaseLocaleConverterTest extends TestCase {
expectedDecimalValue = "1234.56";
expectedIntegerValue = "1234";
- // Reset default to the one specified
- origLocale = Locale.getDefault();
-
// Initialize
converter = null;
result = null;
defaultValue = null;
expectedValue= null;
- if (defaultLocale.equals(origLocale)) {
- origLocale = null;
- } else {
- // System.out.println("Changing default locale from " + origLocale
+ " to " + defaultLocale);
- Locale.setDefault(defaultLocale);
- }
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
-
- converter = null;
- result = null;
- defaultValue = null;
- expectedValue= null;
-
- // Set the Default Locale back to the original value
- if (origLocale != null) {
- // System.out.println("Restoring default locale to " + origLocale);
- Locale.setDefault(origLocale);
- }
-
}
- /**
- * This class isn't intended to perform any real tests; it just provides
- * methods for the real test cases to inherit. However junit complains
- * if a class named ..TestCase contains no test methods, so here we
- * define a dummy one to keep it happy.
- */
- public void testNothing() {
- }
}
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/BigDecimalLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/BigDecimalLocaleConverterTest.java
index 646d4973..4b99a2b7 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/BigDecimalLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/BigDecimalLocaleConverterTest.java
@@ -19,6 +19,9 @@ package org.apache.commons.beanutils.locale.converters;
import java.math.BigDecimal;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
/**
* Test Case for the BigDecimalLocaleConverter class.
*
@@ -26,37 +29,24 @@ import java.math.BigDecimal;
public class BigDecimalLocaleConverterTest extends BaseLocaleConverterTest {
- public BigDecimalLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
defaultValue = new BigDecimal("9.99");
expectedValue = new BigDecimal(expectedDecimalValue);
}
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
/**
* Test Converter() constructor
*
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_2() {
converter = new BigDecimalLocaleConverter();
@@ -75,6 +65,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_3() {
converter = new BigDecimalLocaleConverter(true);
@@ -90,6 +81,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new BigDecimalLocaleConverter(localizedLocale);
@@ -105,6 +97,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
converter = new BigDecimalLocaleConverter(localizedLocale, true);
@@ -120,6 +113,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new BigDecimalLocaleConverter(localizedLocale,
defaultDecimalPattern);
@@ -135,6 +129,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
converter = new BigDecimalLocaleConverter(localizedLocale,
localizedDecimalPattern, true);
@@ -150,6 +145,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new BigDecimalLocaleConverter(defaultValue);
@@ -165,6 +161,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new BigDecimalLocaleConverter(defaultValue, true);
@@ -180,6 +177,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
converter = new BigDecimalLocaleConverter(defaultValue,
@@ -231,6 +229,7 @@ public class BigDecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test that a value beyond {@code double} precision is preserved instead
of being rounded to a lossy {@code 1.0E+19}.
*/
+ @Test
public void testConvertLargeValueKeepsPrecision() {
converter = new BigDecimalLocaleConverter();
convertValueNoPattern(converter, "9999999999999999999", new
BigDecimal("9999999999999999999"));
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/BigIntegerLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/BigIntegerLocaleConverterTest.java
index 909ffcb5..e667e01a 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/BigIntegerLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/BigIntegerLocaleConverterTest.java
@@ -17,9 +17,13 @@
package org.apache.commons.beanutils.locale.converters;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.math.BigInteger;
import org.apache.commons.beanutils.ConversionException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test Case for the BigIntegerLocaleConverter class.
@@ -28,37 +32,24 @@ import org.apache.commons.beanutils.ConversionException;
public class BigIntegerLocaleConverterTest extends BaseLocaleConverterTest {
- public BigIntegerLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
defaultValue = new BigInteger("999");
expectedValue = new BigInteger(expectedIntegerValue);
}
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
/**
* Test Converter() constructor
*
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_2() {
converter = new BigIntegerLocaleConverter();
@@ -77,6 +68,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_3() {
converter = new BigIntegerLocaleConverter(true);
@@ -92,6 +84,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new BigIntegerLocaleConverter(localizedLocale);
@@ -107,6 +100,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
converter = new BigIntegerLocaleConverter(localizedLocale, true);
@@ -122,6 +116,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new BigIntegerLocaleConverter(localizedLocale,
defaultIntegerPattern);
@@ -137,6 +132,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
converter = new BigIntegerLocaleConverter(localizedLocale,
localizedIntegerPattern, true);
@@ -152,6 +148,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new BigIntegerLocaleConverter(defaultValue);
@@ -167,6 +164,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new BigIntegerLocaleConverter(defaultValue, true);
@@ -182,6 +180,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
converter = new BigIntegerLocaleConverter(defaultValue,
@@ -232,6 +231,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test that a value beyond {@code long} range keeps its full magnitude
instead of being clamped to {@code Long.MAX_VALUE}.
*/
+ @Test
public void testConvertLargeValueKeepsMagnitude() {
converter = new BigIntegerLocaleConverter();
convertValueNoPattern(converter, "9999999999999999999", new
BigInteger("9999999999999999999"));
@@ -242,6 +242,7 @@ public class BigIntegerLocaleConverterTest extends
BaseLocaleConverterTest {
* Tries to convert to an unsupported type. This tests behavior of the base
* class. All locale converters should react in the same way.
*/
+ @Test
public void testUnsupportedType() {
converter = new BigIntegerLocaleConverter();
try {
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/ByteLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/ByteLocaleConverterTest.java
index e2df3385..1674022a 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/ByteLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/ByteLocaleConverterTest.java
@@ -17,6 +17,9 @@
package org.apache.commons.beanutils.locale.converters;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
/**
* Test Case for the ByteLocaleConverter class.
*
@@ -24,18 +27,12 @@ package org.apache.commons.beanutils.locale.converters;
public class ByteLocaleConverterTest extends BaseLocaleConverterTest {
- public ByteLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
defaultIntegerPattern = "#,###";
defaultIntegerValue = ",123";
@@ -51,20 +48,13 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
}
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
/**
* Test Converter() constructor
*
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_2() {
converter = new ByteLocaleConverter();
@@ -83,6 +73,7 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_3() {
converter = new ByteLocaleConverter(true);
@@ -98,6 +89,7 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new ByteLocaleConverter(localizedLocale);
@@ -113,6 +105,7 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
converter = new ByteLocaleConverter(localizedLocale, true);
@@ -128,6 +121,7 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new ByteLocaleConverter(localizedLocale,
defaultIntegerPattern);
@@ -143,6 +137,7 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
converter = new ByteLocaleConverter(localizedLocale,
localizedIntegerPattern, true);
@@ -158,6 +153,7 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new ByteLocaleConverter(defaultValue);
@@ -173,6 +169,7 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new ByteLocaleConverter(defaultValue, true);
@@ -188,6 +185,7 @@ public class ByteLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
converter = new ByteLocaleConverter(defaultValue,
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTest.java
index 69b68316..93363e28 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverterTest.java
@@ -17,6 +17,9 @@
package org.apache.commons.beanutils.locale.converters;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -26,6 +29,8 @@ import java.util.Locale;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test Case for the DateLocaleConverter class.
@@ -46,18 +51,12 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
protected boolean validLocalDateSymbols;
- public DateLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
final String version =
System.getProperty("java.specification.version");
log.debug("JDK Version "+version);
@@ -78,7 +77,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
// Use German Locale
// localizedLocale = Locale.GERMAN; // doesn't work for dates
// localizedLocale = Locale.GERMANY; // doesn't work for dates
- localizedLocale = new Locale("de", "AT"); // Austria/German
works
+ localizedLocale = Locale.forLanguageTag("de-AT"); //
Austria/German works
localizedDatePattern = "t MMMM uuuu";
localizedDateValue = "1 Oktober 2004";
localizedShortDateValue = "01.10.04";
@@ -98,22 +97,15 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
}
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
/**
* Test Calendar
*/
+ @Test
public void testCalendarObject() {
converter = new DateLocaleConverter(defaultLocale);
final Calendar calendar = Calendar.getInstance();
calendar.setTime((java.util.Date)expectedValue);
- assertEquals("java.util.Calendar", expectedValue,
converter.convert(calendar));
+ assertEquals(expectedValue, converter.convert(calendar),
"java.util.Calendar");
}
/**
@@ -122,6 +114,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_2() {
converter = new DateLocaleConverter();
@@ -140,6 +133,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_3() {
converter = new DateLocaleConverter(true);
@@ -155,6 +149,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new DateLocaleConverter(localizedLocale);
@@ -170,6 +165,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
// Skip this test if no valid symbols for the locale
@@ -191,6 +187,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new DateLocaleConverter(localizedLocale,
defaultDatePattern);
@@ -206,6 +203,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
// Skip this test if no valid symbols for the locale
@@ -227,6 +225,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new DateLocaleConverter(defaultValue);
@@ -242,6 +241,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new DateLocaleConverter(defaultValue, true);
@@ -257,6 +257,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
// Skip this test if no valid symbols for the locale
@@ -305,14 +306,16 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test java.util.Date
*/
+ @Test
public void testDateObject() {
converter = new DateLocaleConverter(defaultLocale);
- assertEquals("java.util.Date", expectedValue,
converter.convert(expectedValue));
+ assertEquals(expectedValue, converter.convert(expectedValue),
"java.util.Date");
}
/**
* Test invalid date
*/
+ @Test
public void testInvalidDate() {
converter = new DateLocaleConverter(defaultLocale);
@@ -320,17 +323,18 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
try {
converter.convert("01/10/2004", "dd-MM-yyyy");
} catch (final ConversionException e) {
- assertEquals("Parse Error", "Error parsing date '01/10/2004' at
position=2", e.getMessage());
+ assertEquals("Error parsing date '01/10/2004' at position=2",
e.getMessage(), "Parse Error");
}
try {
converter.convert("01-10-2004X", "dd-MM-yyyy");
} catch (final ConversionException e) {
- assertEquals("Parse Length", "Date '01-10-2004X' contains unparsed
characters from position=10", e.getMessage());
+ assertEquals("Date '01-10-2004X' contains unparsed characters from
position=10", e.getMessage(), "Parse Length");
}
}
+ @Test
public void testSetLenient() {
// make sure that date format works as expected
final SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd,
yyyy", Locale.UK);
@@ -379,7 +383,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
// test with no leniency
converter.setLenient(false);
- assertEquals("Set lenient failed", converter.isLenient(), false);
+ assertEquals(converter.isLenient(), false, "Set lenient failed");
try {
@@ -392,7 +396,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
try {
converter.convert("Feb 31, 2001");
- assertEquals("Set lenient failed", converter.isLenient(), false);
+ assertEquals(converter.isLenient(), false, "Set lenient failed");
fail("Parsed illegal date (2)");
} catch (final ConversionException e) {
@@ -401,7 +405,7 @@ public class DateLocaleConverterTest extends
BaseLocaleConverterTest {
// test with leniency
converter.setLenient(true);
- assertEquals("Set lenient failed", converter.isLenient(), true);
+ assertEquals(converter.isLenient(), true, "Set lenient failed");
try {
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverterTest.java
index ddcecd51..02b23732 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/DecimalLocaleConverterTest.java
@@ -17,22 +17,23 @@
package org.apache.commons.beanutils.locale.converters;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.util.Locale;
import org.apache.commons.beanutils.ConversionException;
+import org.junit.jupiter.api.Test;
/**
* Tests that {@link DecimalLocaleConverter} fully consumes its input and
rejects trailing, unparsed characters.
*/
public class DecimalLocaleConverterTest extends BaseLocaleConverterTest {
- public DecimalLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* A grouped number is still parsed in full.
*/
+ @Test
public void testParseAcceptsGroupedNumber() {
final IntegerLocaleConverter converter = new
IntegerLocaleConverter(Locale.US);
assertEquals(Integer.valueOf(1234), converter.convert("1,234"));
@@ -41,6 +42,7 @@ public class DecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Trailing characters left after a partial parse are rejected.
*/
+ @Test
public void testParseRejectsTrailingCharacters() {
final IntegerLocaleConverter converter = new
IntegerLocaleConverter(Locale.US);
try {
@@ -54,6 +56,7 @@ public class DecimalLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* A numeric prefix followed by an expression is rejected.
*/
+ @Test
public void testParseRejectsTrailingExpression() {
final IntegerLocaleConverter converter = new
IntegerLocaleConverter(Locale.US);
try {
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/DoubleLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/DoubleLocaleConverterTest.java
index 3800321a..17e294a5 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/DoubleLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/DoubleLocaleConverterTest.java
@@ -17,36 +17,29 @@
package org.apache.commons.beanutils.locale.converters;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
/**
* Test Case for the DoubleLocaleConverter class.
*/
public class DoubleLocaleConverterTest extends BaseLocaleConverterTest {
- public DoubleLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
defaultValue = Double.valueOf("9.99");
expectedValue = Double.valueOf(expectedDecimalValue);
}
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
/**
* Test Converter() constructor Uses the default locale, no default value
*/
+ @Test
public void testConstructor_2() {
converter = new DoubleLocaleConverter();
// Perform Tests
@@ -59,6 +52,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(locPattern) constructor Uses the default locale, no
default value
*/
+ @Test
public void testConstructor_3() {
converter = new DoubleLocaleConverter(true);
// Perform Tests
@@ -71,6 +65,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new DoubleLocaleConverter(localizedLocale);
// Perform Tests
@@ -83,6 +78,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
converter = new DoubleLocaleConverter(localizedLocale, true);
// Perform Tests
@@ -95,6 +91,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new DoubleLocaleConverter(localizedLocale,
defaultDecimalPattern);
// Perform Tests
@@ -107,6 +104,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
converter = new DoubleLocaleConverter(localizedLocale,
localizedDecimalPattern, true);
// Perform Tests
@@ -119,6 +117,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new DoubleLocaleConverter(defaultValue);
// Perform Tests
@@ -131,6 +130,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new DoubleLocaleConverter(defaultValue, true);
// Perform Tests
@@ -143,6 +143,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
converter = new DoubleLocaleConverter(defaultValue, localizedLocale,
localizedDecimalPattern, true);
convertValueNoPattern(converter, "(A)", localizedDecimalValue,
expectedValue);
@@ -180,6 +181,7 @@ public class DoubleLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Passing a non-Double Number directly (e.g. Integer) must return a
Double, not fail the conversion.
*/
+ @Test
public void testConvertFromNonDoubleNumber() {
converter = new DoubleLocaleConverter();
assertEquals(Double.valueOf(42.0), converter.convert(Double.class,
Integer.valueOf(42), null));
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTest.java
index 55b8f659..89605251 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/FloatLocaleConverterTest.java
@@ -17,11 +17,16 @@
package org.apache.commons.beanutils.locale.converters;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.text.DecimalFormat;
import java.util.Locale;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.locale.LocaleConvertUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test Case for the FloatLocaleConverter class.
@@ -30,37 +35,24 @@ import
org.apache.commons.beanutils.locale.LocaleConvertUtils;
public class FloatLocaleConverterTest extends BaseLocaleConverterTest {
- public FloatLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
defaultValue = Float.valueOf("9.99");
expectedValue = Float.valueOf(expectedDecimalValue);
}
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
/**
* Test Converter() constructor
*
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_2() {
converter = new FloatLocaleConverter();
@@ -79,6 +71,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_3() {
converter = new FloatLocaleConverter(true);
@@ -94,6 +87,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new FloatLocaleConverter(localizedLocale);
@@ -109,6 +103,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
converter = new FloatLocaleConverter(localizedLocale, true);
@@ -124,6 +119,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new FloatLocaleConverter(localizedLocale,
defaultDecimalPattern);
@@ -139,6 +135,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
converter = new FloatLocaleConverter(localizedLocale,
localizedDecimalPattern, true);
@@ -154,6 +151,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new FloatLocaleConverter(defaultValue);
@@ -169,6 +167,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new FloatLocaleConverter(defaultValue, true);
@@ -184,6 +183,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
converter = new FloatLocaleConverter(defaultValue,
@@ -235,17 +235,18 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Float limits
*/
+ @Test
public void testFloatLimits() {
converter = new FloatLocaleConverter(defaultLocale,
defaultDecimalPattern);
final DecimalFormat fmt = new
DecimalFormat("#.#############################################################");
assertEquals(Float.valueOf((float) -0.12), converter.convert("-0.12"));
- assertEquals("Positive Float.MAX_VALUE",
Float.valueOf(Float.MAX_VALUE), converter.convert(fmt.format(Float.MAX_VALUE)));
- assertEquals("Positive Float.MIN_VALUE",
Float.valueOf(Float.MIN_VALUE), converter.convert(fmt.format(Float.MIN_VALUE)));
+ assertEquals(Float.valueOf(Float.MAX_VALUE),
converter.convert(fmt.format(Float.MAX_VALUE)), "Positive Float.MAX_VALUE");
+ assertEquals(Float.valueOf(Float.MIN_VALUE),
converter.convert(fmt.format(Float.MIN_VALUE)), "Positive Float.MIN_VALUE");
- assertEquals("Negative Float.MAX_VALUE", Float.valueOf(Float.MAX_VALUE
* -1), converter.convert(fmt.format(Float.MAX_VALUE * -1)));
- assertEquals("Negative Float.MIN_VALUE", Float.valueOf(Float.MIN_VALUE
* -1), converter.convert(fmt.format(Float.MIN_VALUE * -1)));
+ assertEquals(Float.valueOf(Float.MAX_VALUE * -1),
converter.convert(fmt.format(Float.MAX_VALUE * -1)), "Negative
Float.MAX_VALUE");
+ assertEquals(Float.valueOf(Float.MIN_VALUE * -1),
converter.convert(fmt.format(Float.MIN_VALUE * -1)), "Negative
Float.MIN_VALUE");
try {
converter.convert(fmt.format((double)Float.MAX_VALUE *
(double)10));
@@ -277,6 +278,7 @@ public class FloatLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test parsing zero - see BEANUTILS-351
*/
+ @Test
public void testParseZero() {
try {
final Object result = LocaleConvertUtils.convert("0", Float.class,
Locale.US, null);
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTest.java
index 24ff04a8..2f3fa6dd 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/IntegerLocaleConverterTest.java
@@ -17,6 +17,11 @@
package org.apache.commons.beanutils.locale.converters;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
/**
* Test Case for the IntegerLocaleConverter class.
*
@@ -24,18 +29,12 @@ package org.apache.commons.beanutils.locale.converters;
public class IntegerLocaleConverterTest extends BaseLocaleConverterTest {
- public IntegerLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
defaultValue = Integer.valueOf("999");
expectedValue = Integer.valueOf(expectedIntegerValue);
@@ -47,6 +46,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_2() {
converter = new IntegerLocaleConverter();
@@ -65,6 +65,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_3() {
converter = new IntegerLocaleConverter(true);
@@ -80,6 +81,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new IntegerLocaleConverter(localizedLocale);
@@ -95,6 +97,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
converter = new IntegerLocaleConverter(localizedLocale, true);
@@ -110,6 +113,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new IntegerLocaleConverter(localizedLocale,
defaultIntegerPattern);
@@ -125,6 +129,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
converter = new IntegerLocaleConverter(localizedLocale,
localizedIntegerPattern, true);
@@ -140,6 +145,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new IntegerLocaleConverter(defaultValue);
@@ -155,6 +161,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new IntegerLocaleConverter(defaultValue, true);
@@ -170,6 +177,7 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
converter = new IntegerLocaleConverter(defaultValue,
@@ -220,24 +228,26 @@ public class IntegerLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converting a number
*/
+ @Test
public void testNumber() {
converter = new IntegerLocaleConverter(localizedLocale);
final Integer value = Integer.valueOf(1234);
- assertEquals("Convert Integer", value, converter.convert(value));
- assertEquals("Convert Long", value,
converter.convert(Long.valueOf(value.intValue())));
+ assertEquals(value, converter.convert(value), "Convert Integer");
+ assertEquals(value, converter.convert(Long.valueOf(value.intValue())),
"Convert Long");
}
/**
* Tests whether a conversion to a primitive type can be performed.
*/
+ @Test
public void testToPrimitiveType() {
converter = new IntegerLocaleConverter();
final int value = 20131028;
final Class<Integer> target = Integer.TYPE;
final int result = converter.convert(target, (Object)
Integer.toString(value));
- assertEquals("Wrong result", value, result);
+ assertEquals(value, result, "Wrong result");
}
}
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/LongLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/LongLocaleConverterTest.java
index 30c0742c..2c6825ce 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/LongLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/LongLocaleConverterTest.java
@@ -17,11 +17,14 @@
package org.apache.commons.beanutils.locale.converters;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.text.DecimalFormat;
import org.apache.commons.beanutils.ConversionException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test Case for the LongLocaleConverter class.
@@ -30,37 +33,24 @@ import org.apache.commons.beanutils.ConversionException;
public class LongLocaleConverterTest extends BaseLocaleConverterTest {
- public LongLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
defaultValue = Long.valueOf("999");
expectedValue = Long.valueOf(expectedIntegerValue);
}
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
/**
* Test Converter() constructor
*
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_2() {
converter = new LongLocaleConverter();
@@ -79,6 +69,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_3() {
converter = new LongLocaleConverter(true);
@@ -94,6 +85,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new LongLocaleConverter(localizedLocale);
@@ -109,6 +101,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
converter = new LongLocaleConverter(localizedLocale, true);
@@ -124,6 +117,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new LongLocaleConverter(localizedLocale,
defaultIntegerPattern);
@@ -139,6 +133,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
converter = new LongLocaleConverter(localizedLocale,
localizedIntegerPattern, true);
@@ -154,6 +149,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new LongLocaleConverter(defaultValue);
@@ -169,6 +165,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new LongLocaleConverter(defaultValue, true);
@@ -184,6 +181,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
converter = new LongLocaleConverter(defaultValue,
@@ -234,6 +232,7 @@ public class LongLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Long limits
*/
+ @Test
public void testLongLimits() {
converter = new LongLocaleConverter();
final DecimalFormat fmt = new DecimalFormat("#");
diff --git
a/src/test/java/org/apache/commons/beanutils/locale/converters/ShortLocaleConverterTest.java
b/src/test/java/org/apache/commons/beanutils/locale/converters/ShortLocaleConverterTest.java
index 7073aa69..8f2c81df 100644
---
a/src/test/java/org/apache/commons/beanutils/locale/converters/ShortLocaleConverterTest.java
+++
b/src/test/java/org/apache/commons/beanutils/locale/converters/ShortLocaleConverterTest.java
@@ -17,6 +17,9 @@
package org.apache.commons.beanutils.locale.converters;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
/**
* Test Case for the ShortLocaleConverter class.
*
@@ -24,37 +27,24 @@ package org.apache.commons.beanutils.locale.converters;
public class ShortLocaleConverterTest extends BaseLocaleConverterTest {
- public ShortLocaleConverterTest(final String name) {
- super(name);
- }
-
/**
* Set up instance variables required by this test case.
*/
- @Override
+ @BeforeEach
public void setUp() throws Exception {
- super.setUp();
-
defaultValue = Short.valueOf("999");
expectedValue = Short.valueOf(expectedIntegerValue);
}
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- super.tearDown();
- }
-
/**
* Test Converter() constructor
*
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_2() {
converter = new ShortLocaleConverter();
@@ -73,6 +63,7 @@ public class ShortLocaleConverterTest extends
BaseLocaleConverterTest {
* Uses the default locale, no default value
*
*/
+ @Test
public void testConstructor_3() {
converter = new ShortLocaleConverter(true);
@@ -88,6 +79,7 @@ public class ShortLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale) constructor
*/
+ @Test
public void testConstructor_4() {
converter = new ShortLocaleConverter(localizedLocale);
@@ -103,6 +95,7 @@ public class ShortLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, locPattern) constructor
*/
+ @Test
public void testConstructor_5() {
converter = new ShortLocaleConverter(localizedLocale, true);
@@ -118,6 +111,7 @@ public class ShortLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern) constructor
*/
+ @Test
public void testConstructor_6() {
converter = new ShortLocaleConverter(localizedLocale,
defaultIntegerPattern);
@@ -133,6 +127,7 @@ public class ShortLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(Locale, pattern, locPattern) constructor
*/
+ @Test
public void testConstructor_7() {
converter = new ShortLocaleConverter(localizedLocale,
localizedIntegerPattern, true);
@@ -148,6 +143,7 @@ public class ShortLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue) constructor
*/
+ @Test
public void testConstructor_8() {
converter = new ShortLocaleConverter(defaultValue);
@@ -163,6 +159,7 @@ public class ShortLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locPattern) constructor
*/
+ @Test
public void testConstructor_9() {
converter = new ShortLocaleConverter(defaultValue, true);
@@ -178,6 +175,7 @@ public class ShortLocaleConverterTest extends
BaseLocaleConverterTest {
/**
* Test Converter(defaultValue, locale, pattern, localizedPattern)
constructor
*/
+ @Test
public void testConstructorMain() {
converter = new ShortLocaleConverter(defaultValue,