SethFalco commented on code in PR #49:
URL: https://github.com/apache/commons-beanutils/pull/49#discussion_r1478285471
##########
src/test/java/org/apache/commons/beanutils2/converters/CharacterConverterTestCase.java:
##########
@@ -16,112 +16,107 @@
*/
package org.apache.commons.beanutils2.converters;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import org.apache.commons.beanutils2.ConversionException;
import org.apache.commons.beanutils2.Converter;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Test Case for the CharacterConverter class.
*/
-public class CharacterConverterTestCase extends TestCase {
-
- /**
- * Create Test Suite
- *
- * @return test suite
- */
- public static TestSuite suite() {
- return new TestSuite(CharacterConverterTestCase.class);
- }
+class CharacterConverterTestCase {
- /**
- * Constructs a new Character Converter test case.
- *
- * @param name Test Name
- */
- public CharacterConverterTestCase(final String name) {
- super(name);
- }
+ private Converter<Character> converter;
- /** Sets Up */
- @Override
+ @BeforeEach
public void setUp() throws Exception {
+ converter = new CharacterConverter();
}
- /** Tear Down */
- @Override
+ @AfterEach
public void tearDown() throws Exception {
+ converter = null;
}
/**
* Tests whether the primitive char class can be passed as target type.
*/
- public void testConvertToChar() {
- final Converter<Character> converter = new CharacterConverter();
- assertEquals("Wrong result", Character.valueOf('F'),
converter.convert(Character.TYPE, "FOO"));
+ @Test
+ void testConvertToChar() {
+ assertEquals(Character.valueOf('F'), converter.convert(Character.TYPE,
"FOO"), "Wrong result");
}
/**
* Test Conversion to Character
*/
- public void testConvertToCharacter() {
- final Converter<Character> converter = new CharacterConverter();
- assertEquals("Character Test", Character.valueOf('N'),
converter.convert(Character.class, Character.valueOf('N')));
- assertEquals("String Test", Character.valueOf('F'),
converter.convert(Character.class, "FOO"));
- assertEquals("Integer Test", Character.valueOf('3'),
converter.convert(Character.class, Integer.valueOf(321)));
+ @Test
+ void testConvertToCharacter() {
+ assertEquals(Character.valueOf('N'),
converter.convert(Character.class, Character.valueOf('N')), "Character Test");
+ assertEquals(Character.valueOf('F'),
converter.convert(Character.class, "FOO"), "String Test");
+ assertEquals(Character.valueOf('3'),
converter.convert(Character.class, Integer.valueOf(321)), "Integer Test");
}
/**
* Tests a conversion to character for null input if no default value is
provided.
*/
- public void testConvertToCharacterNullNoDefault() {
- final Converter<Character> converter = new CharacterConverter();
- try {
- converter.convert(Character.class, null);
- fail("Expected a ConversionException for null value");
- } catch (final Exception e) {
- // expected result
- }
+ @Test
+ void testConvertToCharacterNullNoDefault() {
+ assertThrows(ConversionException.class, () ->
converter.convert(Character.class, null));
}
/**
* Test Conversion to String
*/
+ @Test
@SuppressWarnings("unchecked") // testing raw conversion
- public void testConvertToString() {
+ void testConvertToString() {
Review Comment:
Happy to do this, but just want to clarify something, as I made this change
based on the JUnit User Guide:
> _Class and method visibility_
>
> Test classes, test methods, and lifecycle methods are not required to be
`public`, but they must not be `private`.
>
> It is generally recommended to omit the `public` modifier for test
classes, test methods, and lifecycle methods unless there is a technical reason
for doing so – for example, when a test class is extended by a test class in
another package. Another technical reason for making classes and methods
`public` is to simplify testing on the module path when using the Java Module
System.
>
> — https://junit.org/junit5/docs/current/user-guide/
I'll assume you'd prefer to have your convention applied for now. However,
if sharing this convinces you otherwise, let me know and I'd be happy to remove
the scope again. 👍🏽
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]