garydgregory commented on code in PR #49:
URL: https://github.com/apache/commons-beanutils/pull/49#discussion_r1478275955


##########
src/main/java/org/apache/commons/beanutils2/converters/InstantConverter.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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
+ *
+ *      http://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.beanutils2.converters;
+
+import java.time.Instant;
+
+/**
+ * {@link org.apache.commons.beanutils2.Converter} implementation that handles 
conversion
+ * to and from {@link Instant} objects.
+ *

Review Comment:
   Remove extra Javadoc blank line.



##########
src/test/java/org/apache/commons/beanutils2/converters/EnumConverterTestCase.java:
##########
@@ -50,41 +48,74 @@ protected Converter<Enum<PizzaStatus>> makeConverter() {
         return new EnumConverter<>();
     }
 
-    @Override
+    @BeforeEach
     public void setUp() throws Exception {
         converter = makeConverter();
     }
 
-    @Override
+    @AfterEach
     public void tearDown() throws Exception {
         converter = null;
     }
 
-    public void testSimpleConversion() throws Exception {
+    @Test
+    void testSimpleConversion() throws Exception {
         final String[] message = { "from String", "from String", "from 
String", "from String", "from String", "from String", "from String", "from 
String", };
 
         final Object[] input = { "DELIVERED", "ORDERED", "READY" };
 
         final PizzaStatus[] expected = { PizzaStatus.DELIVERED, 
PizzaStatus.ORDERED, PizzaStatus.READY };
 
         for (int i = 0; i < expected.length; i++) {
-            assertEquals(message[i] + " to Enum", expected[i], 
converter.convert(PizzaStatus.class, input[i]));
+            assertEquals(expected[i], converter.convert(PizzaStatus.class, 
input[i]), message[i] + " to Enum");
         }
 
         for (int i = 0; i < expected.length; i++) {
-            assertEquals(input[i] + " to String", input[i], 
converter.convert(String.class, expected[i]));
+            assertEquals(input[i], converter.convert(String.class, 
expected[i]), input[i] + " to String");
         }
     }
 
     /**
      * Tests a conversion to an unsupported type.
      */
-    public void testUnsupportedType() {
-        try {
-            converter.convert(Integer.class, "http://www.apache.org";);
-            fail("Unsupported type could be converted!");
-        } catch (final ConversionException cex) {
-            // expected result
-        }
+    @Test
+    void testUnsupportedType() {
+        assertThrows(ConversionException.class, () -> 
converter.convert(Integer.class, "http://www.apache.org";));
+    }
+
+    @Test
+    void testConvertTimeUnit() {
+        final TimeUnit expected = TimeUnit.NANOSECONDS;
+        final Enum actual = converter.convert(Enum.class, 
"java.util.concurrent.TimeUnit.NANOSECONDS");
+

Review Comment:
   Remove extra whitespace.



##########
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:
   Don't change the public test convention we use in tests.



##########
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 {

Review Comment:
   @SethFalco 
   Our convention is to use public classes for test cases. Please do not change 
this to keep the PR focused and minimize PR noise and size.
   



##########
src/main/java/org/apache/commons/beanutils2/converters/CharacterConverter.java:
##########
@@ -22,11 +22,19 @@
  * <p>
  * Can be configured to either return a <i>default value</i> or throw a
  * {@code ConversionException} if a conversion error occurs.
+ * </p>
+ *

Review Comment:
   Remove extra Javadoc blank line.
   



##########
src/test/java/org/apache/commons/beanutils2/converters/EnumConverterTestCase.java:
##########
@@ -50,41 +48,74 @@ protected Converter<Enum<PizzaStatus>> makeConverter() {
         return new EnumConverter<>();
     }
 
-    @Override
+    @BeforeEach
     public void setUp() throws Exception {
         converter = makeConverter();
     }
 
-    @Override
+    @AfterEach
     public void tearDown() throws Exception {
         converter = null;
     }
 
-    public void testSimpleConversion() throws Exception {
+    @Test
+    void testSimpleConversion() throws Exception {
         final String[] message = { "from String", "from String", "from 
String", "from String", "from String", "from String", "from String", "from 
String", };
 
         final Object[] input = { "DELIVERED", "ORDERED", "READY" };
 
         final PizzaStatus[] expected = { PizzaStatus.DELIVERED, 
PizzaStatus.ORDERED, PizzaStatus.READY };
 
         for (int i = 0; i < expected.length; i++) {
-            assertEquals(message[i] + " to Enum", expected[i], 
converter.convert(PizzaStatus.class, input[i]));
+            assertEquals(expected[i], converter.convert(PizzaStatus.class, 
input[i]), message[i] + " to Enum");
         }
 
         for (int i = 0; i < expected.length; i++) {
-            assertEquals(input[i] + " to String", input[i], 
converter.convert(String.class, expected[i]));
+            assertEquals(input[i], converter.convert(String.class, 
expected[i]), input[i] + " to String");
         }
     }
 
     /**
      * Tests a conversion to an unsupported type.
      */
-    public void testUnsupportedType() {
-        try {
-            converter.convert(Integer.class, "http://www.apache.org";);
-            fail("Unsupported type could be converted!");
-        } catch (final ConversionException cex) {
-            // expected result
-        }
+    @Test
+    void testUnsupportedType() {
+        assertThrows(ConversionException.class, () -> 
converter.convert(Integer.class, "http://www.apache.org";));
+    }
+
+    @Test
+    void testConvertTimeUnit() {
+        final TimeUnit expected = TimeUnit.NANOSECONDS;
+        final Enum actual = converter.convert(Enum.class, 
"java.util.concurrent.TimeUnit.NANOSECONDS");
+
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    void testConvertDayOfWeek() {
+        final DayOfWeek expected = DayOfWeek.MONDAY;
+        final DayOfWeek actual = converter.convert(DayOfWeek.class, 
"java.time.DayOfWeek#MONDAY");
+

Review Comment:
   Remove extra whitespace.



##########
src/test/java/org/apache/commons/beanutils2/converters/EnumConverterTestCase.java:
##########
@@ -50,41 +48,74 @@ protected Converter<Enum<PizzaStatus>> makeConverter() {
         return new EnumConverter<>();
     }
 
-    @Override
+    @BeforeEach
     public void setUp() throws Exception {
         converter = makeConverter();
     }
 
-    @Override
+    @AfterEach
     public void tearDown() throws Exception {
         converter = null;
     }
 
-    public void testSimpleConversion() throws Exception {
+    @Test
+    void testSimpleConversion() throws Exception {
         final String[] message = { "from String", "from String", "from 
String", "from String", "from String", "from String", "from String", "from 
String", };
 
         final Object[] input = { "DELIVERED", "ORDERED", "READY" };
 
         final PizzaStatus[] expected = { PizzaStatus.DELIVERED, 
PizzaStatus.ORDERED, PizzaStatus.READY };
 
         for (int i = 0; i < expected.length; i++) {
-            assertEquals(message[i] + " to Enum", expected[i], 
converter.convert(PizzaStatus.class, input[i]));
+            assertEquals(expected[i], converter.convert(PizzaStatus.class, 
input[i]), message[i] + " to Enum");
         }
 
         for (int i = 0; i < expected.length; i++) {
-            assertEquals(input[i] + " to String", input[i], 
converter.convert(String.class, expected[i]));
+            assertEquals(input[i], converter.convert(String.class, 
expected[i]), input[i] + " to String");
         }
     }
 
     /**
      * Tests a conversion to an unsupported type.
      */
-    public void testUnsupportedType() {
-        try {
-            converter.convert(Integer.class, "http://www.apache.org";);
-            fail("Unsupported type could be converted!");
-        } catch (final ConversionException cex) {
-            // expected result
-        }
+    @Test
+    void testUnsupportedType() {

Review Comment:
   All tests are public (our convention).



-- 
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]

Reply via email to