View | Details | Raw Unified | Return to bug 21013 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI Tests/org/eclipse/ui/tests/propertysheet/PropertySheetTestSuite.java (+1 lines)
Lines 31-35 Link Here
31
	 */
31
	 */
32
	public PropertySheetTestSuite() {
32
	public PropertySheetTestSuite() {
33
		addTest(new TestSuite(PropertySheetAuto.class));
33
		addTest(new TestSuite(PropertySheetAuto.class));
34
        addTest(new TestSuite(ComboBoxPropertyDescriptorTest.class));
34
	}
35
	}
35
}
36
}
(-)Eclipse (+96 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.tests.propertysheet;
12
13
import junit.framework.TestCase;
14
15
import org.eclipse.jface.viewers.ILabelProvider;
16
import org.eclipse.jface.viewers.LabelProvider;
17
18
import org.eclipse.ui.views.properties.ComboBoxLabelProvider;
19
import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
20
21
/**
22
 * Test for new functionality pertaining to Bug 21013.
23
 * 
24
 * @since 3.0
25
 */
26
public class ComboBoxPropertyDescriptorTest extends TestCase {
27
28
    private String ID = "ID"; //$NON-NLS-1$
29
    private String NAME = "NAME"; //$NON-NLS-1$
30
    
31
    private String [] values = {"One", "Two", "Three"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
32
    private ComboBoxPropertyDescriptor descriptor;
33
    
34
    /* (non-Javadoc)
35
     * @see junit.framework.TestCase#setUp()
36
     */
37
    protected void setUp() throws Exception {
38
        super.setUp();
39
        descriptor = new ComboBoxPropertyDescriptor(ID, NAME, values);
40
    }
41
42
    /* (non-Javadoc)
43
     * @see junit.framework.TestCase#tearDown()
44
     */
45
    protected void tearDown() throws Exception {
46
        super.tearDown();
47
    }
48
49
    /**
50
     * Tests the case where the user does not set an ILabelProvider.
51
     */
52
    public void testGetDefaultLabelProvider() {        
53
        ILabelProvider provider = descriptor.getLabelProvider();
54
        assertEquals("Default label provider is of the wrong type", //$NON-NLS-1$ 
55
                ComboBoxLabelProvider.class, 
56
                provider.getClass());
57
        
58
        for (int i = 0; i < values.length; i++) {
59
            String expected = values[i];
60
            assertEquals("Wrong label provided", //$NON-NLS-1$
61
                    expected,
62
                    provider.getText(new Integer(i)));
63
            
64
        }
65
        
66
        testWrongLabel(provider, new Object());
67
        testWrongLabel(provider, null);
68
        testWrongLabel(provider, new Integer(-1));
69
        testWrongLabel(provider, new Integer(values.length));
70
    }
71
72
    /**
73
     * Tests that a bad element object (an Integer outside the accepted range, 
74
     * null or an other Object) returns the empty String.
75
     * @param provider the provider to test against.
76
     * @param element the element to test.
77
     */
78
    public void testWrongLabel(ILabelProvider provider, Object element) {
79
        assertEquals("Wrong label provided in bad case", //$NON-NLS-1$
80
                "", //$NON-NLS-1$
81
                provider.getText(element));        
82
    }
83
    
84
    /**
85
     * Tests the case where the user sets their own ILabelProvider.
86
     */
87
    public void testSetGetLabelProvider() {
88
        ILabelProvider provider = new LabelProvider();
89
        descriptor.setLabelProvider(provider);
90
        ILabelProvider descProvider = descriptor.getLabelProvider();
91
        assertSame("Wrong label provider", //$NON-NLS-1$
92
                provider,
93
                descProvider);
94
    }
95
96
}

Return to bug 21013