Skip to content

Commit

Permalink
Migrate GEF Tests to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ptziegler authored and azoitl committed Dec 28, 2024
1 parent 9f7da2c commit c466019
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 78 deletions.
4 changes: 3 additions & 1 deletion org.eclipse.gef.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Require-Bundle: org.eclipse.jface;bundle-version="[3.2.0,4.0.0)",
org.eclipse.gef;bundle-version="[3.18.0,4.0.0)",
org.eclipse.gef.examples.logic;bundle-version="[3.14.400,4.0.0)",
org.eclipse.swtbot.eclipse.gef.finder;bundle-version="[4.2.1,5.0.0)",
org.junit
junit-jupiter-api;bundle-version="[5.11.4,6.0.0)",
junit-platform-suite-api;bundle-version="[1.11.4,2.0.0)",
org.opentest4j;bundle-version="[1.3.0,2.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-21
Automatic-Module-Name: org.eclipse.gef.tests

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.eclipse.gef.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.EventObject;
Expand All @@ -15,7 +15,7 @@
import org.eclipse.gef.commands.CommandStackEventListener;
import org.eclipse.gef.commands.CommandStackListener;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CommandStackTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 IBM Corporation and others.
* Copyright (c) 2006, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -13,6 +13,8 @@

package org.eclipse.gef.test;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import org.eclipse.swt.graphics.Image;
Expand All @@ -33,10 +35,9 @@
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.tools.DragEditPartsTracker;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DragEditPartsTrackerTest extends Assert {
public class DragEditPartsTrackerTest {

private static class TestGraphicalEditPart extends AbstractGraphicalEditPart {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

import org.eclipse.gef.test.swtbot.SWTBotTestSuite;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

/**
* The main test suite for GEF.
*
* @author Eric Bordeau
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
@Suite
@SelectClasses({
PaletteCustomizerTest.class,
ToolUtilitiesTest.class,
DragEditPartsTrackerTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

package org.eclipse.gef.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

Expand All @@ -36,13 +36,13 @@
import org.eclipse.gef.ui.actions.DeleteAction;
import org.eclipse.gef.ui.parts.GraphicalViewerImpl;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class GraphicalViewerTest {
private GraphicalViewer viewer;

@Before
@BeforeEach
public void setUp() {
viewer = PlatformUI.getWorkbench().getDisplay().syncCall(GraphicalViewerImpl::new);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -12,6 +12,9 @@
*******************************************************************************/
package org.eclipse.gef.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteEntry;
Expand All @@ -22,10 +25,9 @@
import org.eclipse.gef.ui.palette.customize.PaletteSeparatorFactory;
import org.eclipse.gef.ui.palette.customize.PaletteStackFactory;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class PaletteCustomizerTest extends Assert {
public class PaletteCustomizerTest {

class TestCustomizer extends PaletteCustomizer {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

package org.eclipse.gef.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -32,9 +32,9 @@
import org.eclipse.gef.internal.ui.rulers.RulerLayout;
import org.eclipse.gef.rulers.RulerProvider;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class RulerLayoutTests {
private static final Rectangle EMPTY_RECTANGLE = new Rectangle(0, 0, 0, 0);
Expand All @@ -47,7 +47,7 @@ public class RulerLayoutTests {
protected ILogListener logListener;
protected List<String> logMessages;

@Before
@BeforeEach
public void setUp() {
constraint = 42;
figure = new Figure();
Expand All @@ -67,7 +67,7 @@ public int getUnit() {
log.addLogListener(logListener);
}

@After
@AfterEach
public void tearDown() {
log.removeLogListener(logListener);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 IBM Corporation and others.
* Copyright (c) 2006, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -13,17 +13,18 @@

package org.eclipse.gef.test;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.gef.tools.ToolUtilities;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ToolUtilitiesTest extends Assert {
public class ToolUtilitiesTest {

private static class TestGraphicalEditPart extends AbstractGraphicalEditPart {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
import org.eclipse.ui.wizards.IWizardDescriptor;
import org.eclipse.ui.wizards.IWizardRegistry;

import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.osgi.framework.Bundle;

@SuppressWarnings("nls")
public abstract class AbstractSWTBotEditorTests extends AbstractSWTBotTests {
private static final String PROJECT_NAME = "TestProject";

@Before
@BeforeEach
@Override
public void setUp() throws Exception {
super.setUp();
Expand Down Expand Up @@ -87,7 +87,7 @@ public void setUp() throws Exception {
});
}

@After
@AfterEach
@Override
public void tearDown() throws Exception {
IWorkbench wb = PlatformUI.getWorkbench();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package org.eclipse.gef.test.swtbot;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,8 +31,8 @@

import org.eclipse.gef.EditPart;

import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

/**
* To be able to execute these tests in the Eclipse IDE, the tests must
Expand All @@ -44,7 +44,7 @@ public abstract class AbstractSWTBotTests {
private List<Throwable> problems;
protected SWTGefBot bot;

@Before
@BeforeEach
public void setUp() throws Exception {
if (Display.getCurrent() != null) {
fail("""
Expand Down Expand Up @@ -84,12 +84,12 @@ private static final boolean isRelevant(Throwable throwable) {
return false;
}

@After
@AfterEach
public void tearDown() throws Exception {
// Cleanup problem listener and check for exceptions
Platform.removeLogListener(problemListener);
problems.forEach(Throwable::printStackTrace);
assertTrue("Test threw an unchecked exception. Check logs for details", problems.isEmpty());
assertTrue(problems.isEmpty(), "Test threw an unchecked exception. Check logs for details");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@

package org.eclipse.gef.test.swtbot;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.List;

import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;

import org.junit.Test;
import org.junit.jupiter.api.Test;

@SuppressWarnings("nls")
public class FlowDiagramTests extends AbstractSWTBotEditorTests {
Expand Down Expand Up @@ -121,7 +121,7 @@ public void testMarqueeSelection() {
editor.activateTool("Marquee");

UIThreadRunnable.syncExec(() -> editor.drag(0, 0, 500, 500));
assertFalse("At least one edit part should be selected", editor.selectedEditParts().isEmpty());
assertFalse(editor.selectedEditParts().isEmpty(), "At least one edit part should be selected");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
<booleanAttribute key="append.args" value="true"/>
<booleanAttribute key="askclear" value="false"/>
<booleanAttribute key="automaticAdd" value="true"/>
<booleanAttribute key="automaticValidate" value="false"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="true"/>
<booleanAttribute key="clearws" value="true"/>
<booleanAttribute key="clearwslog" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
<booleanAttribute key="default" value="true"/>
<booleanAttribute key="includeOptional" value="true"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<booleanAttribute key="org.eclipse.debug.core.ATTR_FORCE_SYSTEM_CONSOLE_ENCODING" value="false"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.eclipse.gef.tests/src/org/eclipse/gef/test/swtbot/SWTBotTestSuite.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.gef.test.swtbot.SWTBotTestSuite"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.gef.tests"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.sdk.ide"/>
<booleanAttribute key="run_in_ui_thread" value="false"/>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
<booleanAttribute key="useDefaultConfigArea" value="false"/>
<booleanAttribute key="useProduct" value="true"/>
</launchConfiguration>
Loading

0 comments on commit c466019

Please sign in to comment.