|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (c) 2010, 2014 BestSolution.at and others. |
| 2 | + * Copyright (c) 2010, 2025 BestSolution.at and others. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials
|
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0
|
|
14 | 14 | ******************************************************************************/
|
15 | 15 | package org.eclipse.e4.emf.xpath.test;
|
16 | 16 |
|
| 17 | +import static org.assertj.core.api.Assertions.assertThat; |
17 | 18 | import static org.junit.Assert.assertEquals;
|
18 | 19 | import static org.junit.Assert.assertNotNull;
|
19 |
| -import static org.junit.Assert.assertSame; |
20 | 20 | import static org.junit.Assert.assertThrows;
|
21 | 21 | import static org.junit.Assert.assertTrue;
|
22 | 22 |
|
|
27 | 27 | import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory;
|
28 | 28 | import org.eclipse.e4.emf.xpath.XPathContext;
|
29 | 29 | 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; |
30 | 34 | 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; |
35 | 35 | import org.eclipse.emf.common.util.URI;
|
36 | 36 | import org.eclipse.emf.ecore.EObject;
|
37 | 37 | import org.eclipse.emf.ecore.resource.Resource;
|
@@ -73,53 +73,48 @@ public void tearDown() {
|
73 | 73 | public void testSimpleQuery() {
|
74 | 74 |
|
75 | 75 | Object application = xpathContext.getValue("/");
|
76 |
| - assertNotNull(application); |
77 |
| - assertSame(RootImpl.class, application.getClass()); |
| 76 | + assertThat(application).isInstanceOf(Root.class); |
78 | 77 |
|
79 |
| - RootImpl rootApplication = xpathContext.getValue("/", RootImpl.class); |
| 78 | + Root rootApplication = xpathContext.getValue("/", Root.class); |
80 | 79 | assertNotNull(rootApplication);
|
81 | 80 |
|
82 | 81 | application = xpathContext.getValue(".");
|
83 |
| - assertNotNull(application); |
84 |
| - assertSame(RootImpl.class, application.getClass()); |
| 82 | + assertThat(application).isInstanceOf(Root.class); |
85 | 83 |
|
86 | 84 | assertThrows(JXPathNotFoundException.class, () -> xpathContext.getValue(".[@id='nixda']"));
|
87 | 85 |
|
88 | 86 | application = xpathContext.getValue(".[@id='root']");
|
89 |
| - assertNotNull(application); |
90 |
| - assertSame(RootImpl.class, application.getClass()); |
| 87 | + assertThat(application).isInstanceOf(Root.class); |
91 | 88 |
|
92 |
| - rootApplication = xpathContext.getValue(".[@id='root']", RootImpl.class); |
| 89 | + rootApplication = xpathContext.getValue(".[@id='root']", Root.class); |
93 | 90 | assertNotNull(rootApplication);
|
94 | 91 |
|
95 |
| - assertEquals("element1",xpathContext.getValue("nodes[1]/@id")); |
| 92 | + assertEquals("element1", xpathContext.getValue("nodes[1]/@id")); |
96 | 93 |
|
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); |
99 | 96 |
|
100 |
| - ExtendedNodeImpl extendedNode = xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']", |
101 |
| - ExtendedNodeImpl.class); |
102 |
| - assertNotNull(extendedNode); |
| 97 | + assertNotNull(xpathContext.getValue("//.[ecore:eClassName(.)='ExtendedNode']", ExtendedNode.class)); |
103 | 98 | }
|
104 | 99 |
|
105 | 100 | @Test
|
106 | 101 | public void testMenuQuery() {
|
107 | 102 | Object application = xpathContext.getValue("/");
|
108 |
| - assertNotNull(application); |
109 |
| - assertSame(RootImpl.class, application.getClass()); |
| 103 | + assertThat(application).isInstanceOf(Root.class); |
110 | 104 |
|
111 | 105 | Object node = xpathContext.getValue("//.[@id='menuContainer.1']/menus[@id='menu.1']");
|
112 | 106 | assertNotNull(node);
|
| 107 | + assertTrue(node instanceof Menu); |
113 | 108 |
|
114 |
| - Iterator<Object> i = xpathContext.iterate("//.[@id='menu.1']"); |
| 109 | + Iterator<Object> i = xpathContext.iterate("//.[@id='menu.1']"); |
115 | 110 | assertTrue(i.hasNext());
|
116 |
| - assertSame(NodeImpl.class, i.next().getClass()); |
| 111 | + assertThat(i.next()).isInstanceOf(Node.class); |
117 | 112 | assertTrue(i.hasNext());
|
118 |
| - assertSame(MenuImpl.class, i.next().getClass()); |
| 113 | + assertThat(i.next()).isInstanceOf(Menu.class); |
119 | 114 | // EMF model has a loop in it, it just goes back to the top
|
120 |
| - //assertFalse(i.hasNext()); |
| 115 | + // assertFalse(i.hasNext()); |
121 | 116 |
|
122 |
| - List<MenuImpl> list = xpathContext.stream("//.[@id='menu.1']", MenuImpl.class).toList(); |
| 117 | + List<Menu> list = xpathContext.stream("//.[@id='menu.1']", Menu.class).toList(); |
123 | 118 | // EMF model has a loop in it, it just goes back to the top
|
124 | 119 | assertEquals(26, list.size());
|
125 | 120 | }
|
|
0 commit comments