aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core
diff options
context:
space:
mode:
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeMoveParticipantTest.java135
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeRenameParticipantTest.java160
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java110
3 files changed, 0 insertions, 405 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeMoveParticipantTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeMoveParticipantTest.java
deleted file mode 100644
index 262ea420e..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeMoveParticipantTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.ide.eclipse.adt.internal.refactorings.core;
-
-import com.android.annotations.NonNull;
-import com.android.ide.eclipse.adt.AdtPlugin;
-import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
-
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.IMovePolicy;
-import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor;
-import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgDestinationFactory;
-import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory;
-import org.eclipse.jdt.internal.ui.refactoring.reorg.CreateTargetQueries;
-import org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgQueries;
-import org.eclipse.ltk.core.refactoring.participants.MoveRefactoring;
-import org.eclipse.swt.widgets.Shell;
-
-
-@SuppressWarnings({"javadoc", "restriction"})
-public class AndroidTypeMoveParticipantTest extends RefactoringTestBase {
- public void testRefactor1() throws Exception {
- moveType(
- TEST_PROJECT2,
- "com.example.refactoringtest.CustomView1",
- "src/com/example/refactoringtest/subpackage",
- true /*updateReferences*/,
-
- "CHANGES:\n" +
- "-------\n" +
- "[x] Move resource 'testRefactor1/src/com/example/refactoringtest/CustomView1.java' to 'subpackage'\n" +
- "\n" +
- "[x] Move resource 'testRefactor1/src/com/example/refactoringtest/CustomView1.java' to 'subpackage'\n" +
- "\n" +
- "[x] customviews.xml - /testRefactor1/res/layout/customviews.xml\n" +
- " @@ -9 +9\n" +
- " - <com.example.refactoringtest.CustomView1\n" +
- " + <com.example.refactoringtest.subpackage.CustomView1\n" +
- "\n" +
- "\n" +
- "[x] customviews.xml - /testRefactor1/res/layout-land/customviews.xml\n" +
- " @@ -9 +9\n" +
- " - <com.example.refactoringtest.CustomView1\n" +
- " + <com.example.refactoringtest.subpackage.CustomView1");
- }
-
- public void testRefactorFragment() throws Exception {
- moveType(
- TEST_PROJECT2,
- "com.example.refactoringtest.MyFragment",
- "src/com/example/refactoringtest/subpackage",
- true /*updateReferences*/,
-
- "CHANGES:\n" +
- "-------\n" +
- "[x] Move resource 'testRefactorFragment/src/com/example/refactoringtest/MyFragment.java' to 'subpackage'\n" +
- "\n" +
- "[x] Move resource 'testRefactorFragment/src/com/example/refactoringtest/MyFragment.java' to 'subpackage'\n" +
- "\n" +
- "[x] activity_main.xml - /testRefactorFragment/res/layout/activity_main.xml\n" +
- " @@ -33 +33\n" +
- " - <fragment android:name=\"com.example.refactoringtest.MyFragment\"/>\n" +
- " + <fragment android:name=\"com.example.refactoringtest.subpackage.MyFragment\"/>");
- }
-
- public void testRefactor1_norefs() throws Exception {
- moveType(
- TEST_PROJECT2,
- "com.example.refactoringtest.CustomView1",
- "src/com/example/refactoringtest/subpackage",
- false /*updateReferences*/,
-
- "CHANGES:\n" +
- "-------\n" +
- "[x] Move resource 'testRefactor1_norefs/src/com/example/refactoringtest/CustomView1.java' to 'subpackage'\n" +
- "\n" +
- "[x] Move resource 'testRefactor1_norefs/src/com/example/refactoringtest/CustomView1.java' to 'subpackage'");
- }
-
- // ---- Test infrastructure ----
-
- protected void moveType(
- @NonNull Object[] testData,
- @NonNull String typeFqcn,
- @NonNull String destination,
- boolean updateReferences,
- @NonNull String expected) throws Exception {
- IProject project = createProject(testData);
-
- IFolder destinationFolder = project.getFolder(destination);
-
- IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
- assertNotNull(javaProject);
- IType type = javaProject.findType(typeFqcn);
- assertNotNull(typeFqcn, type);
- assertTrue(typeFqcn, type.exists());
- IResource resource = type.getResource();
- assertNotNull(typeFqcn, resource);
- assertTrue(typeFqcn, resource.exists());
-
- IResource[] resources = new IResource[] { resource };
- IJavaElement[] elements = new IJavaElement[] { type };
- IMovePolicy policy = ReorgPolicyFactory.createMovePolicy(resources, elements);
- JavaMoveProcessor processor = new JavaMoveProcessor(policy);
- processor.setUpdateReferences(updateReferences);
- processor.setUpdateQualifiedNames(true);
- assertTrue(policy.canEnable());
- processor.setDestination(ReorgDestinationFactory.createDestination(destinationFolder));
- Shell parent = AdtPlugin.getShell();
- assertNotNull(parent);
- processor.setCreateTargetQueries(new CreateTargetQueries(parent));
- processor.setReorgQueries(new ReorgQueries(parent));
-
- MoveRefactoring refactoring = new MoveRefactoring(processor);
- checkRefactoring(refactoring, expected);
- }
-}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeRenameParticipantTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeRenameParticipantTest.java
deleted file mode 100644
index f65124a2c..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/AndroidTypeRenameParticipantTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.ide.eclipse.adt.internal.refactorings.core;
-
-import com.android.annotations.NonNull;
-import com.android.ide.eclipse.adt.internal.project.BaseProjectHelper;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor;
-import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
-
-
-@SuppressWarnings({"javadoc", "restriction"})
-public class AndroidTypeRenameParticipantTest extends RefactoringTestBase {
- public void testRefactor1() throws Exception {
- renameType(
- TEST_PROJECT,
- "com.example.refactoringtest.MainActivity",
- true /*updateReferences*/,
- "NewActivityName",
-
- "CHANGES:\n" +
- "-------\n" +
- "[x] Rename compilation unit 'MainActivity.java' to 'NewActivityName.java'\n" +
- "\n" +
- "[x] activity_main.xml - /testRefactor1/res/layout/activity_main.xml\n" +
- " @@ -5 +5\n" +
- " - tools:context=\".MainActivity\" >\n" +
- " + tools:context=\".NewActivityName\" >\n" +
- "\n" +
- "\n" +
- "[x] activity_main.xml - /testRefactor1/res/layout-land/activity_main.xml\n" +
- " @@ -5 +5\n" +
- " - tools:context=\".MainActivity\" >\n" +
- " + tools:context=\".NewActivityName\" >\n" +
- "\n" +
- "\n" +
- "[x] AndroidManifest.xml - /testRefactor1/AndroidManifest.xml\n" +
- " @@ -16 +16\n" +
- " - android:name=\"com.example.refactoringtest.MainActivity\"\n" +
- " + android:name=\"com.example.refactoringtest.NewActivityName\"");
- }
-
- public void testRefactor1b() throws Exception {
- renameType(
- TEST_PROJECT,
- "com.example.refactoringtest.MainActivity2",
- true /*updateReferences*/,
- "NewActivityName",
-
- "CHANGES:\n" +
- "-------\n" +
- "[x] Rename compilation unit 'MainActivity2.java' to 'NewActivityName.java'\n" +
- "\n" +
- "[x] AndroidManifest.xml - /testRefactor1b/AndroidManifest.xml\n" +
- " @@ -25 +25\n" +
- " - android:name=\".MainActivity2\"\n" +
- " + android:name=\".NewActivityName\"");
- }
-
- public void testRefactor1_noreferences() throws Exception {
- renameType(
- TEST_PROJECT,
- "com.example.refactoringtest.MainActivity",
- false /*updateReferences*/,
- "NewActivityName",
-
- "CHANGES:\n" +
- "-------\n" +
- "[x] Rename compilation unit 'MainActivity.java' to 'NewActivityName.java'");
- }
-
- public void testRefactor2() throws Exception {
- renameType(
- TEST_PROJECT2,
- "com.example.refactoringtest.CustomView1",
- true /*updateReferences*/,
- "NewCustomViewName",
-
- "CHANGES:\n" +
- "-------\n" +
- "[x] Rename compilation unit 'CustomView1.java' to 'NewCustomViewName.java'\n" +
- "\n" +
- "[x] attrs_custom_view.xml - /testRefactor2/res/values/attrs_custom_view.xml\n" +
- " @@ -4 +4\n" +
- " - <declare-styleable name=\"CustomView1\">\n" +
- " + <declare-styleable name=\"NewCustomViewName\">\n" +
- "\n" +
- "\n" +
- "[x] customviews.xml - /testRefactor2/res/layout/customviews.xml\n" +
- " @@ -9 +9\n" +
- " - <com.example.refactoringtest.CustomView1\n" +
- " + <com.example.refactoringtest.NewCustomViewName\n" +
- "\n" +
- "\n" +
- "[x] customviews.xml - /testRefactor2/res/layout-land/customviews.xml\n" +
- " @@ -9 +9\n" +
- " - <com.example.refactoringtest.CustomView1\n" +
- " + <com.example.refactoringtest.NewCustomViewName");
- }
-
- public void testRefactorFragment() throws Exception {
- renameType(
- TEST_PROJECT2,
- "com.example.refactoringtest.MyFragment",
- true /*updateReferences*/,
- "NewFragmentName",
-
- "CHANGES:\n" +
- "-------\n" +
- "[x] Rename compilation unit 'MyFragment.java' to 'NewFragmentName.java'\n" +
- "\n" +
- "[x] activity_main.xml - /testRefactorFragment/res/layout/activity_main.xml\n" +
- " @@ -33 +33\n" +
- " - <fragment android:name=\"com.example.refactoringtest.MyFragment\"/>\n" +
- " + <fragment android:name=\"com.example.refactoringtest.NewFragmentName\"/>");
- }
-
- // ---- Test infrastructure ----
-
- protected void renameType(
- @NonNull Object[] testData,
- @NonNull String typeFqcn,
- boolean updateReferences,
- @NonNull String newName,
- @NonNull String expected) throws Exception {
- IProject project = createProject(testData);
- IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
- assertNotNull(javaProject);
- IType type = javaProject.findType(typeFqcn);
- assertNotNull(typeFqcn, type);
- assertTrue(typeFqcn, type.exists());
- RenameTypeProcessor processor = new RenameTypeProcessor(type);
- processor.setNewElementName(newName);
- processor.setUpdateQualifiedNames(true);
- processor.setUpdateSimilarDeclarations(false);
- //processor.setMatchStrategy(?);
- //processor.setFilePatterns(patterns);
- processor.setUpdateReferences(updateReferences);
- assertNotNull(processor);
-
- RenameRefactoring refactoring = new RenameRefactoring(processor);
- checkRefactoring(refactoring, expected);
- }
-}
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java
deleted file mode 100644
index e00a44b32..000000000
--- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/refactorings/core/RenameResourceXmlTextActionTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.ide.eclipse.adt.internal.refactorings.core;
-
-import com.android.ide.common.resources.ResourceUrl;
-import com.android.resources.ResourceType;
-
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-
-import junit.framework.TestCase;
-
-@SuppressWarnings("javadoc")
-public class RenameResourceXmlTextActionTest extends TestCase {
- public void test_Simple() throws Exception {
- checkWord("^foo", null);
- checkWord("'foo'^", null);
- checkWord("^@bogus", null);
- checkWord("@bo^gus", null);
- checkWord("bogus@^", null);
- checkWord(" @string/nam^e ", getUrl(ResourceType.STRING, "name"));
- checkWord("@string/nam^e ", getUrl(ResourceType.STRING, "name"));
- checkWord("\"^@string/name ", getUrl(ResourceType.STRING, "name"));
- checkWord("^@string/name ", getUrl(ResourceType.STRING, "name"));
- checkWord("\n^@string/name ", getUrl(ResourceType.STRING, "name"));
- checkWord("\n^@string/name(", getUrl(ResourceType.STRING, "name"));
- checkWord("\n^@string/name;", getUrl(ResourceType.STRING, "name"));
- checkWord("\n^@string/name5", getUrl(ResourceType.STRING, "name5"));
- checkWord("\n@string/name5^", getUrl(ResourceType.STRING, "name5"));
- checkWord("\n@string/name5^(", getUrl(ResourceType.STRING, "name5"));
- checkWord("\n@stri^ng/name5(", getUrl(ResourceType.STRING, "name5"));
- checkWord("\n@string^/name5(", getUrl(ResourceType.STRING, "name5"));
- checkWord("\n@string/^name5(", getUrl(ResourceType.STRING, "name5"));
- checkWord("\n@string^name5(", null);
- checkWord("\n@strings^/name5(", null);
- checkWord("\n@+id/^myid(", getUrl(ResourceType.ID, "myid"));
- checkWord("\n?a^ttr/foo\"", getUrl(ResourceType.ATTR, "foo"));
- checkWord("\n?f^oo\"", getUrl(ResourceType.ATTR, "foo"));
- checkWord("\n^?foo\"", getUrl(ResourceType.ATTR, "foo"));
- }
-
- private static ResourceUrl getUrl(ResourceType type, String name) {
- return ResourceUrl.create(type, name, false, false);
- }
-
- public void testClassNames() throws Exception {
- checkClassName("^foo", null);
- checkClassName("<^foo>", null);
- checkClassName("'foo.bar.Baz'^", null);
- checkClassName("<^foo.bar.Baz ", "foo.bar.Baz");
- checkClassName("<^foo.bar.Baz>", "foo.bar.Baz");
- checkClassName("<foo.^bar.Baz>", "foo.bar.Baz");
- checkClassName("<foo.bar.Baz^>", "foo.bar.Baz");
- checkClassName("<foo.bar.Baz^ >", "foo.bar.Baz");
- checkClassName("<foo.bar$Baz^ >", "foo.bar.Baz");
- checkClassName("</^foo.bar.Baz>", "foo.bar.Baz");
- checkClassName("</foo.^bar.Baz>", "foo.bar.Baz");
-
- checkClassName("\"^foo.bar.Baz\"", "foo.bar.Baz");
- checkClassName("\"foo.^bar.Baz\"", "foo.bar.Baz");
- checkClassName("\"foo.bar.Baz^\"", "foo.bar.Baz");
- checkClassName("\"foo.bar$Baz^\"", "foo.bar.Baz");
-
- checkClassName("<foo.^bar@Baz>", null);
- }
-
- private void checkClassName(String contents, String expectedClassName)
- throws Exception {
- int cursor = contents.indexOf('^');
- assertTrue("Must set cursor position with ^ in " + contents, cursor != -1);
- contents = contents.substring(0, cursor) + contents.substring(cursor + 1);
- assertEquals(-1, contents.indexOf('^'));
- assertEquals(-1, contents.indexOf('['));
- assertEquals(-1, contents.indexOf(']'));
-
- IDocument document = new Document();
- document.replace(0, 0, contents);
- String className =
- RenameResourceXmlTextAction.findClassName(document, null, cursor);
- assertEquals(expectedClassName, className);
- }
-
- private void checkWord(String contents, ResourceUrl expectedResource)
- throws Exception {
- int cursor = contents.indexOf('^');
- assertTrue("Must set cursor position with ^ in " + contents, cursor != -1);
- contents = contents.substring(0, cursor) + contents.substring(cursor + 1);
- assertEquals(-1, contents.indexOf('^'));
- assertEquals(-1, contents.indexOf('['));
- assertEquals(-1, contents.indexOf(']'));
-
- IDocument document = new Document();
- document.replace(0, 0, contents);
- ResourceUrl resource = RenameResourceXmlTextAction.findResource(document, cursor);
- assertEquals(expectedResource, resource);
- }
-}