Skip to content

Commit

Permalink
fix NewTypeWizardTest progress
Browse files Browse the repository at this point in the history
beginTask must only be called once on a given progress monitor instance.
  • Loading branch information
EcljpseB0T committed Dec 12, 2023
1 parent 00eb045 commit cc856df
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -131,30 +131,21 @@ else if (element instanceof IOpenable)
* Adapted / moved from org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathsBlock
*/
public static void createProject(IProject project, URI locationURI, IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
monitor.beginTask(ManipulationsCommonUtilMessages.BuildPathsBlock_operationdesc_project, 10);

// create the project
SubMonitor subMonitor= SubMonitor.convert(monitor, ManipulationsCommonUtilMessages.BuildPathsBlock_operationdesc_project, 2);
try {
if (!project.exists()) {
IProjectDescription desc= project.getWorkspace().newProjectDescription(project.getName());
if (locationURI != null && ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(locationURI)) {
locationURI= null;
}
desc.setLocationURI(locationURI);
project.create(desc, monitor);
monitor= null;
project.create(desc, subMonitor.newChild(1));
}
if (!project.isOpen()) {
project.open(monitor);
monitor= null;
project.open(subMonitor.newChild(1));
}
} finally {
if (monitor != null) {
monitor.done();
}
subMonitor.done();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.junit.Ignore;
import org.junit.Test;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.tests.harness.FussyProgressMonitor;

import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.Refactoring;
Expand Down Expand Up @@ -126,7 +126,10 @@ private void helperAdd(String[] signature, ParameterInfo[] newParamInfos, int[]

processor.setDelegateUpdating(createDelegate);
addInfos(processor.getParameterInfos(), newParamInfos, newIndices);
RefactoringStatus initialConditions= ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
RefactoringStatus initialConditions= ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

assertTrue("precondition was supposed to pass:"+initialConditions.getEntryWithHighestSeverity(), initialConditions.isOK());
JavaRefactoringDescriptor descriptor= processor.createDescriptor();
RefactoringStatus result= performRefactoring(descriptor);
Expand Down Expand Up @@ -176,7 +179,10 @@ private void helperRenameMethod(String[] signature, String newMethodName, boolea
processor.setNewMethodName(newMethodName);
processor.setDelegateUpdating(createDelegate);
processor.setDeprecateDelegates(markAsDeprecated);
ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

JavaRefactoringDescriptor descriptor= processor.createDescriptor();
RefactoringStatus result= performRefactoring(descriptor);
assertNull("precondition was supposed to pass", result);
Expand Down Expand Up @@ -223,7 +229,10 @@ private void helperDoAll(IMethod method, ParameterInfo[] newParamInfos, int[] ne
modifyInfos(processor.getParameterInfos(), newParamInfos, newIndices, oldParamNames, newParamNames, newParameterTypeNames, permutation);
if (newVisibility != JdtFlags.VISIBILITY_CODE_INVALID)
processor.setVisibility(newVisibility);
RefactoringStatus initialConditions= ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
RefactoringStatus initialConditions= ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

assertTrue(initialConditions.isOK());
JavaRefactoringDescriptor descriptor= processor.createDescriptor();
RefactoringStatus result= performRefactoring(descriptor);
Expand Down Expand Up @@ -278,7 +287,10 @@ private void helper1(String[] newOrder, String[] signature, String[] oldNames, S

processor.setDelegateUpdating(createDelegate);
modifyInfos(processor.getParameterInfos(), newOrder, oldNames, newNames);
ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

JavaRefactoringDescriptor descriptor= processor.createDescriptor();
RefactoringStatus result= performRefactoring(descriptor);
assertNull("precondition was supposed to pass", result);
Expand Down Expand Up @@ -379,8 +391,14 @@ private void helperFail(String[] newOrder, String[] signature, int expectedSever
Refactoring ref= new ProcessorBasedRefactoring(processor);

modifyInfos(processor.getParameterInfos(), newOrder, null, null);
ref.checkInitialConditions(new NullProgressMonitor());
RefactoringStatus result= ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

FussyProgressMonitor testMonitor2= new FussyProgressMonitor();
RefactoringStatus result= ref.checkInitialConditions(testMonitor2);
testMonitor2.assertUsedUp();

if (result.isOK()) {
JavaRefactoringDescriptor descriptor= processor.createDescriptor();
result= performRefactoring(descriptor, true);
Expand All @@ -398,7 +416,10 @@ private void helperAddFail(String[] signature, ParameterInfo[] newParamInfos, in
Refactoring ref= new ProcessorBasedRefactoring(processor);

addInfos(processor.getParameterInfos(), newParamInfos, newIndices);
RefactoringStatus result= ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
RefactoringStatus result= ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

if (result.isOK()) {
JavaRefactoringDescriptor descriptor= processor.createDescriptor();
result= performRefactoring(descriptor, true);
Expand Down Expand Up @@ -430,7 +451,10 @@ private void helperDoAllFail(String methodName,
modifyInfos(processor.getParameterInfos(), newParamInfos, newIndices, oldParamNames, newParamNames, newParameterTypeNames, permutation);
if (newVisibility != JdtFlags.VISIBILITY_CODE_INVALID)
processor.setVisibility(newVisibility);
RefactoringStatus result= ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
RefactoringStatus result= ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

if (result.isOK()) {
JavaRefactoringDescriptor descriptor= processor.createDescriptor();
result= performRefactoring(descriptor);
Expand Down Expand Up @@ -470,12 +494,18 @@ private void helperDoAllWithExceptions(String typeName,
processor.setVisibility(newVisibility);

// from RefactoringTest#performRefactoring():
RefactoringStatus status= ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
RefactoringStatus status= ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

assertTrue("checkActivation was supposed to pass", status.isOK());

mangleExceptions(processor.getExceptionInfos(), removeExceptions, addExceptions, method.getCompilationUnit());

status= ref.checkFinalConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor2= new FussyProgressMonitor();
status= ref.checkFinalConditions(testMonitor2);
testMonitor2.assertUsedUp();

assertTrue("checkInput was supposed to pass", status.isOK());
Change undo= performChange(ref, true);
assertNotNull(undo);
Expand All @@ -500,12 +530,18 @@ private void helperException(String[] signature, String[] removeExceptions, Stri
Refactoring ref= new ProcessorBasedRefactoring(processor);

// from RefactoringTest#performRefactoring():
RefactoringStatus status= ref.checkInitialConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
RefactoringStatus status= ref.checkInitialConditions(testMonitor);
testMonitor.assertUsedUp();

assertTrue("checkActivation was supposed to pass", status.isOK());

mangleExceptions(processor.getExceptionInfos(), removeExceptions, addExceptions, method.getCompilationUnit());

status= ref.checkFinalConditions(new NullProgressMonitor());
FussyProgressMonitor testMonitor2= new FussyProgressMonitor();
status= ref.checkFinalConditions(testMonitor2);
testMonitor2.assertUsedUp();

assertTrue("checkInput was supposed to pass", status.isOK());
Change undo= performChange(ref, true);
assertNotNull(undo);
Expand Down
3 changes: 2 additions & 1 deletion org.eclipse.jdt.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ Require-Bundle:
org.eclipse.jdt.jeview,
org.eclipse.jdt.astview,
org.eclipse.compare.core,
org.eclipse.compare
org.eclipse.compare,
org.eclipse.core.tests.harness
Bundle-RequiredExecutionEnvironment: JavaSE-17
Eclipse-BundleShape: dir
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.junit.Before;
import org.junit.Test;

import org.eclipse.core.tests.harness.FussyProgressMonitor;

import org.eclipse.core.runtime.IPath;

import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -140,7 +142,10 @@ public void testBasicCreate() throws Exception {
IProject project= fWizardPage.getProjectHandle();

IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
op.run(null);
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
op.run(testMonitor);
testMonitor.assertUsedUp();


IJavaProject jproj= fWizardPage.getNewJavaProject();

Expand All @@ -167,7 +172,10 @@ public void testProjectChange() throws Exception {
fWizardPage.setProjectHandle(otherProject);

IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
op.run(null);
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
op.run(testMonitor);
testMonitor.assertUsedUp();


IJavaProject jproj= fWizardPage.getNewJavaProject();

Expand Down Expand Up @@ -232,7 +240,10 @@ public void testUserCreate() throws Exception {
fWizardPage.setDefaultClassPath(entries, true);

IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
op.run(null);
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
op.run(testMonitor);
testMonitor.assertUsedUp();


IJavaProject jproj= fWizardPage.getNewJavaProject();

Expand All @@ -257,7 +268,10 @@ public void testReadExisting() throws Exception {
fWizardPage.setDefaultClassPath(entries, true);

IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
op.run(null);
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
op.run(testMonitor);
testMonitor.assertUsedUp();


IProject proj= fWizardPage.getNewJavaProject().getProject();

Expand All @@ -278,7 +292,10 @@ public void testExistingOverwrite() throws Exception {
IProject project= fWizardPage.getProjectHandle();

IRunnableWithProgress op= new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
op.run(null);
FussyProgressMonitor testMonitor= new FussyProgressMonitor();
op.run(testMonitor);
testMonitor.assertUsedUp();


IPath folderPath= project.getFolder("dbin").getFullPath();
IClasspathEntry[] entries= new IClasspathEntry[] {
Expand Down
Loading

0 comments on commit cc856df

Please sign in to comment.