001 package org.springframework.richclient.form; 002 003 import junit.framework.TestCase; 004 import org.springframework.binding.form.HierarchicalFormModel; 005 import org.springframework.binding.form.ValidatingFormModel; 006 import org.springframework.binding.form.support.DefaultFormModel; 007 008 /** 009 * Unit tests for {@link FormModelHelper} 010 */ 011 public class FormModelHelperTests extends TestCase { 012 013 public void testGetChild() throws Exception { 014 // test the edge conditions first 015 try { 016 FormModelHelper.getChild(null, ""); 017 fail("Should have thrown an IllegalArgumentException"); 018 } 019 catch (IllegalArgumentException exp) { 020 // should have happened 021 } 022 023 try { 024 FormModelHelper.getChild(new DefaultFormModel(), null); 025 fail("Should have thrown an IllegalArgumentException"); 026 } 027 catch (IllegalArgumentException exp) { 028 // should have happened 029 } 030 031 HierarchicalFormModel parentModel = new DefaultFormModel(); 032 assertNull(FormModelHelper.getChild(parentModel, "testChildName")); 033 034 final ValidatingFormModel childFormModel = FormModelHelper.createFormModel(new Object(), "testChildName"); 035 parentModel.addChild(childFormModel); 036 037 assertNotNull(FormModelHelper.getChild(parentModel, "testChildName")); 038 assertNull(FormModelHelper.getChild(parentModel, "bogusChildName")); 039 } 040 041 }