1   package org.springframework.richclient.form;
2   
3   import junit.framework.TestCase;
4   import org.springframework.binding.form.HierarchicalFormModel;
5   import org.springframework.binding.form.ValidatingFormModel;
6   import org.springframework.binding.form.support.DefaultFormModel;
7   
8   /**
9    * Unit tests for {@link FormModelHelper}
10   */
11  public class FormModelHelperTests extends TestCase {
12  
13      public void testGetChild() throws Exception {
14          // test the edge conditions first
15          try {
16              FormModelHelper.getChild(null, "");
17              fail("Should have thrown an IllegalArgumentException");
18          }
19          catch (IllegalArgumentException exp) {
20              // should have happened
21          }
22  
23          try {
24              FormModelHelper.getChild(new DefaultFormModel(), null);
25              fail("Should have thrown an IllegalArgumentException");
26          }
27          catch (IllegalArgumentException exp) {
28              // should have happened
29          }
30  
31          HierarchicalFormModel parentModel = new DefaultFormModel();
32          assertNull(FormModelHelper.getChild(parentModel, "testChildName"));
33  
34          final ValidatingFormModel childFormModel = FormModelHelper.createFormModel(new Object(), "testChildName");
35          parentModel.addChild(childFormModel);
36  
37          assertNotNull(FormModelHelper.getChild(parentModel, "testChildName"));
38          assertNull(FormModelHelper.getChild(parentModel, "bogusChildName"));
39      }
40  
41  }