Skip to content

Commit de18285

Browse files
committed
Make E4 EMF XPath tests more explicit and apply minor clean-ups
1 parent 815c9c0 commit de18285

File tree

3 files changed

+27
-35
lines changed

3 files changed

+27
-35
lines changed

tests/org.eclipse.e4.emf.xpath.test/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-17
99
Export-Package: org.eclipse.e4.emf.xpath.test.model.xpathtest,
1010
org.eclipse.e4.emf.xpath.test.model.xpathtest.impl,
1111
org.eclipse.e4.emf.xpath.test.model.xpathtest.util
12+
Import-Package: org.assertj.core.api;version="[3.27.0,4.0.0)"
1213
Require-Bundle: org.eclipse.e4.ui.model.workbench,
1314
org.eclipse.e4.emf.xpath,
1415
org.junit,

tests/org.eclipse.e4.emf.xpath.test/src/org/eclipse/e4/emf/xpath/test/ExampleQueriesApplicationTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 vogella GmbH and others.
2+
* Copyright (c) 2018, 2025 vogella GmbH and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,8 +13,8 @@
1313
******************************************************************************/
1414
package org.eclipse.e4.emf.xpath.test;
1515

16+
import static org.assertj.core.api.Assertions.assertThat;
1617
import static org.junit.Assert.assertNotNull;
17-
import static org.junit.Assert.assertTrue;
1818

1919
import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
2020
import org.eclipse.e4.emf.xpath.XPathContext;
@@ -46,7 +46,6 @@ public class ExampleQueriesApplicationTest {
4646
@SuppressWarnings("restriction")
4747
@Before
4848
public void setUp() {
49-
5049
resourceSet = new ResourceSetImpl();
5150
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
5251
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new E4XMIResourceFactory());
@@ -76,15 +75,13 @@ public void tearDown() {
7675
@Test
7776
public void testAccessingTheApplication() {
7877
Object application = xpathContext.getValue("/");
79-
assertNotNull(application);
80-
assertTrue(application instanceof MApplication);
78+
assertThat(application).isInstanceOf(MApplication.class);
8179
}
8280

8381
@Test
8482
public void testAccessingTheMainMenu() {
8583
Object menu = xpathContext.getValue("//mainMenu");
86-
assertNotNull(menu);
87-
assertTrue(menu instanceof MMenu);
84+
assertThat(menu).isInstanceOf(MMenu.class);
8885

8986
MMenu mMenu = xpathContext.getValue("//mainMenu", MMenu.class);
9087
assertNotNull(mMenu);
@@ -96,5 +93,4 @@ public void testAccessingAllMenus() {
9693
assertNotNull(menuEntries);
9794
}
9895

99-
10096
}

tests/org.eclipse.e4.emf.xpath.test/src/org/eclipse/e4/emf/xpath/test/ExampleQueriesTestCase.java

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010, 2014 BestSolution.at and others.
2+
* Copyright (c) 2010, 2025 BestSolution.at and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,9 +14,9 @@
1414
******************************************************************************/
1515
package org.eclipse.e4.emf.xpath.test;
1616

17+
import static org.assertj.core.api.Assertions.assertThat;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertNotNull;
19-
import static org.junit.Assert.assertSame;
2020
import static org.junit.Assert.assertThrows;
2121
import static org.junit.Assert.assertTrue;
2222

@@ -27,11 +27,11 @@
2727
import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
2828
import org.eclipse.e4.emf.xpath.XPathContext;
2929
import org.eclipse.e4.emf.xpath.XPathContextFactory;
30+
import org.eclipse.e4.emf.xpath.test.model.xpathtest.ExtendedNode;
31+
import org.eclipse.e4.emf.xpath.test.model.xpathtest.Menu;
32+
import org.eclipse.e4.emf.xpath.test.model.xpathtest.Node;
33+
import org.eclipse.e4.emf.xpath.test.model.xpathtest.Root;
3034
import org.eclipse.e4.emf.xpath.test.model.xpathtest.XpathtestPackage;
31-
import org.eclipse.e4.emf.xpath.test.model.xpathtest.impl.ExtendedNodeImpl;
32-
import org.eclipse.e4.emf.xpath.test.model.xpathtest.impl.MenuImpl;
33-
import org.eclipse.e4.emf.xpath.test.model.xpathtest.impl.NodeImpl;
34-
import org.eclipse.e4.emf.xpath.test.model.xpathtest.impl.RootImpl;
3535
import org.eclipse.emf.common.util.URI;
3636
import org.eclipse.emf.ecore.EObject;
3737
import org.eclipse.emf.ecore.resource.Resource;
@@ -73,53 +73,48 @@ public void tearDown() {
7373
public void testSimpleQuery() {
7474

7575
Object application = xpathContext.getValue("/");
76-
assertNotNull(application);
77-
assertSame(RootImpl.class, application.getClass());
76+
assertThat(application).isInstanceOf(Root.class);
7877

79-
RootImpl rootApplication = xpathContext.getValue("/", RootImpl.class);
78+
Root rootApplication = xpathContext.getValue("/", Root.class);
8079
assertNotNull(rootApplication);
8180

8281
application = xpathContext.getValue(".");
83-
assertNotNull(application);
84-
assertSame(RootImpl.class, application.getClass());
82+
assertThat(application).isInstanceOf(Root.class);
8583

8684
assertThrows(JXPathNotFoundException.class, () -> xpathContext.getValue(".[@id='nixda']"));
8785

8886
application = xpathContext.getValue(".[@id='root']");
89-
assertNotNull(application);
90-
assertSame(RootImpl.class, application.getClass());
87+
assertThat(application).isInstanceOf(Root.class);
9188

92-
rootApplication = xpathContext.getValue(".[@id='root']", RootImpl.class);
89+
rootApplication = xpathContext.getValue(".[@id='root']", Root.class);
9390
assertNotNull(rootApplication);
9491

95-
assertEquals("element1",xpathContext.getValue("nodes[1]/@id"));
92+
assertEquals("element1", xpathContext.getValue("nodes[1]/@id"));
9693

97-
assertEquals(NodeImpl.class, xpathContext.getValue("//.[@id='element2.2']").getClass());
98-
assertEquals(ExtendedNodeImpl.class,xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']").getClass());
94+
assertThat(xpathContext.getValue("//.[@id='element2.2']")).isInstanceOf(Node.class);
95+
assertThat(xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']")).isInstanceOf(ExtendedNode.class);
9996

100-
ExtendedNodeImpl extendedNode = xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']",
101-
ExtendedNodeImpl.class);
102-
assertNotNull(extendedNode);
97+
assertNotNull(xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']", ExtendedNode.class));
10398
}
10499

105100
@Test
106101
public void testMenuQuery() {
107102
Object application = xpathContext.getValue("/");
108-
assertNotNull(application);
109-
assertSame(RootImpl.class, application.getClass());
103+
assertThat(application).isInstanceOf(Root.class);
110104

111105
Object node = xpathContext.getValue("//.[@id='menuContainer.1']/menus[@id='menu.1']");
112106
assertNotNull(node);
107+
assertTrue(node instanceof Menu);
113108

114-
Iterator<Object> i = xpathContext.iterate("//.[@id='menu.1']");
109+
Iterator<Object> i = xpathContext.iterate("//.[@id='menu.1']");
115110
assertTrue(i.hasNext());
116-
assertSame(NodeImpl.class, i.next().getClass());
111+
assertThat(i.next()).isInstanceOf(Node.class);
117112
assertTrue(i.hasNext());
118-
assertSame(MenuImpl.class, i.next().getClass());
113+
assertThat(i.next()).isInstanceOf(Menu.class);
119114
// EMF model has a loop in it, it just goes back to the top
120-
//assertFalse(i.hasNext());
115+
// assertFalse(i.hasNext());
121116

122-
List<MenuImpl> list = xpathContext.stream("//.[@id='menu.1']", MenuImpl.class).toList();
117+
List<Menu> list = xpathContext.stream("//.[@id='menu.1']", Menu.class).toList();
123118
// EMF model has a loop in it, it just goes back to the top
124119
assertEquals(26, list.size());
125120
}

0 commit comments

Comments
 (0)