1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
38
39
40 public class UIComponentTest extends UIComponentTestBase
41 {
42
43
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
68
69
70
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 }