Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve UIEventsTest #1471

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
};

Expand All @@ -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))
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand 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);
Expand Down
Loading