Skip to content

Commit e5503ef

Browse files
vogellaakurtakov
authored andcommitted
Migrate org.eclipse.e4.ui.tests to JUnit 5
1 parent 8567247 commit e5503ef

File tree

4 files changed

+186
-179
lines changed

4 files changed

+186
-179
lines changed

tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Require-Bundle: org.eclipse.emf.ecore.xmi;bundle-version="2.4.0",
1515
org.eclipse.e4.core.contexts,
1616
org.eclipse.e4.core.di,
1717
org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
18-
org.junit;bundle-version="3.8.2",
1918
org.eclipse.e4.ui.workbench.swt;bundle-version="0.9.0",
2019
org.eclipse.e4.ui.model.workbench;bundle-version="1.2.0";visibility:=reexport,
2120
org.eclipse.e4.core.commands;bundle-version="0.9.0",

tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EModelServicePerspectiveFindTest.java

Lines changed: 173 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
package org.eclipse.e4.ui.tests.application;
1616

17-
import static org.junit.Assert.assertEquals;
18-
import static org.junit.Assert.assertNotNull;
19-
import static org.junit.Assert.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
2020

2121
import java.util.List;
2222
import org.eclipse.e4.core.contexts.IEclipseContext;
@@ -31,178 +31,186 @@
3131
import org.eclipse.e4.ui.workbench.Selector;
3232
import org.eclipse.e4.ui.workbench.modeling.EModelService;
3333
import org.eclipse.e4.ui.workbench.modeling.ElementMatcher;
34-
import org.junit.After;
35-
import org.junit.Before;
36-
import org.junit.Test;
37-
import org.junit.runner.RunWith;
38-
import org.junit.runners.Parameterized;
39-
import org.junit.runners.Parameterized.Parameter;
40-
import org.junit.runners.Parameterized.Parameters;
34+
import org.junit.jupiter.api.AfterEach;
35+
import org.junit.jupiter.api.BeforeEach;
36+
import org.junit.jupiter.api.Nested;
37+
import org.junit.jupiter.api.Test;
4138

4239
/**
4340
* Test EModelService with its various IN_*_PERSPECTIVE and OUTSIDE_PERSPECTIVE
4441
* flags. See bug 450130.
4542
*/
46-
@RunWith(Parameterized.class)
4743
public class EModelServicePerspectiveFindTest {
48-
@Parameters
49-
public static Object[] data() {
50-
return new Object[] { true, false };
51-
}
52-
53-
/** If true, create simple app setup, otherwise a traditional setup */
54-
@Parameter
55-
public boolean simple;
56-
57-
private IEclipseContext applicationContext;
58-
private EModelService modelService;
59-
private MApplication app = null;
60-
private MWindow window;
61-
private MPerspectiveStack perspectiveStack;
62-
private MPart partA;
63-
private MPart partB;
64-
private MPart outerPart;
6544

66-
private Selector selectAll;
67-
68-
@Before
69-
public void setUp() {
70-
applicationContext = E4Application.createDefaultContext();
71-
modelService = applicationContext.get(EModelService.class);
72-
selectAll = new ElementMatcher(null, null, (String) null);
73-
if (simple) {
74-
setupSimpleApplication();
75-
} else {
76-
setupWorkbenchApplication();
45+
static abstract class AbstractPerspectiveFindTest {
46+
private IEclipseContext applicationContext;
47+
private EModelService modelService;
48+
private MApplication app = null;
49+
private MWindow window;
50+
private MPerspectiveStack perspectiveStack;
51+
private MPart partA;
52+
private MPart partB;
53+
private MPart outerPart;
54+
55+
private Selector selectAll;
56+
57+
abstract boolean isSimple();
58+
59+
@BeforeEach
60+
public void setUp() {
61+
applicationContext = E4Application.createDefaultContext();
62+
modelService = applicationContext.get(EModelService.class);
63+
selectAll = new ElementMatcher(null, null, (String) null);
64+
if (isSimple()) {
65+
setupSimpleApplication();
66+
} else {
67+
setupWorkbenchApplication();
68+
}
69+
}
70+
71+
@AfterEach
72+
public void tearDown() {
73+
applicationContext.dispose();
74+
}
75+
76+
/**
77+
* A simpler form of application setup as might be found in a new E4 app
78+
*/
79+
private void setupSimpleApplication() {
80+
app = modelService.createModelElement(MApplication.class);
81+
app.setContext(applicationContext);
82+
window = modelService.createModelElement(MWindow.class);
83+
window.setElementId("singleValidId");
84+
app.getChildren().add(window);
85+
86+
setupPerspectiveStack();
87+
window.getChildren().add(perspectiveStack);
88+
89+
outerPart = modelService.createModelElement(MPart.class);
90+
MPartStack outerPartStack = modelService.createModelElement(MPartStack.class);
91+
outerPartStack.getChildren().add(outerPart);
92+
window.getChildren().add(outerPartStack);
93+
94+
window.setSelectedElement(perspectiveStack);
95+
}
96+
97+
/**
98+
* The form of application as might be found with an E3.x-based compat layer
99+
*/
100+
private void setupWorkbenchApplication() {
101+
app = modelService.createModelElement(MApplication.class);
102+
app.setContext(applicationContext);
103+
window = modelService.createModelElement(MWindow.class);
104+
window.setElementId("singleValidId");
105+
app.getChildren().add(window);
106+
107+
MPartSashContainer topPSC = modelService.createModelElement(MPartSashContainer.class);
108+
window.getChildren().add(topPSC);
109+
110+
setupPerspectiveStack();
111+
topPSC.getChildren().add(perspectiveStack);
112+
113+
MPartStack outerPartStack = modelService.createModelElement(MPartStack.class);
114+
outerPart = modelService.createModelElement(MPart.class);
115+
outerPartStack.getChildren().add(outerPart);
116+
topPSC.getChildren().add(outerPartStack);
117+
118+
window.setSelectedElement(topPSC);
119+
topPSC.setSelectedElement(perspectiveStack);
120+
}
121+
122+
/**
123+
* Creates a perspective stack with two perspectives A and B, each with a
124+
* part stack with a single part.
125+
*/
126+
private void setupPerspectiveStack() {
127+
perspectiveStack = modelService.createModelElement(MPerspectiveStack.class);
128+
129+
MPerspective perspectiveA = modelService.createModelElement(MPerspective.class);
130+
perspectiveStack.getChildren().add(perspectiveA);
131+
MPartStack partStackA = modelService.createModelElement(MPartStack.class);
132+
perspectiveA.getChildren().add(partStackA);
133+
partA = modelService.createModelElement(MPart.class);
134+
partStackA.getChildren().add(partA);
135+
136+
MPerspective perspectiveB = modelService.createModelElement(MPerspective.class);
137+
perspectiveStack.getChildren().add(perspectiveB);
138+
MPartStack partStackB = modelService.createModelElement(MPartStack.class);
139+
perspectiveB.getChildren().add(partStackB);
140+
partB = modelService.createModelElement(MPart.class);
141+
partStackB.getChildren().add(partB);
142+
143+
perspectiveStack.setSelectedElement(perspectiveA);
144+
}
145+
146+
@Test
147+
public void testInActivePerspective() {
148+
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.IN_ACTIVE_PERSPECTIVE,
149+
selectAll);
150+
assertNotNull(elements);
151+
assertEquals(1, elements.size());
152+
assertEquals(partA, elements.get(0));
153+
}
154+
155+
@Test
156+
public void testInAnyPerspective() {
157+
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.IN_ANY_PERSPECTIVE,
158+
selectAll);
159+
assertNotNull(elements);
160+
assertEquals(2, elements.size());
161+
assertTrue(elements.contains(partA));
162+
assertTrue(elements.contains(partB));
163+
}
164+
165+
@Test
166+
public void testOuterPerspective() {
167+
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.OUTSIDE_PERSPECTIVE,
168+
selectAll);
169+
assertNotNull(elements);
170+
assertEquals(1, elements.size());
171+
assertTrue(elements.contains(outerPart));
172+
}
173+
174+
@Test
175+
public void testInTrim() {
176+
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.IN_TRIM, selectAll);
177+
assertNotNull(elements);
178+
assertEquals(0, elements.size());
179+
}
180+
181+
@Test
182+
public void testPresentation() {
183+
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.PRESENTATION, selectAll);
184+
assertNotNull(elements);
185+
assertEquals(2, elements.size());
186+
assertTrue(elements.contains(partA));
187+
assertTrue(elements.contains(outerPart));
188+
}
189+
190+
@Test
191+
public void testAnywhere() {
192+
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.ANYWHERE, selectAll);
193+
assertNotNull(elements);
194+
assertEquals(3, elements.size());
195+
assertTrue(elements.contains(partA));
196+
assertTrue(elements.contains(partB));
197+
assertTrue(elements.contains(outerPart));
77198
}
78199
}
79200

80-
@After
81-
public void tearDown() {
82-
applicationContext.dispose();
83-
}
84-
85-
/**
86-
* A simpler form of application setup as might be found in a new E4 app
87-
*/
88-
private void setupSimpleApplication() {
89-
app = modelService.createModelElement(MApplication.class);
90-
app.setContext(applicationContext);
91-
window = modelService.createModelElement(MWindow.class);
92-
window.setElementId("singleValidId");
93-
app.getChildren().add(window);
94-
95-
setupPerspectiveStack();
96-
window.getChildren().add(perspectiveStack);
97-
98-
outerPart = modelService.createModelElement(MPart.class);
99-
MPartStack outerPartStack = modelService.createModelElement(MPartStack.class);
100-
outerPartStack.getChildren().add(outerPart);
101-
window.getChildren().add(outerPartStack);
102-
103-
window.setSelectedElement(perspectiveStack);
104-
}
105-
106-
/**
107-
* The form of application as might be found with an E3.x-based compat layer
108-
*/
109-
private void setupWorkbenchApplication() {
110-
app = modelService.createModelElement(MApplication.class);
111-
app.setContext(applicationContext);
112-
window = modelService.createModelElement(MWindow.class);
113-
window.setElementId("singleValidId");
114-
app.getChildren().add(window);
115-
116-
MPartSashContainer topPSC = modelService.createModelElement(MPartSashContainer.class);
117-
window.getChildren().add(topPSC);
118-
119-
setupPerspectiveStack();
120-
topPSC.getChildren().add(perspectiveStack);
121-
122-
MPartStack outerPartStack = modelService.createModelElement(MPartStack.class);
123-
outerPart = modelService.createModelElement(MPart.class);
124-
outerPartStack.getChildren().add(outerPart);
125-
topPSC.getChildren().add(outerPartStack);
126-
127-
window.setSelectedElement(topPSC);
128-
topPSC.setSelectedElement(perspectiveStack);
129-
}
130-
131-
/**
132-
* Creates a perspective stack with two perspectives A and B, each with a
133-
* part stack with a single part.
134-
*/
135-
private void setupPerspectiveStack() {
136-
perspectiveStack = modelService.createModelElement(MPerspectiveStack.class);
137-
138-
MPerspective perspectiveA = modelService.createModelElement(MPerspective.class);
139-
perspectiveStack.getChildren().add(perspectiveA);
140-
MPartStack partStackA = modelService.createModelElement(MPartStack.class);
141-
perspectiveA.getChildren().add(partStackA);
142-
partA = modelService.createModelElement(MPart.class);
143-
partStackA.getChildren().add(partA);
144-
145-
MPerspective perspectiveB = modelService.createModelElement(MPerspective.class);
146-
perspectiveStack.getChildren().add(perspectiveB);
147-
MPartStack partStackB = modelService.createModelElement(MPartStack.class);
148-
perspectiveB.getChildren().add(partStackB);
149-
partB = modelService.createModelElement(MPart.class);
150-
partStackB.getChildren().add(partB);
151-
152-
perspectiveStack.setSelectedElement(perspectiveA);
153-
}
154-
155-
@Test
156-
public void testInActivePerspective() {
157-
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.IN_ACTIVE_PERSPECTIVE,
158-
selectAll);
159-
assertNotNull(elements);
160-
assertEquals(1, elements.size());
161-
assertEquals(partA, elements.get(0));
162-
}
163-
164-
@Test
165-
public void testInAnyPerspective() {
166-
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.IN_ANY_PERSPECTIVE,
167-
selectAll);
168-
assertNotNull(elements);
169-
assertEquals(2, elements.size());
170-
assertTrue(elements.contains(partA));
171-
assertTrue(elements.contains(partB));
172-
}
173-
174-
@Test
175-
public void testOuterPerspective() {
176-
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.OUTSIDE_PERSPECTIVE,
177-
selectAll);
178-
assertNotNull(elements);
179-
assertEquals(1, elements.size());
180-
assertTrue(elements.contains(outerPart));
181-
}
182-
183-
@Test
184-
public void testInTrim() {
185-
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.IN_TRIM, selectAll);
186-
assertNotNull(elements);
187-
assertEquals(0, elements.size());
188-
}
189-
190-
@Test
191-
public void testPresentation() {
192-
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.PRESENTATION, selectAll);
193-
assertNotNull(elements);
194-
assertEquals(2, elements.size());
195-
assertTrue(elements.contains(partA));
196-
assertTrue(elements.contains(outerPart));
201+
@Nested
202+
class Simple extends AbstractPerspectiveFindTest {
203+
@Override
204+
boolean isSimple() {
205+
return true;
206+
}
197207
}
198208

199-
@Test
200-
public void testAnywhere() {
201-
List<MPart> elements = modelService.findElements(window, MPart.class, EModelService.ANYWHERE, selectAll);
202-
assertNotNull(elements);
203-
assertEquals(3, elements.size());
204-
assertTrue(elements.contains(partA));
205-
assertTrue(elements.contains(partB));
206-
assertTrue(elements.contains(outerPart));
209+
@Nested
210+
class Workbench extends AbstractPerspectiveFindTest {
211+
@Override
212+
boolean isSimple() {
213+
return false;
214+
}
207215
}
208-
}
216+
}

0 commit comments

Comments
 (0)