View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package javax.faces.component;
20  
21  import java.lang.reflect.Method;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import javax.el.ValueExpression;
28  import javax.faces.context.FacesContext;
29  
30  import static org.apache.myfaces.Assert.*;
31  import org.apache.myfaces.TestRunner;
32  import static org.easymock.EasyMock.*;
33  import static org.testng.Assert.*;
34  import org.testng.annotations.Test;
35  
36  /**
37   * @author Mathias Broekelmann (latest modification by $Author: skitching $)
38   * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Sun, 13 Jul 2008) $
39   */
40  public class UIComponentTest extends UIComponentTestBase
41  {
42      /**
43       * Test method for {@link javax.faces.component.UIComponent#getFacetCount()}.
44       */
45      @Test
46      public void testGetFacetCount() throws Exception
47      {
48          UIComponent component = _mocksControl.createMock(UIComponent.class, new Method[] { UIComponent.class
49                  .getDeclaredMethod("getFacets", null) });
50          Map<String, UIComponent> map = new HashMap<String, UIComponent>();
51          map.put("xxx1", new UIInput());
52          map.put("xxx2", new UIInput());
53          map.put("xxx3", new UIInput());
54          expect(component.getFacets()).andReturn(map);
55          _mocksControl.replay();
56          assertEquals(3, component.getFacetCount());
57          _mocksControl.verify();
58  
59          _mocksControl.reset();
60          expect(component.getFacets()).andReturn(null);
61          _mocksControl.replay();
62          assertEquals(0, component.getFacetCount());
63          _mocksControl.verify();
64      }
65  
66      /**
67       * Test method for
68       * {@link javax.faces.component.UIComponent#getContainerClientId(javax.faces.context.FacesContext)}.
69       * 
70       * @throws Exception
71       */
72      @Test
73      public void testGetContainerClientId() throws Exception
74      {
75          Collection<Method> mockedMethods = new ArrayList<Method>();
76          Class<UIComponent> clazz = UIComponent.class;
77          mockedMethods.add(clazz.getDeclaredMethod("getClientId", new Class[] { FacesContext.class }));
78          final UIComponent testimpl = _mocksControl.createMock(clazz, mockedMethods.toArray(new Method[mockedMethods
79                  .size()]));
80          _mocksControl.checkOrder(true);
81  
82          assertException(NullPointerException.class, new TestRunner()
83          {
84              public void run() throws Throwable
85              {
86                  testimpl.getContainerClientId(null);
87              }
88          });
89  
90          expect(testimpl.getClientId(same(_facesContext))).andReturn("xyz");
91          _mocksControl.replay();
92          assertEquals("xyz", testimpl.getContainerClientId(_facesContext));
93          _mocksControl.verify();
94      }
95  }