public void testStringArrayToNumber(){
  IntegerConverter intConverter=new IntegerConverter();
  ArrayConverter arrayConverter=new ArrayConverter(int[].class,intConverter);
  String[] array=new String[]{"10","  11","12  ","  13  "};
  ArrayList list=new ArrayList();
  for (int i=0; i < array.length; i++) {
    list.add(array[i]);
  }
  String msg=null;
  int[] expectedInt=new int[]{10,11,12,13};
  Integer[] expectedInteger=new Integer[]{new Integer(expectedInt[0]),new Integer(expectedInt[1]),new Integer(expectedInt[2]),new Integer(expectedInt[3])};
  try {
    msg="String[] --> int[]";
    checkArray(msg,expectedInt,arrayConverter.convert(int[].class,array));
  }
 catch (  Exception e) {
    fail(msg + " failed " + e);
  }
  try {
    msg="String[] --> Integer[]";
    checkArray(msg,expectedInteger,arrayConverter.convert(Integer[].class,array));
  }
 catch (  Exception e) {
    fail(msg + " failed " + e);
  }
  try {
    msg="List --> int[]";
    checkArray(msg,expectedInt,arrayConverter.convert(int[].class,list));
  }
 catch (  Exception e) {
    fail(msg + " failed " + e);
  }
  try {
    msg="List --> Integer[]";
    checkArray(msg,expectedInteger,arrayConverter.convert(Integer[].class,list));
  }
 catch (  Exception e) {
    fail(msg + " failed " + e);
  }
}

public void testStringArrayToNumber ( ) { IntegerConverter intConverter = new IntegerConverter ( ) ; ArrayConverter arrayConverter = new ArrayConverter ( int [ ] . class , intConverter ) ; String [ ] array = new String [ ] { "10" , "  11" , "12  " , "  13  " } ; ArrayList list = new ArrayList ( ) ; for ( int i = 0 ; i < array . length ; i ++ ) { list . add ( array [ i ] ) ; } String msg = null ; int [ ] expectedInt = new int [ ] { 10 , 11 , 12 , 13 } ; Integer [ ] expectedInteger = new Integer [ ] { new Integer ( expectedInt [ 0 ] ) , new Integer ( expectedInt [ 1 ] ) , new Integer ( expectedInt [ 2 ] ) , new Integer ( expectedInt [ 3 ] ) } ; try { msg = "String[] --> int[]" ; checkArray ( msg , expectedInt , arrayConverter . convert ( int [ ] . class , array ) ) ; } catch ( Exception e ) { fail ( msg + " failed " + e ) ; } try { msg = "String[] --> Integer[]" ; checkArray ( msg , expectedInteger , arrayConverter . convert ( Integer [ ] . class , array ) ) ; } catch ( Exception e ) { fail ( msg + " failed " + e ) ; } try { msg = "List --> int[]" ; checkArray ( msg , expectedInt , arrayConverter . convert ( int [ ] . class , list ) ) ; } catch ( Exception e ) { fail ( msg + " failed " + e ) ; } try { msg = "List --> Integer[]" ; checkArray ( msg , expectedInteger , arrayConverter . convert ( Integer [ ] . class , list ) ) ; } catch ( Exception e ) { fail ( msg + " failed " + e ) ; } }
test converting a string [ ] to integer array ( with leading / trailing whitespace )
