blob: ab909386ece1f3f522484fb1add229cdc7c76941 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 Ashley Cambrell 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:
* Ashley Cambrell - initial API and implementation
******************************************************************************/
package org.eclipse.jface.tests.internal.databinding.internal.swt;
import org.eclipse.jface.internal.databinding.internal.swt.ComboSingleSelectionObservableValue;
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Combo;
/**
* @since 3.2
*
*/
public class ComboSingleSelectionObservableValueTest extends
AbstractSWTTestCase {
public void testSetValue() throws Exception {
Combo combo = new Combo(getShell(), SWT.NONE);
ComboSingleSelectionObservableValue observableValue = new ComboSingleSelectionObservableValue(
combo);
combo.add("Item1");
combo.add("Item2");
assertEquals(-1, combo.getSelectionIndex());
assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
Integer value = new Integer(1);
observableValue.setValue(value);
assertEquals("combo selection index", value.intValue(), combo
.getSelectionIndex());
assertEquals("observable value", value, observableValue.getValue());
assertEquals("Item2", combo.getText());
}
public void testDispose() throws Exception {
Combo combo = new Combo(getShell(), SWT.NONE);
ComboSingleSelectionObservableValue observableValue = new ComboSingleSelectionObservableValue(
combo);
combo.add("Item1");
combo.add("Item2");
assertEquals(-1, combo.getSelectionIndex());
assertEquals(-1, ((Integer) observableValue.getValue()).intValue());
combo.select(0);
notifySelection(combo);
assertEquals(0, combo.getSelectionIndex());
assertEquals(new Integer(0), observableValue.getValue());
observableValue.dispose();
combo.select(1);
notifySelection(combo);
assertEquals(1, combo.getSelectionIndex());
}
}