All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jdesktop.test.matchers.PropertyChangeEventMatcher Maven / Gradle / Ivy

Go to download

Code and classes to support testing SwingX. Classes contained in this module are for internal SwingX use only.

There is a newer version: 1.6.5-1
Show newest version
package org.jdesktop.test.matchers;

import static org.hamcrest.CoreMatchers.is;

import java.beans.PropertyChangeEvent;

import org.hamcrest.Description;
import org.mockito.ArgumentMatcher;

@SuppressWarnings("nls")
class PropertyChangeEventMatcher extends ArgumentMatcher {
    private final String propertyName;
    private final Object oldValue;
    private final Object newValue;
    
    public PropertyChangeEventMatcher(String propertyName, Object oldValue, Object newValue) {
        this.propertyName = propertyName;
        this.oldValue = oldValue;
        this.newValue = newValue;
    }
    
    @Override
    public boolean matches(Object argument) {
        if (argument instanceof PropertyChangeEvent) {
            PropertyChangeEvent pce = (PropertyChangeEvent) argument;
            
            boolean result = propertyName.equals(pce.getPropertyName());
            result &= oldValue == null || pce.getOldValue() == null || is(oldValue).matches(pce.getOldValue()); 
            result &= newValue == null || pce.getNewValue() == null || is(newValue).matches(pce.getNewValue());
            
            return result;
        }
        
        return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void describeTo(Description description) {
        super.describeTo(description);
        description.appendText(" " + propertyName);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy