mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
encapsulate fields: tests
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
public class A {
|
||||
static int getI() {
|
||||
return 23;
|
||||
}
|
||||
|
||||
static class B {
|
||||
static private int i = 42;
|
||||
|
||||
static int m() {
|
||||
return getI();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(B.m());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
public class A {
|
||||
static int getI() {
|
||||
return 23;
|
||||
}
|
||||
|
||||
static class B {
|
||||
static private int i = 42;
|
||||
|
||||
static int m() {
|
||||
return getI();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(B.m());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
public class A {
|
||||
public int i;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
public int getI() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
A a = new B();
|
||||
a.i = 23;
|
||||
System.out.println(a.i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
public class A {
|
||||
public int i;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
public int getI() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
A a = new B();
|
||||
a.i = 23;
|
||||
System.out.println(a.i);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,14 @@ public class EncapsulateFieldsTest extends MultiFileTestCase{
|
||||
doTest("i", "There already is a method <b><code>Super setI(int)</code></b> which differs from setter <b><code>setI</code></b> by return type only.");
|
||||
}
|
||||
|
||||
public void testHideOverriderMethod() throws Exception {
|
||||
doTest("i", "A", "There is already a <b><code>method <b><code>B.getI()</code></b></code></b> which would hide generated getter for a.i");
|
||||
}
|
||||
|
||||
public void testHideOuterclassMethod() throws Exception {
|
||||
doTest("i", "A.B", "There is already a <b><code>method <b><code>A.getI()</code></b></code></b> which would be hidden by generated getter");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
@@ -41,11 +49,15 @@ public class EncapsulateFieldsTest extends MultiFileTestCase{
|
||||
|
||||
|
||||
private void doTest(final String fieldName, final String conflicts) throws Exception {
|
||||
doTest(fieldName, "Test", conflicts);
|
||||
}
|
||||
|
||||
private void doTest(final String fieldName, final String className, final String conflicts) throws Exception {
|
||||
doTest(new PerformAction() {
|
||||
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {
|
||||
PsiClass aClass = myJavaFacade.findClass("Test", GlobalSearchScope.projectScope(myProject));
|
||||
PsiClass aClass = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(myProject));
|
||||
|
||||
assertNotNull("Class Test not found", aClass);
|
||||
assertNotNull("Tested class not found", aClass);
|
||||
|
||||
|
||||
doTest(aClass, aClass.findFieldByName(fieldName, false), conflicts, true, true);
|
||||
|
||||
Reference in New Issue
Block a user