This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit c301062c198d42f981fd565a2b07f61d3afb067e Author: Gary Gregory <[email protected]> AuthorDate: Sun Aug 18 08:36:57 2024 -0400 Sort members --- .../beanutils2/converters/ColorConverter.java | 84 ++++++++-------- .../beanutils2/converters/DimensionConverter.java | 22 ++-- .../converters/InetAddressConverter.java | 22 ++-- .../beanutils2/converters/LocaleConverter.java | 22 ++-- .../beanutils2/converters/PatternConverter.java | 22 ++-- .../beanutils2/converters/PointConverter.java | 22 ++-- .../apache/commons/beanutils2/BeanMapTestCase.java | 112 ++++++++++----------- .../commons/beanutils2/BeanUtilsBeanTestCase.java | 36 +++---- .../commons/beanutils2/bugs/Jira541TestCase.java | 86 ++++++++-------- .../converters/ColorConverterTestCase.java | 96 +++++++++--------- .../converters/InetAddressConverterTestCase.java | 8 +- .../converters/LocaleConverterTestCase.java | 12 +-- .../converters/PointConverterTestCase.java | 8 +- 13 files changed, 276 insertions(+), 276 deletions(-) diff --git a/src/main/java/org/apache/commons/beanutils2/converters/ColorConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/ColorConverter.java index 543a9f4b..10b5d4ec 100644 --- a/src/main/java/org/apache/commons/beanutils2/converters/ColorConverter.java +++ b/src/main/java/org/apache/commons/beanutils2/converters/ColorConverter.java @@ -60,17 +60,6 @@ public class ColorConverter extends AbstractConverter<Color> { super(defaultValue); } - /** - * Gets the default type this {@code Converter} handles. - * - * @return The default type this {@code Converter} handles. - * @since 2.0.0 - */ - @Override - protected Class<Color> getDefaultType() { - return Color.class; - } - /** * Converts a {@link Color} into a {@link String}. * @@ -159,39 +148,14 @@ public class ColorConverter extends AbstractConverter<Color> { } /** - * Parses the Color based on the result of the {@link Color#toString()} method. - * - * Accepts the following values: - * <ul> - * <li>{@code java.awt.Color[r=255,g=255,b=255]}</li> - * <li>{@code [r=255,g=255,b=255]}</li> - * <li>{@code r=255,g=255,b=255}</li> - * <li>{@code 255,255,255}</li> - * </ul> + * Gets the default type this {@code Converter} handles. * - * @param value A color as represented by {@link Color#toString()}. - * @return The Java friendly {@link Color} this color represents. - * @throws IllegalArgumentException If the input can't be matches by the {@link #JAVA_COLOR_PATTERN} - * or a {@link Color} component specified is over 255. + * @return The default type this {@code Converter} handles. + * @since 2.0.0 */ - private Color parseToStringColor(final String value) { - Objects.requireNonNull(value); - - final Matcher matcher = JAVA_COLOR_PATTERN.matcher(value); - - if (!matcher.matches()) { - throw new IllegalArgumentException("Invalid Color String provided. Could not parse."); - } - - final int red = Integer.parseInt(matcher.group(1)); - final int green = Integer.parseInt(matcher.group(2)); - final int blue = Integer.parseInt(matcher.group(3)); - - if (red > 255 || green > 255 || blue > 255) { - throw new IllegalArgumentException("Color component integers must be between 0 and 255."); - } - - return new Color(red, green, blue); + @Override + protected Class<Color> getDefaultType() { + return Color.class; } /** @@ -236,4 +200,40 @@ public class ColorConverter extends AbstractConverter<Color> { "is required, prefix with 0x instead of #, otherwise expecting 3, 4, 6, or 8 characters only."); } } + + /** + * Parses the Color based on the result of the {@link Color#toString()} method. + * + * Accepts the following values: + * <ul> + * <li>{@code java.awt.Color[r=255,g=255,b=255]}</li> + * <li>{@code [r=255,g=255,b=255]}</li> + * <li>{@code r=255,g=255,b=255}</li> + * <li>{@code 255,255,255}</li> + * </ul> + * + * @param value A color as represented by {@link Color#toString()}. + * @return The Java friendly {@link Color} this color represents. + * @throws IllegalArgumentException If the input can't be matches by the {@link #JAVA_COLOR_PATTERN} + * or a {@link Color} component specified is over 255. + */ + private Color parseToStringColor(final String value) { + Objects.requireNonNull(value); + + final Matcher matcher = JAVA_COLOR_PATTERN.matcher(value); + + if (!matcher.matches()) { + throw new IllegalArgumentException("Invalid Color String provided. Could not parse."); + } + + final int red = Integer.parseInt(matcher.group(1)); + final int green = Integer.parseInt(matcher.group(2)); + final int blue = Integer.parseInt(matcher.group(3)); + + if (red > 255 || green > 255 || blue > 255) { + throw new IllegalArgumentException("Color component integers must be between 0 and 255."); + } + + return new Color(red, green, blue); + } } diff --git a/src/main/java/org/apache/commons/beanutils2/converters/DimensionConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/DimensionConverter.java index 58d27942..664455ce 100644 --- a/src/main/java/org/apache/commons/beanutils2/converters/DimensionConverter.java +++ b/src/main/java/org/apache/commons/beanutils2/converters/DimensionConverter.java @@ -56,17 +56,6 @@ public class DimensionConverter extends AbstractConverter<Dimension> { super(defaultValue); } - /** - * Gets the default type this {@code Converter} handles. - * - * @return The default type this {@code Converter} handles. - * @since 2.0.0 - */ - @Override - protected Class<Dimension> getDefaultType() { - return Dimension.class; - } - /** * Converts the input object into an output object of the specified type. * @@ -103,4 +92,15 @@ public class DimensionConverter extends AbstractConverter<Dimension> { throw conversionException(type, value); } + + /** + * Gets the default type this {@code Converter} handles. + * + * @return The default type this {@code Converter} handles. + * @since 2.0.0 + */ + @Override + protected Class<Dimension> getDefaultType() { + return Dimension.class; + } } diff --git a/src/main/java/org/apache/commons/beanutils2/converters/InetAddressConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/InetAddressConverter.java index 4f98bdc3..a1d35915 100644 --- a/src/main/java/org/apache/commons/beanutils2/converters/InetAddressConverter.java +++ b/src/main/java/org/apache/commons/beanutils2/converters/InetAddressConverter.java @@ -47,17 +47,6 @@ public class InetAddressConverter extends AbstractConverter<InetAddress> { super(defaultValue); } - /** - * Gets the default type this {@code Converter} handles. - * - * @return The default type this {@code Converter} handles. - * @since 2.0.0 - */ - @Override - protected Class<InetAddress> getDefaultType() { - return InetAddress.class; - } - /** * Converts the specified input object into an output object of the specified type. * @@ -81,4 +70,15 @@ public class InetAddressConverter extends AbstractConverter<InetAddress> { throw conversionException(type, value); } + + /** + * Gets the default type this {@code Converter} handles. + * + * @return The default type this {@code Converter} handles. + * @since 2.0.0 + */ + @Override + protected Class<InetAddress> getDefaultType() { + return InetAddress.class; + } } diff --git a/src/main/java/org/apache/commons/beanutils2/converters/LocaleConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/LocaleConverter.java index d0ee5e13..e12dfc7c 100644 --- a/src/main/java/org/apache/commons/beanutils2/converters/LocaleConverter.java +++ b/src/main/java/org/apache/commons/beanutils2/converters/LocaleConverter.java @@ -44,17 +44,6 @@ public class LocaleConverter extends AbstractConverter<Locale> { super(defaultValue); } - /** - * Gets the default type this {@code Converter} handles. - * - * @return The default type this {@code Converter} handles. - * @since 2.0.0 - */ - @Override - protected Class<Locale> getDefaultType() { - return Locale.class; - } - /** * Converts the specified input object into an output object of the specified type. * @@ -72,4 +61,15 @@ public class LocaleConverter extends AbstractConverter<Locale> { throw conversionException(type, value); } + + /** + * Gets the default type this {@code Converter} handles. + * + * @return The default type this {@code Converter} handles. + * @since 2.0.0 + */ + @Override + protected Class<Locale> getDefaultType() { + return Locale.class; + } } diff --git a/src/main/java/org/apache/commons/beanutils2/converters/PatternConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/PatternConverter.java index c338e52d..25449cd8 100644 --- a/src/main/java/org/apache/commons/beanutils2/converters/PatternConverter.java +++ b/src/main/java/org/apache/commons/beanutils2/converters/PatternConverter.java @@ -44,17 +44,6 @@ public class PatternConverter extends AbstractConverter<Pattern> { super(defaultValue); } - /** - * Gets the default type this {@code Converter} handles. - * - * @return The default type this {@code Converter} handles. - * @since 2.0.0 - */ - @Override - protected Class<Pattern> getDefaultType() { - return Pattern.class; - } - /** * Converts the specified input object into an output object of the specified type. * @@ -73,4 +62,15 @@ public class PatternConverter extends AbstractConverter<Pattern> { throw conversionException(type, value); } + + /** + * Gets the default type this {@code Converter} handles. + * + * @return The default type this {@code Converter} handles. + * @since 2.0.0 + */ + @Override + protected Class<Pattern> getDefaultType() { + return Pattern.class; + } } diff --git a/src/main/java/org/apache/commons/beanutils2/converters/PointConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/PointConverter.java index 6991eaab..e2f993e9 100644 --- a/src/main/java/org/apache/commons/beanutils2/converters/PointConverter.java +++ b/src/main/java/org/apache/commons/beanutils2/converters/PointConverter.java @@ -49,17 +49,6 @@ public class PointConverter extends AbstractConverter<Point> { super(defaultValue); } - /** - * Gets the default type this {@code Converter} handles. - * - * @return The default type this {@code Converter} handles. - * @since 2.0.0 - */ - @Override - protected Class<Point> getDefaultType() { - return Point.class; - } - /** * Converts the specified input object into an output object of the specified type. * @@ -100,4 +89,15 @@ public class PointConverter extends AbstractConverter<Point> { throw conversionException(type, value); } + + /** + * Gets the default type this {@code Converter} handles. + * + * @return The default type this {@code Converter} handles. + * @since 2.0.0 + */ + @Override + protected Class<Point> getDefaultType() { + return Point.class; + } } diff --git a/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java index a0bcc642..dc4704cf 100644 --- a/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java @@ -172,6 +172,24 @@ public class BeanMapTestCase extends AbstractMapTest<String, Object> { super(testName); } + @Override + public Object[] getNewSampleValues() { + final Object[] values = { + Integer.valueOf(223), + Long.valueOf(23341928234L), + Double.valueOf(23423.34), + Float.valueOf(213332.12f), + Short.valueOf((short)234), + Byte.valueOf((byte)20), + Character.valueOf('b'), + Integer.valueOf(232), + "SomeNewStringValue", + new Object(), + null, + }; + return values; + } + // note to self. The Sample keys were generated by copying the field // declarations and using the following regular expression search and replace: // @@ -210,21 +228,20 @@ public class BeanMapTestCase extends AbstractMapTest<String, Object> { } @Override - public Object[] getNewSampleValues() { - final Object[] values = { - Integer.valueOf(223), - Long.valueOf(23341928234L), - Double.valueOf(23423.34), - Float.valueOf(213332.12f), - Short.valueOf((short)234), - Byte.valueOf((byte)20), - Character.valueOf('b'), - Integer.valueOf(232), - "SomeNewStringValue", - new Object(), - null, + public String[] ignoredTests() { + // Ignore the serialization tests on collection views. + return new String[] { + "TestBeanMap.bulkTestMapEntrySet.testCanonicalEmptyCollectionExists", + "TestBeanMap.bulkTestMapEntrySet.testCanonicalFullCollectionExists", + "TestBeanMap.bulkTestMapKeySet.testCanonicalEmptyCollectionExists", + "TestBeanMap.bulkTestMapKeySet.testCanonicalFullCollectionExists", + "TestBeanMap.bulkTestMapValues.testCanonicalEmptyCollectionExists", + "TestBeanMap.bulkTestMapValues.testCanonicalFullCollectionExists", + "TestBeanMap.bulkTestMapEntrySet.testSimpleSerialization", + "TestBeanMap.bulkTestMapKeySet.testSimpleSerialization", + "TestBeanMap.bulkTestMapEntrySet.testSerializeDeserializeThenCompare", + "TestBeanMap.bulkTestMapKeySet.testSerializeDeserializeThenCompare" }; - return values; } /** @@ -264,43 +281,8 @@ public class BeanMapTestCase extends AbstractMapTest<String, Object> { } @Override - public String[] ignoredTests() { - // Ignore the serialization tests on collection views. - return new String[] { - "TestBeanMap.bulkTestMapEntrySet.testCanonicalEmptyCollectionExists", - "TestBeanMap.bulkTestMapEntrySet.testCanonicalFullCollectionExists", - "TestBeanMap.bulkTestMapKeySet.testCanonicalEmptyCollectionExists", - "TestBeanMap.bulkTestMapKeySet.testCanonicalFullCollectionExists", - "TestBeanMap.bulkTestMapValues.testCanonicalEmptyCollectionExists", - "TestBeanMap.bulkTestMapValues.testCanonicalFullCollectionExists", - "TestBeanMap.bulkTestMapEntrySet.testSimpleSerialization", - "TestBeanMap.bulkTestMapKeySet.testSimpleSerialization", - "TestBeanMap.bulkTestMapEntrySet.testSerializeDeserializeThenCompare", - "TestBeanMap.bulkTestMapKeySet.testSerializeDeserializeThenCompare" - }; - } - - /** - * Need to override this method because the "clear()" method on the bean - * map just returns the bean properties to their default states. It does - * not actually remove the mappings as per the map contract. The default - * testClear() methods checks that the clear method throws an - * UnsupportedOperationException since this class is not add/remove - * modifiable. In our case though, we do not always throw that exception. - */ - @Override - public void testMapClear() { - //TODO: make sure a call to BeanMap.clear returns the bean to its - //default initialization values. - } - - /** - * Need to override this method because the "put()" method on the bean - * doesn't work for this type of Map. - */ - @Override - public void testMapPut() { - // see testBeanMapPutAllWriteable + public Map<String, Object> makeObject() { + return new BeanMap(); } public void testBeanMapClone() { @@ -425,6 +407,29 @@ public class BeanMapTestCase extends AbstractMapTest<String, Object> { assertEquals("Double.TYPE", Double.valueOf("6"), beanMap.getTypeTransformer(Double.TYPE).apply("6")); } + /** + * Need to override this method because the "clear()" method on the bean + * map just returns the bean properties to their default states. It does + * not actually remove the mappings as per the map contract. The default + * testClear() methods checks that the clear method throws an + * UnsupportedOperationException since this class is not add/remove + * modifiable. In our case though, we do not always throw that exception. + */ + @Override + public void testMapClear() { + //TODO: make sure a call to BeanMap.clear returns the bean to its + //default initialization values. + } + + /** + * Need to override this method because the "put()" method on the bean + * doesn't work for this type of Map. + */ + @Override + public void testMapPut() { + // see testBeanMapPutAllWriteable + } + public void testMethodAccessor() throws Exception { final BeanMap map = (BeanMap) makeFullMap(); final Method method = BeanWithProperties.class.getDeclaredMethod("getSomeIntegerValue"); @@ -445,9 +450,4 @@ public class BeanMapTestCase extends AbstractMapTest<String, Object> { values = map.values(); super.verifyValues(); } - - @Override - public Map<String, Object> makeObject() { - return new BeanMap(); - } } diff --git a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java index 4461dfe6..4374fc35 100644 --- a/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/BeanUtilsBeanTestCase.java @@ -754,18 +754,6 @@ public class BeanUtilsBeanTestCase extends TestCase { } } - public void testGetMappedProperty2Args() throws Exception { - assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty(null, null)); - assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty(null, "")); - assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty("", null)); - } - - public void testGetMappedProperty3Args() throws Exception { - assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty(null, null)); - assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty(null, "", null)); - assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty("", null, null)); - } - /** * tests getting an indexed property */ @@ -825,6 +813,18 @@ public class BeanUtilsBeanTestCase extends TestCase { assertEquals("java.util.Date[0] --> String", testUtilDate.toString(), value); } + public void testGetMappedProperty2Args() throws Exception { + assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty(null, null)); + assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty(null, "")); + assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty("", null)); + } + + public void testGetMappedProperty3Args() throws Exception { + assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty(null, null)); + assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty(null, "", null)); + assertThrows(NullPointerException.class, () -> BeanUtils.getMappedProperty("", null, null)); + } + /** * tests getting a nested property */ @@ -903,6 +903,12 @@ public class BeanUtilsBeanTestCase extends TestCase { assertEquals("Mapped property set correctly", "some.dotty.value", bean.getMapproperty("this.that.the-other")); } + public void testPopulate() throws Exception { + BeanUtilsBean.getInstance().populate(null, null); + BeanUtilsBean.getInstance().populate("", null); + BeanUtilsBean.getInstance().populate(null, new HashMap<>()); + } + /** * Test populate() method on individual array elements. */ @@ -943,12 +949,6 @@ public class BeanUtilsBeanTestCase extends TestCase { } - public void testPopulate() throws Exception { - BeanUtilsBean.getInstance().populate(null, null); - BeanUtilsBean.getInstance().populate("", null); - BeanUtilsBean.getInstance().populate(null, new HashMap<>()); - } - /** * Test populate() method on array properties as a whole. */ diff --git a/src/test/java/org/apache/commons/beanutils2/bugs/Jira541TestCase.java b/src/test/java/org/apache/commons/beanutils2/bugs/Jira541TestCase.java index 6f073b00..b2676cb7 100644 --- a/src/test/java/org/apache/commons/beanutils2/bugs/Jira541TestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/bugs/Jira541TestCase.java @@ -35,33 +35,36 @@ import org.junit.jupiter.api.Test; */ public class Jira541TestCase { - private static final String FIELD_NAME = "field"; - private static final String FIELD_VALUE = "name"; + public static class BaseType { - @Test - public void testFluentBeanIntrospectorOnOverriddenSetter() throws Exception { - testImpl(); + private String field; + + public String getField() { + return field; + } + + public BaseType setField(final String objectName) { + this.field = objectName; + return this; + } } + public static class SubTypeA extends BaseType { - @Test - public void testFluentBeanIntrospectorOnOverriddenSetterConcurrent() throws Exception { - final ExecutorService executionService = Executors.newFixedThreadPool(256); - try { - final List<Future<?>> futures = new ArrayList<>(); - for (int i = 0; i < 10000; i++) { - futures.add(executionService.submit(() -> { - testImpl(); - return null; - })); - } - for (final Future<?> future : futures) { - future.get(); - } - } finally { - executionService.shutdown(); + @Override + public SubTypeA setField(final String field) { + super.setField(field); + return this; } } + public static class SubTypeB extends BaseType { + + } + + private static final String FIELD_NAME = "field"; + + private static final String FIELD_VALUE = "name"; + private static void testImpl() throws ReflectiveOperationException { final PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); propertyUtilsBean.addBeanIntrospector(new FluentPropertyBeanIntrospector()); @@ -78,30 +81,27 @@ public class Jira541TestCase { assertEquals(FIELD_VALUE, subTypeB.getField()); } - public static class BaseType { - - private String field; - - public BaseType setField(final String objectName) { - this.field = objectName; - return this; - } - - public String getField() { - return field; - } + @Test + public void testFluentBeanIntrospectorOnOverriddenSetter() throws Exception { + testImpl(); } - public static class SubTypeA extends BaseType { - - @Override - public SubTypeA setField(final String field) { - super.setField(field); - return this; + @Test + public void testFluentBeanIntrospectorOnOverriddenSetterConcurrent() throws Exception { + final ExecutorService executionService = Executors.newFixedThreadPool(256); + try { + final List<Future<?>> futures = new ArrayList<>(); + for (int i = 0; i < 10000; i++) { + futures.add(executionService.submit(() -> { + testImpl(); + return null; + })); + } + for (final Future<?> future : futures) { + future.get(); + } + } finally { + executionService.shutdown(); } } - - public static class SubTypeB extends BaseType { - - } } diff --git a/src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTestCase.java index 93ca7b5d..a3773586 100644 --- a/src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTestCase.java @@ -39,66 +39,60 @@ public class ColorConverterTestCase { converter = new ColorConverter(); } - @Test - public void testConvertingPattern() { - final Color expected = Color.BLACK; - final Color actual = converter.convert(Color.class, "#000000"); - - Assert.assertEquals(expected, actual); + @Test(expected = ConversionException.class) + public void testColorBlank() { + converter.convert(Color.class, "#"); } - @Test - public void testConvertingPatternWithAlpha() { - final Color expected = Color.LIGHT_GRAY; - final Color actual = converter.convert(Color.class, "#C0C0C0FF"); - - Assert.assertEquals(expected, actual); + @Test(expected = ConversionException.class) + public void testColorInvalidLength() { + converter.convert(Color.class, "#F"); } @Test - public void testConvertingPattern3Digit() { + public void testConvertingColorName() { final Color expected = Color.WHITE; - final Color actual = converter.convert(Color.class, "#FFF"); + final Color actual = converter.convert(Color.class, "white"); Assert.assertEquals(expected, actual); } @Test - public void testConvertingPattern4Digit() { - final Color expected = Color.YELLOW; - final Color actual = converter.convert(Color.class, "#FF0F"); + public void testConvertingColorNameCaps() { + final Color expected = Color.LIGHT_GRAY; + final Color actual = converter.convert(Color.class, "LIGHTGRAY"); Assert.assertEquals(expected, actual); } @Test - public void testConvertingLiteralHex() { - final Color expected = Color.BLUE; - final Color actual = converter.convert(Color.class, "0x0000FF"); + public void testConvertingJavaColorStringFull() { + final Color expected = Color.WHITE; + final Color actual = converter.convert(Color.class, "java.awt.Color[r=255,g=255,b=255]"); Assert.assertEquals(expected, actual); } @Test - public void testConvertingColorName() { - final Color expected = Color.WHITE; - final Color actual = converter.convert(Color.class, "white"); + public void testConvertingJavaColorStringWithoutBrackets() { + final Color expected = Color.DARK_GRAY; + final Color actual = converter.convert(Color.class, "r=64,g=64,b=64"); Assert.assertEquals(expected, actual); } @Test - public void testConvertingColorNameCaps() { - final Color expected = Color.LIGHT_GRAY; - final Color actual = converter.convert(Color.class, "LIGHTGRAY"); + public void testConvertingJavaColorStringWithoutColorPrefixes() { + final Color expected = Color.PINK; + final Color actual = converter.convert(Color.class, "255,175,175"); Assert.assertEquals(expected, actual); } @Test - public void testConvertingJavaColorStringFull() { - final Color expected = Color.WHITE; - final Color actual = converter.convert(Color.class, "java.awt.Color[r=255,g=255,b=255]"); + public void testConvertingJavaColorStringWithoutPackage() { + final Color expected = Color.GREEN; + final Color actual = converter.convert(Color.class, "[r=0,g=255,b=0]"); Assert.assertEquals(expected, actual); } @@ -116,46 +110,52 @@ public class ColorConverterTestCase { } @Test - public void testConvertingJavaColorStringWithoutPackage() { - final Color expected = Color.GREEN; - final Color actual = converter.convert(Color.class, "[r=0,g=255,b=0]"); + public void testConvertingLiteralHex() { + final Color expected = Color.BLUE; + final Color actual = converter.convert(Color.class, "0x0000FF"); Assert.assertEquals(expected, actual); } @Test - public void testConvertingJavaColorStringWithoutBrackets() { - final Color expected = Color.DARK_GRAY; - final Color actual = converter.convert(Color.class, "r=64,g=64,b=64"); + public void testConvertingPattern() { + final Color expected = Color.BLACK; + final Color actual = converter.convert(Color.class, "#000000"); Assert.assertEquals(expected, actual); } @Test - public void testConvertingJavaColorStringWithoutColorPrefixes() { - final Color expected = Color.PINK; - final Color actual = converter.convert(Color.class, "255,175,175"); + public void testConvertingPattern3Digit() { + final Color expected = Color.WHITE; + final Color actual = converter.convert(Color.class, "#FFF"); Assert.assertEquals(expected, actual); } - @Test(expected = ConversionException.class) - public void testInvalidNumber3() { - converter.convert(Color.class, "#FFZ"); + @Test + public void testConvertingPattern4Digit() { + final Color expected = Color.YELLOW; + final Color actual = converter.convert(Color.class, "#FF0F"); + + Assert.assertEquals(expected, actual); } - @Test(expected = ConversionException.class) - public void testInvalidNumber4() { - converter.convert(Color.class, "#FFFY"); + @Test + public void testConvertingPatternWithAlpha() { + final Color expected = Color.LIGHT_GRAY; + final Color actual = converter.convert(Color.class, "#C0C0C0FF"); + + Assert.assertEquals(expected, actual); } @Test(expected = ConversionException.class) - public void testColorBlank() { - converter.convert(Color.class, "#"); + public void testInvalidNumber3() { + converter.convert(Color.class, "#FFZ"); } @Test(expected = ConversionException.class) - public void testColorInvalidLength() { - converter.convert(Color.class, "#F"); + public void testInvalidNumber4() { + converter.convert(Color.class, "#FFFY"); } } diff --git a/src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTestCase.java index 5d9b5a87..4f1905c2 100644 --- a/src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/converters/InetAddressConverterTestCase.java @@ -65,12 +65,12 @@ public class InetAddressConverterTestCase { } @Test(expected = ConversionException.class) - public void testText() { - converter.convert(InetAddress.class, "Hello, world!"); + public void testInvalidIp() { + converter.convert(InetAddress.class, "512.512.512.512"); } @Test(expected = ConversionException.class) - public void testInvalidIp() { - converter.convert(InetAddress.class, "512.512.512.512"); + public void testText() { + converter.convert(InetAddress.class, "Hello, world!"); } } diff --git a/src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTestCase.java index 91859c90..bc423421 100644 --- a/src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/converters/LocaleConverterTestCase.java @@ -39,17 +39,17 @@ public class LocaleConverterTestCase { } @Test - public void testConvertStandardLocale() { - final Locale expected = Locale.ENGLISH; - final Locale actual = converter.convert(Locale.class, "en"); + public void testConvertCustomLocale() { + final Locale expected = Locale.forLanguageTag("en-owo"); + final Locale actual = converter.convert(Locale.class, "en-owo"); Assert.assertEquals(expected, actual); } @Test - public void testConvertCustomLocale() { - final Locale expected = Locale.forLanguageTag("en-owo"); - final Locale actual = converter.convert(Locale.class, "en-owo"); + public void testConvertStandardLocale() { + final Locale expected = Locale.ENGLISH; + final Locale actual = converter.convert(Locale.class, "en"); Assert.assertEquals(expected, actual); } diff --git a/src/test/java/org/apache/commons/beanutils2/converters/PointConverterTestCase.java b/src/test/java/org/apache/commons/beanutils2/converters/PointConverterTestCase.java index 42eb6368..33d883fd 100644 --- a/src/test/java/org/apache/commons/beanutils2/converters/PointConverterTestCase.java +++ b/src/test/java/org/apache/commons/beanutils2/converters/PointConverterTestCase.java @@ -39,17 +39,17 @@ public class PointConverterTestCase { } @Test - public void testConvertingPoint() { + public void testConvertingNoSpace() { final Point expected = new Point(100, 200); - final Point actual = converter.convert(Point.class, "(100, 200)"); + final Point actual = converter.convert(Point.class, "(100,200)"); Assert.assertEquals(expected, actual); } @Test - public void testConvertingNoSpace() { + public void testConvertingPoint() { final Point expected = new Point(100, 200); - final Point actual = converter.convert(Point.class, "(100,200)"); + final Point actual = converter.convert(Point.class, "(100, 200)"); Assert.assertEquals(expected, actual); }
