I was creating a test case for the property model to do some mind
exercises, and came up with the following testcase:

public class PropertyModelTest extends WicketTestCase
{
        /**
         * Interface for testing the property assignment with an 
<code>null</code>
         * interface property.
         */
        public static interface IAddress
        {
        }

        /**
         * Abstract class for testing the property assignment with an
         * <code>null</code> abstract class property.
         */
        public static abstract class AbstractAddress implements IAddress
        {
                /** street field for assignment in property expressions. */
                public String street;
        }

        /**
         * Concrete class for testing the property assignment with an
         * <code>null</code> concrete class property.
         */
        public static class ConcreteAddress extends AbstractAddress
        {
        }

        /**
         * Person class for keeping the various different references for use in 
the
         * test cases.
         */
        public static class Person
        {
                /** tests a <code>null</code> interface property. */
                public IAddress interfaceAddress;
                /** tests a <code>null</code> abstract class property. */
                public AbstractAddress abstractAddress;
                /** tests a <code>null</code> concrete class property. */
                public ConcreteAddress concreteAddress;
                /** tests a <code>null</code> final concrete class property. */
                public final ConcreteAddress finalAddress = null;
        }

        /**
         * Tests setting a value on a [EMAIL PROTECTED] PropertyModel} when a 
final (constant!)
         * property is <code>null</code> and a concrete type. This should end in
         * an exception because Wicket can't assign to the property, since it is
         * final.
         */
        public void testSetWithNullPathFinal()
        {
                Person person = new Person();
                PropertyModel model = new PropertyModel(person, 
"finalAddress.street");
                try
                {
                        model.setObject("foo");
                        fail("Expected exception");
                }
                catch (WicketRuntimeException wre)
                {
                        // ok!
                }
        }
}

What do you think? Is this test case correct? If so, should we improve
the JDK that final fields can be assigned using reflection?

Martijn

-- 
Wicket joins the Apache Software Foundation as Apache Wicket
Apache Wicket 1.3.0-beta2 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta2/

Reply via email to