Package org.apache.commons.beanutils

Examples of org.apache.commons.beanutils.Converter


    /**
     * Test Conversion to String
     */
    public void testConvertToString() {

        Converter converter = new CharacterConverter();

        assertEquals("Character Test", "N", converter.convert(String.class, new Character('N')));
        assertEquals("String Test",    "F", converter.convert(String.class, "FOO"));
        assertEquals("Integer Test",   "3", converter.convert(String.class, new Integer(321)));
        assertEquals("Null Test",     null, converter.convert(String.class, null));
    }
View Full Code Here


    /**
     * Test Conversion to Character
     */
    public void testConvertToCharacter() {
        Converter converter = new CharacterConverter();
        assertEquals("Character Test", new Character('N'), converter.convert(Character.class, new Character('N')));
        assertEquals("String Test",    new Character('F'), converter.convert(Character.class, "FOO"));
        assertEquals("Integer Test",   new Character('3'), converter.convert(Character.class, new Integer(321)));
    }
View Full Code Here

    /**
     * Tests whether the primitive char class can be passed as target type.
     */
    public void testConvertToChar() {
        Converter converter = new CharacterConverter();
        assertEquals("Wrong result", new Character('F'), converter.convert(Character.TYPE, "FOO"));
    }
View Full Code Here

    /**
     * Tests a conversion to character for null input if no default value is
     * provided.
     */
    public void testConvertToCharacterNullNoDefault() {
        Converter converter = new CharacterConverter();
        try {
            converter.convert(Character.class, null);
            fail("Expected a ConversionException for null value");
        } catch (Exception e) {
            // expected result
        }
    }
View Full Code Here

    /**
     * Test Conversion to Character (with default)
     */
    public void testDefault() {
        Converter converter = new CharacterConverter("C");
        assertEquals("Default Test",   new Character('C'), converter.convert(Character.class, null));
    }
View Full Code Here

    /**
     * Tries a conversion to an unsupported type.
     */
    public void testConvertToUnsupportedType() {
        Converter converter = new CharacterConverter();
        try {
            converter.convert(Integer.class, "Test");
            fail("Could convert to unsupported type!");
        } catch (ConversionException cex) {
            // expected result
        }
    }
View Full Code Here

    /**
     * Test Invalid Amounts (too big/small)
     */
    public void testInvalidAmount() {
        Converter converter = makeConverter();
        Class<?> clazz = Byte.class;

        Long min         = new Long(Byte.MIN_VALUE);
        Long max         = new Long(Byte.MAX_VALUE);
        Long minMinusOne = new Long(min.longValue() - 1);
        Long maxPlusOne  = new Long(max.longValue() + 1);

        // Minimum
        assertEquals("Minimum", new Byte(Byte.MIN_VALUE), converter.convert(clazz, min));

        // Maximum
        assertEquals("Maximum", new Byte(Byte.MAX_VALUE), converter.convert(clazz, max));

        // Too Small
        try {
            assertEquals("Minimum - 1", null, converter.convert(clazz, minMinusOne));
            fail("Less than minimum, expected ConversionException");
        } catch (Exception e) {
            // expected result
        }

        // Too Large
        try {
            assertEquals("Maximum + 1", null, converter.convert(clazz, maxPlusOne));
            fail("More than maximum, expected ConversionException");
        } catch (Exception e) {
            // expected result
        }
    }
View Full Code Here

        if (returnType.equals(Class.class)) {
            value = toQualifiedClassName(value, defaultPackage);
        }

        /* Converter lookup */
        Converter converter = ConvertUtils.lookup(returnType);
        if (converter == null && returnType.isEnum()) {
            converter = EnumerationConverter.getInstance();
        }

        if (converter != null) {
            return converter.convert(returnType, value);
        } else {
            return converter;
        }
    }
View Full Code Here

    public EnumerationConverterTestCase(String name) {
        super(name);
    }

    public void testEnum() {
        Converter converter = EnumerationConverter.getInstance();

        Thread.State expected = Thread.State.TERMINATED;
        Thread.State actual = (Thread.State) converter.convert(Thread.State.class,
                Thread.State.TERMINATED.name());
        assertEquals(expected, actual);
    }
View Full Code Here

    /**
     * Test Conversion to String
     */
    public void testConvertToString() {

        Converter converter = new CharacterConverter();

        assertEquals("Character Test", "N", converter.convert(String.class, new Character('N')));
        assertEquals("String Test",    "F", converter.convert(String.class, "FOO"));
        assertEquals("Integer Test",   "3", converter.convert(String.class, new Integer(321)));
        assertEquals("Null Test",     null, converter.convert(String.class, null));
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.beanutils.Converter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.