1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.component;
20
21 import javax.faces.context.FacesContext;
22 import javax.faces.el.MethodBinding;
23
24 import org.apache.myfaces.trinidad.event.AttributeChangeEvent;
25 import org.apache.myfaces.trinidad.event.AttributeChangeListener;
26
27
28
29
30 public class AttributeChangeTester extends MethodBinding
31 implements AttributeChangeListener
32 {
33 public AttributeChangeTester()
34 {
35 }
36
37 public void processAttributeChange(AttributeChangeEvent event)
38 {
39 if (_methodBindingCalled)
40 throw new IllegalStateException("Method binding called before listener");
41 _listenerCalled = true;
42 }
43
44 @Override
45 public Object invoke(FacesContext context, Object params[])
46 {
47 if (params.length != 1)
48 throw new IllegalStateException("Params not of length 1");
49 if (params[0] == null)
50 throw new IllegalStateException("Event is null");
51 if (!(params[0] instanceof AttributeChangeEvent))
52 throw new IllegalStateException("Event isn't an AttributeChangeEvent");
53
54 _methodBindingCalled = true;
55 return null;
56 }
57
58 @Override
59 public Class<?> getType(FacesContext context)
60 {
61 return null;
62 }
63
64 public void verify()
65 {
66 if (!_methodBindingCalled)
67 throw new IllegalStateException("Method binding never called");
68
69 if (!_listenerCalled)
70 throw new IllegalStateException("Listener never called");
71 }
72
73 private boolean _methodBindingCalled;
74 private boolean _listenerCalled;
75 }