Skip to main content
summaryrefslogtreecommitdiffstats
blob: ac9c6d7a8ee16c598d20e7dca9bfb1d3671d8f38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 * 
 * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
 * for its Fraunhofer Institute and Computer Architecture and Software
 * Technology (FIRST), Berlin, Germany and Technical University Berlin,
 * Germany.
 * 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 * 
 * Contributors:
 * 	  Fraunhofer FIRST - Initial API and implementation
 * 	  Technical University Berlin - Initial API and implementation
 **********************************************************************/
package org.eclipse.objectteams.otdt.tests.superhierarchy;

import junit.framework.Test;

import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.objectteams.otdt.core.hierarchy.OTTypeHierarchies;
import org.eclipse.objectteams.otdt.internal.core.PhantomType;
import org.eclipse.objectteams.otdt.tests.hierarchy.FileBasedHierarchyTest;

/**
 * 
 * @author Michael Krueger (mkr)
 * @version $Id: OTSuperTypeHierarchyTest011.java 23494 2010-02-05 23:06:44Z stephan $ 
 * 
 */
public class OTSuperTypeHierarchyTest011 extends FileBasedHierarchyTest
{
    
    private IType _T10;
    private IType _T21;    

    private IType _T21T11T0R1;
    private IType _phantom_T21T11T0R2;

    private IType _T10T0R1;
    private IType _T10T0R2;
    
	private IType _objectType;

    public OTSuperTypeHierarchyTest011(String name)
	{
		super(name);
	}
	
	public static Test suite()
	{
		if (true)
		{
			return new Suite(OTSuperTypeHierarchyTest011.class);
		}
		@SuppressWarnings("unused")
		junit.framework.TestSuite suite = 
			new Suite(OTSuperTypeHierarchyTest011.class.getName());
		return suite;
	}
	
	public void setUpSuite() throws Exception
	{
		setTestProjectDir("Hierarchy");
		super.setUpSuite();
		
		String srcFolder = "src";
		String pkg = "test011";
		
		_T10 = getType(getTestProjectDir(), srcFolder, pkg, "T10");

        _T21 =  getType(getTestProjectDir(), srcFolder, pkg, "T21");
                
        _objectType =
            getType(getTestProjectDir(), "rt.jar", "java.lang", "Object");

        _T21T11T0R1 = getRole(_T21, "T21.T11.T0.R1");
        _T10T0R1 = getRole(_T10, "T10.T0.R1");
        _T10T0R2 = getRole(_T10, "T10.T0.R2");
        _phantom_T21T11T0R2 = new PhantomType(getRole(_T21, "T21.T11.T0"), _T10T0R2);
    }
    
	public void testCreation()
	{
		assertCreation(_T10);
        assertCreation(_T21);
        assertCreation(_T21T11T0R1);
        assertCreation(_phantom_T21T11T0R2);        
        assertCreation(_T10T0R1);
        assertCreation(_T10T0R2);
    }

    public void testGetTSuperTypes_T21T11T0R1() throws JavaModelException
    {
        _focusType = _T21T11T0R1;
        _testObj = createSuperTypeHierarchy(_focusType);
    
        IType[] actual = OTTypeHierarchies.getInstance().getTSuperTypes(_testObj, _focusType);
        IType[] expected = new IType[] { _T10T0R1 };
   
        assertEquals(expected.length, actual.length);        
        assertTrue(compareTypes(expected, actual));        
    }

    
    public void testGetSuperclasses_T21T11T0R1() throws JavaModelException
    {
        _focusType = _T21T11T0R1;
        _testObj = createSuperTypeHierarchy(_focusType);
   
        IType[] actual = OTTypeHierarchies.getInstance().getSuperclasses(_testObj, _focusType);
        IType[] expected = new IType[] { _T10T0R1,
                                         _T10T0R2 };
   
        assertEquals(expected.length, actual.length);        
        assertTrue(compareTypes(expected, actual));        
    }

    public void testGetAllClasses_T21T11T0R1() throws JavaModelException
    {
        _focusType = _T21T11T0R1;
        _testObj = createSuperTypeHierarchy(_focusType);
        
        IType[] actual = _testObj.getAllClasses();
        IType[] expected = new IType[] { _T21T11T0R1,
        								 _T10T0R1,
										 _T10T0R2,
										 _objectType };
   
        assertEquals(expected.length, actual.length);        
        assertTrue(compareTypes(expected, actual));        
    }

    public void testGetAllClasses_T21T11T0R1_phantom() throws JavaModelException
    {
        _focusType = _T21T11T0R1;
        _testObj = createSuperTypeHierarchy(_focusType);
        OTTypeHierarchies.getInstance().setPhantomMode(_testObj, true);
        
        IType[] actual = _testObj.getAllClasses();
        IType[] expected = new IType[] { _T21T11T0R1,
        		 						 _phantom_T21T11T0R2,
        								 _T10T0R1,
										 _T10T0R2,
										 _objectType };
   
        assertEquals(expected.length, actual.length);        
        assertTrue(compareTypes(expected, actual)); 
    }
    
    public void testGetAllClasses_T10T0R1() throws JavaModelException
    {
        _focusType = _T10T0R1;
        _testObj = createSuperTypeHierarchy(_focusType);
        
        IType[] actual = _testObj.getAllClasses();
        IType[] expected = new IType[] { _T10T0R1,
										 _T10T0R2,
										 _objectType };
   
        assertEquals(expected.length, actual.length);        
        assertTrue(compareTypes(expected, actual));        
    }
}

Back to the top