-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate OpenProjectExplorerFolderTest to JUnit 5 #22
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |||||
| *******************************************************************************/ | ||||||
| package org.eclipse.ui.tests.performance; | ||||||
|
|
||||||
| import static org.junit.Assert.fail; | ||||||
| import static org.junit.jupiter.api.Assertions.fail; | ||||||
|
|
||||||
| import java.io.ByteArrayInputStream; | ||||||
| import java.io.ByteArrayOutputStream; | ||||||
|
|
@@ -28,14 +28,16 @@ | |||||
| import org.eclipse.core.runtime.CoreException; | ||||||
| import org.eclipse.core.runtime.NullProgressMonitor; | ||||||
| import org.eclipse.core.runtime.Platform; | ||||||
| import org.eclipse.test.performance.PerformanceTestCaseJunit4; | ||||||
| import org.eclipse.test.performance.Performance; | ||||||
| import org.eclipse.test.performance.PerformanceMeter; | ||||||
| import org.eclipse.ui.IViewPart; | ||||||
| import org.eclipse.ui.IWorkbenchPage; | ||||||
| import org.eclipse.ui.PartInitException; | ||||||
| import org.eclipse.ui.PlatformUI; | ||||||
| import org.eclipse.ui.navigator.resources.ProjectExplorer; | ||||||
| import org.junit.ClassRule; | ||||||
| import org.junit.Test; | ||||||
| import org.junit.jupiter.api.Test; | ||||||
| import org.junit.jupiter.api.TestInfo; | ||||||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||||||
| import org.osgi.framework.Bundle; | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -61,72 +63,79 @@ | |||||
| * "sleep" to simulate computations, it only effects Elapsed Time (not CPU | ||||||
| * Time). | ||||||
| */ | ||||||
| public class OpenProjectExplorerFolderTest extends PerformanceTestCaseJunit4 { | ||||||
| public class OpenProjectExplorerFolderTest { | ||||||
|
|
||||||
| @ClassRule | ||||||
| public static final UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule(); | ||||||
| @RegisterExtension | ||||||
| static UIPerformanceTestRule uiPerformanceTestRule = new UIPerformanceTestRule(); | ||||||
|
|
||||||
| /* | ||||||
| * performance testcase for bug 106158 | ||||||
| * https://bugs.eclipse.org/bugs/show_bug.cgi?id=106158 | ||||||
| */ | ||||||
| @Test | ||||||
| public void testOpenNavigatorFolder() { | ||||||
| IProject project = createProject("testViewAndContentTypeProject"); | ||||||
| Bundle bundle = Platform.getBundle("org.eclipse.ui.tests.performance"); | ||||||
| URL url = bundle.getEntry("data/testContentType.zip"); | ||||||
| try (ZipInputStream zis = new ZipInputStream(url.openStream())) { | ||||||
| ZipEntry entry = zis.getNextEntry(); | ||||||
| while (entry != null) { | ||||||
| byte[] content = new byte[0]; | ||||||
| try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { | ||||||
| byte[] b = new byte[2048]; | ||||||
| int read = zis.read(b); | ||||||
| while (read != -1) { | ||||||
| baos.write(b, 0, read); | ||||||
| read = zis.read(b); | ||||||
| public void testOpenNavigatorFolder(TestInfo testInfo) { | ||||||
| Performance perf = Performance.getDefault(); | ||||||
| String scenarioId = getClass().getName() + "." + testInfo.getDisplayName(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
| PerformanceMeter meter = perf.createPerformanceMeter(scenarioId); | ||||||
| try { | ||||||
| IProject project = createProject("testViewAndContentTypeProject"); | ||||||
| Bundle bundle = Platform.getBundle("org.eclipse.ui.tests.performance"); | ||||||
| URL url = bundle.getEntry("data/testContentType.zip"); | ||||||
| try (ZipInputStream zis = new ZipInputStream(url.openStream())) { | ||||||
| ZipEntry entry = zis.getNextEntry(); | ||||||
| while (entry != null) { | ||||||
| byte[] content = new byte[0]; | ||||||
| try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { | ||||||
| byte[] b = new byte[2048]; | ||||||
| int read = zis.read(b); | ||||||
| while (read != -1) { | ||||||
| baos.write(b, 0, read); | ||||||
| read = zis.read(b); | ||||||
| } | ||||||
| content = baos.toByteArray(); | ||||||
| } | ||||||
| content = baos.toByteArray(); | ||||||
| } | ||||||
| catch (IOException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| IFile file = project.getFile(entry.getName()); | ||||||
| try (ByteArrayInputStream bais = new ByteArrayInputStream(content)) { | ||||||
| if (!file.exists()) | ||||||
| file.create(bais, true, new NullProgressMonitor()); | ||||||
| else | ||||||
| file.setContents(bais, true, false, new NullProgressMonitor()); | ||||||
| } | ||||||
| catch (CoreException e) { | ||||||
| fail(e.getMessage()); | ||||||
| catch (IOException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| IFile file = project.getFile(entry.getName()); | ||||||
| try (ByteArrayInputStream bais = new ByteArrayInputStream(content)) { | ||||||
| if (!file.exists()) | ||||||
| file.create(bais, true, new NullProgressMonitor()); | ||||||
| else | ||||||
| file.setContents(bais, true, false, new NullProgressMonitor()); | ||||||
| } | ||||||
| catch (CoreException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| entry = zis.getNextEntry(); | ||||||
| } | ||||||
| entry = zis.getNextEntry(); | ||||||
| } | ||||||
| catch (IOException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| meter.start(); | ||||||
| IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||||||
| IViewPart view = null; | ||||||
| try { | ||||||
| view = activePage.showView(ProjectExplorer.VIEW_ID); | ||||||
| } | ||||||
| catch (PartInitException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| ProjectExplorer projectExplorer = null; | ||||||
| try { | ||||||
| projectExplorer = (ProjectExplorer) view; | ||||||
| } | ||||||
| catch (ClassCastException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| projectExplorer.getCommonViewer().expandAll(); | ||||||
| meter.stop(); | ||||||
| meter.commit(); | ||||||
| perf.assertPerformance(meter); | ||||||
| } finally { | ||||||
| meter.dispose(); | ||||||
| } | ||||||
| catch (IOException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| startMeasuring(); | ||||||
| IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||||||
| IViewPart view = null; | ||||||
| try { | ||||||
| view = activePage.showView(ProjectExplorer.VIEW_ID); | ||||||
| } | ||||||
| catch (PartInitException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| ProjectExplorer projectExplorer = null; | ||||||
| try { | ||||||
| projectExplorer = (ProjectExplorer) view; | ||||||
| } | ||||||
| catch (ClassCastException e) { | ||||||
| fail(e.getMessage()); | ||||||
| } | ||||||
| projectExplorer.getCommonViewer().expandAll(); | ||||||
| stopMeasuring(); | ||||||
| commitMeasurements(); | ||||||
| assertPerformance(); | ||||||
| } | ||||||
|
|
||||||
| private IProject createProject(String name) { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
uiPerformanceTestRulefield should remainpublicandfinalto match the original JUnit 4 implementation and follow best practices for registered extensions. This ensures the extension is not accidentally modified and remains accessible if needed by the framework or other tests.