1   /*
2    * Copyright 2002-2007 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package org.springframework.binding.value.support;
17  
18  import javax.swing.event.ListDataEvent;
19  
20  import org.easymock.IArgumentMatcher;
21  
22  /**
23   * Custom ArgumentMatcher for EasyMock.
24   * 
25   * @author Peter De Bruycker
26   */
27  public class ListDataEventArgumentMatcher implements IArgumentMatcher {
28  
29  	private ListDataEvent expected;
30  
31  	public ListDataEventArgumentMatcher(ListDataEvent expected) {
32  		this.expected = expected;
33  	}
34  	
35  	public void appendTo(StringBuffer sb) {
36  		sb.append("javax.swing.event.ListDataEvent[");
37  		
38  		sb.append("type=").append(expected.getType()).append(", ");
39  		sb.append("index0=").append(expected.getIndex0()).append(", ");
40  		sb.append("index1=").append(expected.getIndex1()).append(", ");
41  		
42  		sb.append("]");
43  	}
44  
45  	public boolean matches(Object value) {
46  		if (!(value instanceof ListDataEvent)) {
47  			return false;
48  		}
49  
50  		ListDataEvent actual = (ListDataEvent) value;
51  
52  		boolean matches = true;
53  		matches = matches && actual.getSource().equals(expected.getSource());
54  		matches = matches && actual.getType() == expected.getType();
55  		matches = matches && actual.getIndex0() == expected.getIndex0();
56  		matches = matches && actual.getIndex1() == expected.getIndex1();
57  
58  		return matches;
59  	}
60  
61  }