Skip to content

Commit

Permalink
Add new test for pulling up method in anonymous class that should fail (
Browse files Browse the repository at this point in the history
#1828)

- fixes #1773
  • Loading branch information
jjohnstn authored Dec 3, 2024
1 parent 673d5e7 commit e57bf66
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package p;

public class A {
public class BaseTargetClass {}

public class OriginalClass {
public int data = 60;
public void memberMethod() {}

public class NestedOriginalClass extends BaseTargetClass {
void setup() {
new BaseTargetClass() {
void method() {
methodHelper();
}

void methodHelper() {
System.out.println("Helper Method in Anonymous Class: " + data);
}
};
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,28 @@ public void testFail35() throws Exception {
helper2(new String[] { "method" }, new String[][] { new String[0] }, true, false, 0);
}

@Test
public void testFail36() throws Exception {
ICompilationUnit cu= createCUfromTestFile(getPackageP(), "A");
IJavaElement element= cu.getElementAt(322);
assertTrue("element is method", element instanceof IMethod);
IMethod[] methods= new IMethod[] { (IMethod)element };

PullUpRefactoringProcessor processor= createRefactoringProcessor(methods);
Refactoring ref= processor.getRefactoring();

FussyProgressMonitor testMonitor= new FussyProgressMonitor();
assertTrue("activation", ref.checkInitialConditions(testMonitor).isOK());
testMonitor.assertUsedUp();
testMonitor.prepare();
setTargetClass(processor, 0);

RefactoringStatus checkInputResult= ref.checkFinalConditions(testMonitor);
testMonitor.assertUsedUp();
testMonitor.prepare();
assertFalse("precondition was supposed to fail", checkInputResult.isOK());
// helper2(new String[] { "method" }, new String[][] { new String[0] }, true, false, 0);
}
//----------------------------------------------------------
@Test
public void testField0() throws Exception {
Expand Down

0 comments on commit e57bf66

Please sign in to comment.