FileDocCategorySizeDatePackage
StrutsTypeConverterTest.javaAPI DocExample4028Mon Jul 23 13:26:26 BST 2007org.apache.struts2.util

StrutsTypeConverterTest

public class StrutsTypeConverterTest extends TestCase
Test case for Struts Type Converter.

Fields Summary
Constructors Summary
Methods Summary
public voidtestConvertFromString()
Typically form html -> Struts

throws
Exception

        InternalStrutsTypeConverter strutsTypeConverter = new InternalStrutsTypeConverter();
        strutsTypeConverter.convertValue(new HashMap(), "12/12/1997", Date.class);
        assertTrue(strutsTypeConverter.isConvertFromString);
        assertTrue(strutsTypeConverter.objToBeConverted instanceof String[]);
        assertEquals(((String[])strutsTypeConverter.objToBeConverted).length, 1);
    
public voidtestConvertFromStringInArrayForm()
Typically from html -> Struts (in array due to the nature of html, param being able to have many values).

throws
Exception

        InternalStrutsTypeConverter strutsTypeConverter = new InternalStrutsTypeConverter();
        strutsTypeConverter.convertValue(new HashMap(), new String[] { "12/12/1997", "1/1/1977" }, Date.class);
        assertTrue(strutsTypeConverter.isConvertFromString);
        assertTrue(strutsTypeConverter.objToBeConverted instanceof String[]);
        assertEquals(((String[])strutsTypeConverter.objToBeConverted).length, 2);
    
public voidtestConvertToString()
Typically form Struts -> html

throws
Exception

        InternalStrutsTypeConverter strutsTypeConverter = new InternalStrutsTypeConverter();
        strutsTypeConverter.convertValue(new HashMap(), "", String.class);
        assertTrue(strutsTypeConverter.isConvertToString);
        assertEquals(strutsTypeConverter.objToBeConverted, "");
    
public voidtestFallbackConversion()

        InternalStrutsTypeConverter strutsTypeConverter = new InternalStrutsTypeConverter();
        strutsTypeConverter.convertValue(new HashMap(), new Object(), Date.class);
        assertTrue(strutsTypeConverter.fallbackConversion);