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
|
/*******************************************************************************
* Copyright (c) 2005-2009 itemis AG (http://www.itemis.eu) 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
*
*******************************************************************************/
package org.eclipse.xtend.typesystem.baseimpl;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.internal.xtend.type.baseimpl.TypesComparator;
import org.eclipse.internal.xtend.type.impl.java.JavaMetaModel;
import org.eclipse.internal.xtend.type.impl.java.beans.JavaBeansStrategy;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.typesystem.Type;
import org.eclipse.xtend.typesystem.javabeansimpl.test.TypeA;
import org.eclipse.xtend.typesystem.javabeansimpl.test.TypeB;
/**
* @author Sven Efftinge (http://www.efftinge.de)
* @author Arno Haase
*/
public class TypesComparatorTest extends TestCase {
ExecutionContextImpl ec;
private JavaMetaModel mm;
@Override
protected void setUp() throws Exception {
ec = new ExecutionContextImpl();
mm = new JavaMetaModel("asdf", new JavaBeansStrategy());
ec.registerMetaModel(mm);
}
public final void testNullParams() {
final Comparator<List<? extends Type>> c = new TypesComparator();
final Type aType = mm.getTypeForName(TypeA.class.getName());
try {
c.compare(null, null);
fail();
} catch (final Exception e) {
}
try {
c.compare(null, l(aType));
fail();
} catch (final Exception e) {
}
try {
c.compare(l(aType), null);
fail();
} catch (final Exception e) {
}
}
public final void testSimple() {
final Comparator<List<? extends Type>> c = new TypesComparator();
final Type aType = mm.getTypeForName(TypeA.class.getName()); // TODO
final Type bType = mm.getTypeForName(TypeB.class.getName()); // TODO
assertTrue(c.compare(l(aType), l(aType)) == 0);
assertTrue(c.compare(l(aType), l(bType)) > 0);
assertTrue(c.compare(l(bType), l(aType)) < 0);
}
public final void testComplex() {
final Comparator<List<? extends Type>> c = new TypesComparator();
final Type aType = mm.getTypeForName(TypeA.class.getName()); // TODO
final Type bType = mm.getTypeForName(TypeB.class.getName()); // TODO
assertTrue(c.compare(l(aType, aType), l(aType, aType)) == 0);
assertTrue(c.compare(l(aType, aType), l(bType, aType)) > 0);
assertTrue(c.compare(l(aType, aType), l(aType, bType)) > 0);
assertTrue(c.compare(l(bType, aType), l(aType, aType)) < 0);
assertTrue(c.compare(l(aType, bType), l(aType, aType)) < 0);
}
private List<? extends Type> l(final Type a) {
final List<Type> l = new ArrayList<Type>();
l.add(a);
return l;
}
private List<? extends Type> l(final Type a, final Type b) {
final List<Type> l = new ArrayList<Type>();
l.add(a);
l.add(b);
return l;
}
}
|