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 org.apache.myfaces.trinidad.component;
20  
21  import javax.el.ELContext;
22  import javax.el.MethodExpression;
23  import javax.el.MethodInfo;
24  
25  import org.apache.myfaces.trinidad.event.AttributeChangeEvent;
26  import org.apache.myfaces.trinidad.event.AttributeChangeListener;
27  
28  /**
29   * Utility class for testing out AttributeChange events.
30   */
31  public class AttributeChangeTester extends MethodExpression
32   implements AttributeChangeListener
33  {
34    public AttributeChangeTester()
35    {
36    }
37  
38    public void processAttributeChange(AttributeChangeEvent event)
39    {
40      if (_methodBindingCalled)
41        throw new IllegalStateException("Method binding called before listener");
42      _listenerCalled = true;
43    }
44  
45    public MethodInfo getMethodInfo(ELContext context)
46    {
47      return null;
48    }
49  
50    @Override
51    public Object invoke(ELContext context, Object params[])
52    {
53      if (params.length != 1)
54        throw new IllegalStateException("Params not of length 1");
55      if (params[0] == null)
56        throw new IllegalStateException("Event is null");
57      if (!(params[0] instanceof AttributeChangeEvent))
58        throw new IllegalStateException("Event isn't an AttributeChangeEvent");
59  
60      _methodBindingCalled = true;
61      return null;
62    }
63  
64    public String getExpressionString()
65    {
66      return null;
67    }
68  
69    public boolean isLiteralText()
70    {
71      return false;
72    }
73  
74    public int hashCode()
75    {
76      return 0;
77    }
78  
79    public boolean equals(Object o)
80    {
81      return o == this;
82    }
83  
84    public void verify()
85    {
86      if (!_methodBindingCalled)
87        throw new IllegalStateException("Method binding never called");
88  
89      if (!_listenerCalled)
90        throw new IllegalStateException("Listener never called");
91    }
92  
93    private boolean _methodBindingCalled;
94    private boolean _listenerCalled;
95  }