mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 23:39:39 +07:00
test++
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
class InStaticInitializer {
|
||||
public static final String x = "Hello World";
|
||||
|
||||
static {
|
||||
System.out.println(x);
|
||||
}
|
||||
//Field must be placed before initializer or illegal forward reference will happen
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import org.junit.*;
|
||||
public class T {
|
||||
private int i;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import org.junit.*;
|
||||
public class T {
|
||||
private int i;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
|
||||
public class T {
|
||||
private int i;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
public static final String string;
|
||||
|
||||
public void demo(String val){
|
||||
if ("test1".equals(val)){
|
||||
//do somethign
|
||||
} else {
|
||||
string = "test2";
|
||||
if (string.equals(val)) {
|
||||
//... something else
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import junit.framework.TestCase;
|
||||
public class T extends TestCase {
|
||||
private int i;
|
||||
|
||||
public void test() {
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import junit.framework.TestCase;
|
||||
public class T extends TestCase {
|
||||
private int i;
|
||||
|
||||
public void setUp() {
|
||||
i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
public class FieldTest {
|
||||
private Object comboBox;
|
||||
|
||||
private class NoSelectionComboItem {
|
||||
public final Object comboBox;
|
||||
|
||||
private NoSelectionComboItem() {
|
||||
comboBox = FieldTest.this.comboBox;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
Object comboItem = comboBox.getSelectedItem();
|
||||
return comboItem == this ? "<Please Select>" : "<Back to overview>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import junit.framework.TestCase;
|
||||
|
||||
class Base extends TestCase {
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
}
|
||||
}
|
||||
|
||||
public class T extends Base {
|
||||
private int i;
|
||||
|
||||
public void test() {
|
||||
}
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class InStaticInitializer {
|
||||
static {
|
||||
System.out.println(<selection>"Hello World"</selection>);
|
||||
}
|
||||
//Field must be placed before initializer or illegal forward reference will happen
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.junit.*;
|
||||
public class T {
|
||||
@Test
|
||||
public void test() {
|
||||
int <caret>i = 9;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp(){}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import org.junit.*;
|
||||
public class T {
|
||||
@Test
|
||||
public void test() {
|
||||
int <caret>i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import org.junit.Test;
|
||||
public class T {
|
||||
@Test
|
||||
public void test() {
|
||||
int <caret>i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
public void demo(String val){
|
||||
if ("test1".equals(val)){
|
||||
//do somethign
|
||||
} else if (<selection>"test2"</selection>.equals(val)) {
|
||||
//... something else
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import junit.framework.TestCase;
|
||||
public class T extends TestCase {
|
||||
public void test() {
|
||||
int <caret>i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import junit.framework.TestCase;
|
||||
public class T extends TestCase {
|
||||
public void setUp() {
|
||||
int <caret>i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
public class FieldTest {
|
||||
private Object comboBox;
|
||||
|
||||
private class NoSelectionComboItem {
|
||||
private NoSelectionComboItem() {
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
Object comboItem = <selection>comboBox</selection>.getSelectedItem();
|
||||
return comboItem == this ? "<Please Select>" : "<Back to overview>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import junit.framework.TestCase;
|
||||
|
||||
class Base extends TestCase {
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
}
|
||||
}
|
||||
|
||||
public class T extends Base {
|
||||
public void test() {
|
||||
int <caret>i = 9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.refactoring.introduceField.BaseExpressionToFieldHandler;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.JavaTestUtil;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class IntroduceFieldInSameClassTest extends LightCodeInsightTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
public void testInClassInitializer () throws Exception {
|
||||
configureByFile("/refactoring/introduceField/before1.java");
|
||||
performRefactoring(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, true);
|
||||
checkResultByFile("/refactoring/introduceField/after1.java");
|
||||
}
|
||||
|
||||
public void testInElseClause() throws Exception {
|
||||
configureByFile("/refactoring/introduceField/beforeElseClause.java");
|
||||
performRefactoring(BaseExpressionToFieldHandler.InitializationPlace.IN_CURRENT_METHOD, true);
|
||||
checkResultByFile("/refactoring/introduceField/afterElseClause.java");
|
||||
}
|
||||
|
||||
public void testOuterClass() throws Exception {
|
||||
configureByFile("/refactoring/introduceField/beforeOuterClass.java");
|
||||
performRefactoring(BaseExpressionToFieldHandler.InitializationPlace.IN_CONSTRUCTOR, false);
|
||||
checkResultByFile("/refactoring/introduceField/afterOuterClass.java");
|
||||
}
|
||||
|
||||
private static void performRefactoring(final BaseExpressionToFieldHandler.InitializationPlace initializationPlace, final boolean declareStatic) {
|
||||
new MockIntroduceFieldHandler(initializationPlace, declareStatic).invoke(getProject(), myEditor, myFile, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 17-Oct-2007
|
||||
*/
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiLocalVariable;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.introduceField.BaseExpressionToFieldHandler;
|
||||
import com.intellij.refactoring.introduceField.LocalToFieldHandler;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class IntroduceFieldWitSetUpInitializationTest extends CodeInsightTestCase {
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
protected Module createModule(final String name) {
|
||||
final Module module = super.createModule(name);
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final LibraryTable.ModifiableModel modifiableModel = model.getModuleLibraryTable().getModifiableModel();
|
||||
final Library library = modifiableModel.createLibrary("junit");
|
||||
final Library.ModifiableModel libModel = library.getModifiableModel();
|
||||
libModel.addRoot(VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Before.class))), OrderRootType.CLASSES);
|
||||
libModel.commit();
|
||||
model.commit();
|
||||
return module;
|
||||
}
|
||||
|
||||
public void testInSetUp() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInitiallyInSetUp() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPublicBaseClassSetUp() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testBeforeExist() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testBeforeNotExist() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testBeforeNotExist1() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
private void doTest() throws Exception {
|
||||
configureByFile("/refactoring/introduceField/before" + getTestName(false) + ".java");
|
||||
final PsiLocalVariable local =
|
||||
PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class);
|
||||
new LocalToFieldHandler(getProject(), false) {
|
||||
protected BaseExpressionToFieldHandler.Settings showRefactoringDialog(final PsiClass aClass,
|
||||
final PsiLocalVariable local,
|
||||
final PsiExpression[] occurences,
|
||||
final boolean isStatic) {
|
||||
return new BaseExpressionToFieldHandler.Settings("i", true, false, false,
|
||||
BaseExpressionToFieldHandler.InitializationPlace.IN_SETUP_METHOD,
|
||||
PsiModifier.PRIVATE, local, local.getType(), true, (BaseExpressionToFieldHandler.TargetDestination)null, false,
|
||||
false);
|
||||
}
|
||||
}.convertLocalToField(local, myEditor);
|
||||
checkResultByFile("/refactoring/introduceField/after" + getTestName(false)+ ".java");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.refactoring.introduceField.IntroduceFieldHandler;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class MockIntroduceFieldHandler extends IntroduceFieldHandler {
|
||||
private final InitializationPlace myInitializationPlace;
|
||||
private final boolean myDeclareStatic;
|
||||
|
||||
public MockIntroduceFieldHandler(final InitializationPlace initializationPlace, final boolean declareStatic) {
|
||||
myInitializationPlace = initializationPlace;
|
||||
myDeclareStatic = declareStatic;
|
||||
}
|
||||
|
||||
protected Settings showRefactoringDialog(Project project, Editor editor, PsiClass parentClass, PsiExpression expr, PsiType type,
|
||||
PsiExpression[] occurences, PsiElement anchorElement, PsiElement anchorElementIfAll) {
|
||||
SuggestedNameInfo name = JavaCodeStyleManager.getInstance(project).suggestVariableName(VariableKind.FIELD, null, expr, type);
|
||||
return new Settings(name.names[0], true, myDeclareStatic, true, myInitializationPlace,
|
||||
PsiModifier.PUBLIC,
|
||||
null,
|
||||
type, true, (TargetDestination)null, false, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user