Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions org.eclipse.wb.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.31.100,4.0.0)",
org.eclipse.wb.swing.java6;bundle-version="[1.9.1000,2.0.0)";resolution:=optional,
org.eclipse.draw2d;bundle-version="[3.20.0,4.0.0)",
org.eclipse.gef;bundle-version="[3.21.100,4.0.0)",
org.junit;bundle-version="[4.13.2,5.0.0)",
org.mockito.mockito-core;bundle-version="[5.12.0,6.0.0)",
org.objectweb.asm;bundle-version="[9.7.0,10.0.0)",
org.objenesis;bundle-version="[3.4.0,4.0.0)",
net.bytebuddy.byte-buddy;bundle-version="[1.14.16,2.0.0)",
junit-jupiter-api;bundle-version="[5.10.2,6.0.0)",
junit-platform-suite-api;bundle-version="[1.10.2,2.0.0)"
junit-platform-suite-api;bundle-version="[1.10.2,2.0.0)",
org.opentest4j;bundle-version="[1.3.0,2.0.0)"
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.wb.tests.designer;x-internal:=true,
org.eclipse.wb.tests.designer.core;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*******************************************************************************/
package org.eclipse.wb.tests.designer;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.Suite.SuiteClasses;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.platform.suite.api.SelectClasses;

import java.io.File;
import java.lang.annotation.Annotation;
Expand All @@ -45,11 +45,11 @@ public class JUnitUtils {
private static File TEST_DIR = new File("src");
private static Set<Class<?>> TEST_ANNOTATIONS = Set.of( //
Test.class, //
Ignore.class, //
Before.class, //
After.class, //
BeforeClass.class, //
AfterClass.class);
Disabled.class, //
BeforeEach.class, //
AfterEach.class, //
BeforeAll.class, //
AfterAll.class);

public static Set<Class<?>> getRepeatedlyExecutedClasses() {
Map<Class<?>, Integer> counts = new HashMap<>();
Expand Down Expand Up @@ -103,7 +103,7 @@ private static List<Class<?>> getAllExecutedClasses(Class<?> clazz) {
List<Class<?>> result = new ArrayList<>();
result.add(clazz);

SuiteClasses suiteClasses = clazz.getAnnotation(SuiteClasses.class);
SelectClasses suiteClasses = clazz.getAnnotation(SelectClasses.class);
if (suiteClasses != null) {
for (Class<?> suiteClass : suiteClasses.value()) {
result.addAll(getAllExecutedClasses(suiteClass));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.JavaModelException;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.eclipse.wb.internal.core.DesignerPlugin;
import org.eclipse.wb.internal.core.utils.IOUtils2;
import org.eclipse.wb.internal.core.utils.external.ExternalFactoriesHelper;
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;
import org.eclipse.wb.tests.designer.core.TestProject;
import org.eclipse.wb.tests.designer.tests.Activator;

Expand All @@ -42,27 +41,13 @@
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWizard;

import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.commons.lang3.StringUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.osgi.framework.Bundle;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Vector;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;

Expand Down Expand Up @@ -377,75 +362,4 @@ public static String createTemporaryJar(String entryName, String content) throws
// return path to "jar"
return tempFile.getAbsolutePath();
}

////////////////////////////////////////////////////////////////////////////
//
// TestSuite
//
////////////////////////////////////////////////////////////////////////////
/**
* Sorts test methods in the given {@link TestSuite} to same order as they are declared in source
* of test class.
*/
public static void sortTestSuiteMethods(Class<?> clazz, TestSuite suite) {
try {
final List<String> sourceMethodNames = getSourceMethodNames(clazz);
Vector<TestCase> tests = getTestsVector(suite);
Collections.sort(tests, new Comparator<TestCase>() {
@Override
public int compare(TestCase o1, TestCase o2) {
String method_1 = o1.getName();
String method_2 = o2.getName();
if ("test_setUp".equals(method_1)) {
return -1;
}
if ("test_setUp".equals(method_2)) {
return 1;
}
if ("test_tearDown".equals(method_1)) {
return 1;
}
if ("test_tearDown".equals(method_2)) {
return -1;
}
return sourceMethodNames.indexOf(method_1) - sourceMethodNames.indexOf(method_2);
}
});
} catch (Throwable e) {
ReflectionUtils.propagate(e);
}
}

/**
* @return the names of methods declared in the given {@link Class}, in same order as in source.
*/
private static List<String> getSourceMethodNames(Class<?> testClass) throws Exception {
final List<String> sourceMethodNames = new ArrayList<>();
String classPath = testClass.getName().replace('.', '/') + ".class";
InputStream classStream = testClass.getClassLoader().getResourceAsStream(classPath);
ClassReader classReader = new ClassReader(classStream);
classReader.accept(new ClassVisitor(Opcodes.ASM9) {
@Override
public MethodVisitor visitMethod(int access,
String name,
String desc,
String signature,
String[] exceptions) {
sourceMethodNames.add(name);
return new MethodVisitor(Opcodes.ASM9) {};
}
}, 0);
return sourceMethodNames;
}

/**
* @return the live {@link Vector} of tests in the given {@link TestSuite}.
*/
private static Vector<TestCase> getTestsVector(TestSuite suite) throws Exception {
Field testsField = TestSuite.class.getDeclaredField("fTests");
testsField.setAccessible(true);
@SuppressWarnings("unchecked")
Vector<TestCase> tests = (Vector<TestCase>) testsField.get(suite);
return tests;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
import org.eclipse.wb.internal.core.utils.state.GlobalState;
import org.eclipse.wb.tests.designer.tests.DesignerTestCase;

import junit.framework.TestCase;

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

/**
* Fake {@link TestCase} that just wait long time, so that we have time to get memory snapshot.
* Fake test case that just wait long time, so that we have time to get memory
* snapshot.
*
* @author scheglov_ke
*/
@Ignore
@Disabled
public class WaitForMemoryProfilerTest extends DesignerTestCase {
@Test
public void test_waitForProfiler() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
import org.eclipse.wb.tests.gef.GefTests;
import org.eclipse.wb.tests.utils.CommonTests;

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

/**
* All WindowBuilder tests.
*
* @author scheglov_ke
*/

@RunWith(Suite.class)
@SuiteClasses({
@Suite
@SelectClasses({
Draw2dTests.class, //
GefTests.class, //
SwtTests.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.wb.internal.core.utils.IOUtils2;
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;
import org.eclipse.wb.tests.designer.core.AbstractJavaProjectTest.AnnotationExtension;
import org.eclipse.wb.tests.designer.core.annotations.DisposeProjectAfter;
import org.eclipse.wb.tests.designer.core.annotations.DisposeProjectBefore;
import org.eclipse.wb.tests.designer.core.annotations.WaitForAutoBuildAfter;
Expand All @@ -38,17 +39,17 @@
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.MultipleFailureException;
import org.junit.runners.model.Statement;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -57,6 +58,7 @@
*
* @author scheglov_ke
*/
@ExtendWith(AnnotationExtension.class)
public abstract class AbstractJavaProjectTest extends DesignerTestCase {
private static final List<IFile> m_createdResources = new ArrayList<>();

Expand All @@ -66,7 +68,7 @@ public abstract class AbstractJavaProjectTest extends DesignerTestCase {
//
////////////////////////////////////////////////////////////////////////////
@Override
@After
@AfterEach
public void tearDown() throws Exception {
// remove resources (with retries)
{
Expand Down Expand Up @@ -97,7 +99,7 @@ public void tearDown() throws Exception {
super.tearDown();
}

@AfterClass
@AfterAll
public static void tearDownClass() throws Exception {
do_projectDispose();
}
Expand All @@ -108,39 +110,30 @@ public static void tearDownClass() throws Exception {
//
////////////////////////////////////////////////////////////////////////////

@Rule
public TestRule methodRule = new TestRule() {
public static class AnnotationExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback {
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
List<Throwable> errors = new ArrayList<>();
if (description.getAnnotation(DisposeProjectBefore.class) != null) {
waitEventLoop(10);
do_projectDispose();
waitEventLoop(10);
}
try {
base.evaluate();
} catch (Throwable t) {
errors.add(t);
} finally {
if (description.getAnnotation(DisposeProjectAfter.class) != null) {
waitEventLoop(10);
do_projectDispose();
waitEventLoop(10);
}
if (description.getAnnotation(WaitForAutoBuildAfter.class) != null) {
waitForAutoBuild();
}
public void beforeTestExecution(ExtensionContext context) throws Exception {
Method method = context.getRequiredTestMethod();
if (method.getAnnotation(DisposeProjectBefore.class) != null) {
waitEventLoop(10);
do_projectDispose();
waitEventLoop(10);
}
}

}
MultipleFailureException.assertEmpty(errors);
}
};
@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
Method method = context.getRequiredTestMethod();
if (method.getAnnotation(DisposeProjectAfter.class) != null) {
waitEventLoop(10);
do_projectDispose();
waitEventLoop(10);
}
if (method.getAnnotation(WaitForAutoBuildAfter.class) != null) {
waitForAutoBuild();
}
}
};
}

////////////////////////////////////////////////////////////////////////////
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;

import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.jupiter.api.AfterEach;

import java.util.List;

Expand All @@ -69,7 +69,7 @@ public abstract class AbstractJavaTest extends AbstractJavaProjectTest {
//
////////////////////////////////////////////////////////////////////////////
@Override
@After
@AfterEach
public void tearDown() throws Exception {
// don't ignore model compilation problems
m_ignoreModelCompileProblems = false;
Expand Down Expand Up @@ -252,11 +252,11 @@ protected static void assertRelatedNodes(JavaInfo javaInfo, String[] sourceTight
throws Exception {
List<ASTNode> nodes = javaInfo.getRelatedNodes();
assertEquals(
sourceTightlyNodes.length,
nodes.size(),
StringUtils.join(sourceTightlyNodes, ", ")
+ " != "
+ StringUtils.join(nodes.iterator(), ", "),
sourceTightlyNodes.length,
nodes.size());
+ StringUtils.join(nodes.iterator(), ", "));
for (int i = 0; i < nodes.size(); i++) {
ASTNode node = nodes.get(i);
// prepare node to compare source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.swt.graphics.Image;

import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.osgi.framework.Bundle;

import java.io.InputStream;
Expand Down
Loading
Loading