String[] values = new String[2];
values[0] = "foo";
values[1] = "bar";
Element e = createElement("bag", null);
e.addElement("element").addElement("str").addText(values[0]);
e.addElement("element").addElement("str").addText(values[1]);
wrapper.setElement(e);
// String Array
String[] converted = (String[]) wrapper.convert(String[].class);
assert values.length == converted.length;
assertEquals(values[0], converted[0]);
assertEquals(values[1], converted[1]);
// List
List convertedList = (List) wrapper.convert(List.class);
assert values.length == convertedList.size();
assertEquals(values[0], convertedList.get(0));
assertEquals(values[1], convertedList.get(1));
// List<String> (Generic type)
// Isn't there an easier way of getting a generic type than this??
Type t = RemotingTest.class.getMethod("dummy").getGenericReturnType();
List<String> stringList = (List<String>) wrapper.convert(t);
assert values.length == stringList.size();
assertEquals(values[0], stringList.get(0));
assertEquals(values[1], stringList.get(1));
// Set
Set s = (Set) wrapper.convert(Set.class);
assert values.length == s.size();
assert s.contains(values[0]);
assert s.contains(values[1]);
// Queue
Queue q = (Queue) wrapper.convert(Queue.class);
assert values.length == q.size();
assert q.contains(values[0]);
assert q.contains(values[1]);
// Concrete class
ArrayList l = (ArrayList) wrapper.convert(ArrayList.class);
assert values.length == l.size();
assertEquals(values[0], l.get(0));
assertEquals(values[1], l.get(1));
try
{
// This should throw a ConversionException
wrapper.convert(InvalidList.class);
assert false;
}
catch (ConversionException ex)
{
}
t = RemotingTest.class.getMethod("dummyInvalid").getGenericReturnType();
try
{
// This should throw a ConversionException also
wrapper.convert(t);
assert false;
}
catch (ConversionException ex)
{
}
int[] intValues = new int[2];
intValues[0] = 44444;
intValues[1] = 55555;
e = createElement("bag", null);
e.addElement("element").addElement("number").addText("" + intValues[0]);
e.addElement("element").addElement("number").addText("" + intValues[1]);
wrapper.setElement(e);
// int Array
int[] convertedInts = (int[]) wrapper.convert(int[].class);
assert intValues.length == convertedInts.length;