-
Notifications
You must be signed in to change notification settings - Fork 0
/
PolymorphicDispatcherTest.xtend
151 lines (127 loc) · 5.21 KB
/
PolymorphicDispatcherTest.xtend
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
/*******************************************************************************
* Copyright (c) 2014 RCP Vision (http://www.rcp-vision.com) 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:
* Lorenzo Bettini - Initial contribution and API
*******************************************************************************/
package org.eclipse.emf.parsley.tests
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EStructuralFeature
import org.eclipse.emf.parsley.runtime.util.PolymorphicDispatcherExtensions
import org.eclipse.emf.parsley.tests.util.EmfParsleyFixturesAndUtilitiesTestRule
import org.junit.Rule
import org.junit.Test
import static extension org.eclipse.emf.parsley.runtime.util.PolymorphicDispatcherExtensions.*
import static extension org.junit.Assert.*
class PolymorphicDispatcherTest {
var Object target;
val static IN_BASE_CLASS = "BaseClass.baseClassFeature"
val static IN_DERIVED_CLASS = "DerivedClass.baseClassFeature"
val static SPECIAL_CASE = "SpecialCase"
@Rule public extension EmfParsleyFixturesAndUtilitiesTestRule fixtures = new EmfParsleyFixturesAndUtilitiesTestRule()
static class Customize_BaseClass_baseClassFeature {
def String text_BaseClass_baseClassFeature(EStructuralFeature feature) {
return IN_BASE_CLASS
}
}
static class Customize_DerivedClass_baseClassFeature {
def String text_DerivedClass_baseClassFeature(EStructuralFeature feature) {
return IN_DERIVED_CLASS
}
}
static class Customize_TestEClassForFeatureName_FeatureNameSpecialCase {
// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=494886
def String text_TestEClassForFeatureName_EField(EStructuralFeature feature) {
return SPECIAL_CASE
}
}
static class Customize_TestEClassForFeatureName_FeatureNameSpecialCase2 {
// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=494886
def String text_TestEClassForFeatureName_eField(EStructuralFeature feature) {
return SPECIAL_CASE
}
}
new() {
// the following is useless... but it's just to have coverage
// for the protected constructor
new PolymorphicDispatcherExtensions() {
}
}
@Test
def void testGivenNoSuchMethodReturnsNull() {
target = new Object
null.assertPolymorphicInvoke(
testPackage.baseClass, testPackage.baseClass_BaseClassFeature
)
}
@Test
def void testPolymorphicInvokeWithMethodForTheContainingEClass() {
target = new Customize_BaseClass_baseClassFeature
IN_BASE_CLASS.assertPolymorphicInvoke(
testPackage.baseClass, testPackage.baseClass_BaseClassFeature
)
}
@Test
def void testPolymorphicInvokeWithBaseClassFeatureCustomizedForDerivedClass() {
// we have a customization for the feature (inherited from the base class)
// in the context of the derived class
target = new Customize_DerivedClass_baseClassFeature
IN_DERIVED_CLASS.assertPolymorphicInvoke(
testPackage.derivedClass, testPackage.baseClass_BaseClassFeature
)
}
@Test
def void testPolymorphicInvokeOnDerivedClassCustomizedForBaseClassFeature() {
// we have a customization for the feature in the context of the base class
// and we pass the derived class
target = new Customize_BaseClass_baseClassFeature
IN_BASE_CLASS.assertPolymorphicInvoke(
testPackage.derivedClass, testPackage.baseClass_BaseClassFeature
)
}
@Test
def void testPolymorphicInvokeOnDerivedDerivedClassCustomizedForBaseClassFeature() {
// we have a customization for the feature in the context of the base class
// and we pass the derived derived class
target = new Customize_BaseClass_baseClassFeature
IN_BASE_CLASS.assertPolymorphicInvoke(
testPackage.derivedDerivedClass, testPackage.baseClass_BaseClassFeature
)
}
@Test
def void testPolymorphicInvokeOnMultipleInheritanceClassCustomizedForBaseClassFeature() {
// we have a customization for the feature in the context of the base class
// and we pass a derived class with multiple inheritance (extending also the base class)
target = new Customize_BaseClass_baseClassFeature
IN_BASE_CLASS.assertPolymorphicInvoke(
testPackage.multipleInheritanceClass, testPackage.baseClass_BaseClassFeature
)
}
@Test
def void testPolymorphicInvokeWithSpecialFeatureName() {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=494886
target = new Customize_TestEClassForFeatureName_FeatureNameSpecialCase
SPECIAL_CASE.assertPolymorphicInvoke(
testPackage.testEClassForFeatureName, testPackage.testEClassForFeatureName_EField
)
}
@Test
def void testPolymorphicInvokeWithSpecialFeatureName2() {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=494886
target = new Customize_TestEClassForFeatureName_FeatureNameSpecialCase2
SPECIAL_CASE.assertPolymorphicInvoke(
testPackage.testEClassForFeatureName, testPackage.testEClassForFeatureName_EField
)
}
def private assertPolymorphicInvoke(Object expected, EClass eClass, EStructuralFeature feature) {
expected.assertEquals(polymorphicInvoke(eClass, feature))
}
def private polymorphicInvoke(EClass eClass, EStructuralFeature feature) {
target.
polymorphicInvokeBasedOnFeature(eClass, feature, "text_", feature)
}
}