public void testBListtoBArray() throws Exception { ArrayList<B> input = new ArrayList<B>(); B b = new B(); b.setData(0); input.add(b); b = new B(); b.setData(1); input.add(b); b = new B(); b.setData(2); input.add(b); B[] output = new B[0]; if (ConvertUtils.isConvertable(input, output.getClass())) { output = (B[]) ConvertUtils.convert(input, output.getClass()); } assertTrue(output.length == 3); assertTrue(output[0].getData() == 0); assertTrue(output[1].getData() == 1); assertTrue(output[2].getData() == 2); }
/** * Negative test...can't convert List of B into C[] * * @throws Exception */ public void testBListtoCArray() throws Exception { ArrayList<B> input = new ArrayList<B>(); B b = new B(); b.setData(0); input.add(b); b = new B(); b.setData(1); input.add(b); b = new B(); b.setData(2); input.add(b); C[] output = new C[0]; boolean success = false; try { output = (C[]) ConvertUtils.convert(input, output.getClass()); } catch (WebServiceException e) { assertTrue(e.getMessage().contains("Cannot convert")); success = true; } assertTrue(success); }