blob: 718688d0fdd1cd8a5694d5e90603f23f22145010 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 Brad Reynolds and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Brad Reynolds - initial API and implementation
* Matthew Hall - bug 245183
******************************************************************************/
package org.eclipse.core.tests.internal.databinding.beans;
import java.beans.PropertyDescriptor;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator;
import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
import org.eclipse.swt.widgets.Display;
/**
* @since 3.3
*/
public class BeanObservableValueDecoratorTest extends AbstractDefaultRealmTestCase {
private Bean bean;
private JavaBeanObservableValue observableValue;
private BeanObservableValueDecorator decorator;
private PropertyDescriptor propertyDescriptor;
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
bean = new Bean();
propertyDescriptor = new PropertyDescriptor("value",
Bean.class);
observableValue = new JavaBeanObservableValue(
SWTObservables.getRealm(Display.getDefault()), bean,
propertyDescriptor);
decorator = new BeanObservableValueDecorator(
observableValue, new WritableValue(bean, Object.class), observableValue
.getPropertyDescriptor());
}
public void testGetDelegate() throws Exception {
assertEquals(observableValue, decorator.getDelegate());
}
public void testGetObserved() throws Exception {
assertEquals(bean, decorator.getObserved());
}
public void testGetPropertyDescriptor() throws Exception {
assertEquals(propertyDescriptor, decorator.getPropertyDescriptor());
}
public void testEquals_IdentityCheckShortcut() {
IObservableValue delegate = new WritableValue() {
public boolean equals(Object obj) {
fail("ObservableList.equals() should return true instead of delegating to wrappedList when this == obj");
return false;
}
};
decorator = new BeanObservableValueDecorator(delegate, new WritableValue(bean, Object.class), propertyDescriptor);
assertTrue(decorator.equals(decorator));
}
public void testEquals_SameClassDelegatesToDelegateObservables() {
IObservableValue delegate = new WritableValue() {
public boolean equals(Object o) {
return o == this;
}
};
decorator = new BeanObservableValueDecorator(delegate,
new WritableValue(bean, Object.class), propertyDescriptor);
BeanObservableValueDecorator otherDecorator = new BeanObservableValueDecorator(
delegate, new WritableValue(bean, Object.class),
propertyDescriptor);
assertTrue(decorator.equals(otherDecorator));
}
}