package com.thoughtworks.xstream.test; import java.util.ArrayList; import java.util.List; import junit.framework.AssertionFailedError; import junit.framework.TestCase; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.Annotations; import com.thoughtworks.xstream.annotations.XStreamImplicit; public class XStreamImplicitUntypedTest extends TestCase { /* * Bug with @XStreamImplicit: * * Configuring a class with an untyped Collection that is annotated with * @XStreamImplicit throws an unexpected NullPointerException. Indicate in * documentation and through initialization exception that @XStreamImplicit * is only available for typed Collections. */ public void testNoTypeCollections() { final XStream xs = new XStream(); assertNoException(new Runner() { public Object run() { Annotations.configureAliases(xs, Untyped.class); return "Success"; } }); } private static class Untyped { @XStreamImplicit private List list = new ArrayList(); public Untyped() { list.add("1"); } } /** * Determine whether the given code executes without throwing an * Exception. * * @param r The code to execute. * @return The object returned by the code. */ private T assertNoException(Runner r) { try { return r.run(); } catch (Exception ex) { throw new AssertionFailedError("expected no exception but caught " + ex); } } /** * Encapsulates a piece of code. * * @param The return type of the code. */ private static interface Runner { public T run(); } }