From 2b1256772b711d08f00944b0ebcdd1093ad8488d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Fri, 5 Jan 2024 09:34:27 +0200 Subject: [PATCH] Improve UIEventsTest This test had custom assertTrue that did nothing for as long as it existed in the repo. --- .../e4/ui/tests/application/UIEventsTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java index fb86d740669..eda7f4c147c 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UIEventsTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2023 IBM Corporation and others. + * Copyright (c) 2009, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,6 +14,7 @@ package org.eclipse.e4.ui.tests.application; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; @@ -59,12 +60,16 @@ static class EventTester { boolean[] hasFired; EventHandler attListener = event -> { - assertTrue(event.getTopic().equals(topic), - "Incorrect Topic: " + event.getTopic()); //$NON-NLS-1$ + // In case of * topic check that that event topic starts with the same prefix + if (topic.endsWith("*")) { + assertTrue("Incorrect Topic.", event.getTopic().startsWith(topic.substring(0, topic.length() - 2))); + } else { + assertEquals("Incorrect Topic.", topic, event.getTopic()); + } String attId = (String) event.getProperty(EventTags.ATTNAME); int attIndex = getAttIndex(attId); - assertTrue(attIndex >= 0, "Unknown Attribite: " + attId); //$NON-NLS-1$ + assertTrue("Unknown Attribite: " + attId, attIndex >= 0); //$NON-NLS-1$ hasFired[attIndex] = true; }; @@ -81,9 +86,6 @@ public EventTester(String name, String topic, String[] attIds, eventBroker.subscribe(this.topic, attListener); } - protected void assertTrue(boolean b, String string) { - } - protected int getAttIndex(String attId) { for (int i = 0; i < attIds.length; i++) { if (attIds[i].equals(attId)) @@ -232,7 +234,7 @@ public void testAllTopics() { String newId = "Some New Id"; allData.setElementId(newId); allData.getTags().add("Testing"); - // allData.setTags("new Style"); + allData.getPersistedState().put("testing", "Some state"); checkForFailures(allTesters, appTester); @@ -322,7 +324,7 @@ public void testBrokerCleanup() { IEventBroker childEB = childContext.get(IEventBroker.class); assertNotEquals("child context has same IEventBroker", appEB, childEB); - final boolean seen[] = { false }; + final boolean[] seen = { false }; childEB.subscribe(testTopic, event -> seen[0] = true); // ensure the EBs are wired up @@ -355,7 +357,7 @@ private void ensureNoCrossTalk(EventTester[] allTesters, EventTester skipMe) { badTesters.add(t); } - if (badTesters.size() > 0) { + if (!badTesters.isEmpty()) { String msg = "Events were fired in the wrong topic(s): " + badTesters; fail(msg);