001 /* 002 * Copyright 2002-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.richclient.core; 017 018 import java.beans.PropertyChangeEvent; 019 020 import org.easymock.IArgumentMatcher; 021 import org.springframework.util.ObjectUtils; 022 023 /** 024 * Custom ArgumentMatcher for EasyMock. 025 * 026 * @author Peter De Bruycker 027 */ 028 public class PropertyChangeEventArgumentMatcher implements IArgumentMatcher { 029 030 private PropertyChangeEvent expected; 031 032 public PropertyChangeEventArgumentMatcher(PropertyChangeEvent expected) { 033 this.expected = expected; 034 } 035 036 public void appendTo(StringBuffer sb) { 037 sb.append("java.beans.PropertyChangeEvent["); 038 039 sb.append("source=").append(expected.getSource()).append(", "); 040 sb.append("propertyName=").append(expected.getPropertyName()).append(", "); 041 sb.append("oldValue=").append(expected.getOldValue()).append(", "); 042 sb.append("newValue=").append(expected.getNewValue()).append(""); 043 044 sb.append("]"); 045 } 046 047 public boolean matches(Object value) { 048 if (!(value instanceof PropertyChangeEvent)) { 049 return false; 050 } 051 052 PropertyChangeEvent actual = (PropertyChangeEvent) value; 053 054 boolean matches = true; 055 matches = matches && actual.getSource().equals(expected.getSource()); 056 matches = matches && actual.getPropertyName().equals(expected.getPropertyName()); 057 matches = matches && ObjectUtils.nullSafeEquals(actual.getOldValue(), expected.getOldValue()); 058 matches = matches && ObjectUtils.nullSafeEquals(actual.getNewValue(), expected.getNewValue()); 059 060 return matches; 061 } 062 063 }