Home | History | Annotate | Download | only in refactoring
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.ide.eclipse.adt.internal.editors.layout.refactoring;
     17 
     18 import static com.android.SdkConstants.FQCN_GESTURE_OVERLAY_VIEW;
     19 import static com.android.SdkConstants.FQCN_LINEAR_LAYOUT;
     20 
     21 import org.eclipse.core.resources.IFile;
     22 import org.eclipse.core.runtime.NullProgressMonitor;
     23 import org.eclipse.ltk.core.refactoring.Change;
     24 import org.w3c.dom.Element;
     25 
     26 import java.util.List;
     27 
     28 public class WrapInRefactoringTest extends RefactoringTest {
     29 
     30     public void testWrapIn1() throws Exception {
     31         // Test wrapping view: should indent view
     32         checkRefactoring("sample3.xml", FQCN_LINEAR_LAYOUT, "@+id/button2");
     33     }
     34 
     35     public void testWrapIn2() throws Exception {
     36         // Test wrapping the root: should move namespace
     37         checkRefactoring("sample3.xml", FQCN_GESTURE_OVERLAY_VIEW, "@+id/newlinear");
     38     }
     39 
     40     public void testWrapIn3() throws Exception {
     41         // Test wrap multiple adjacent elements - should wrap all as a unit
     42         checkRefactoring("sample3.xml", FQCN_LINEAR_LAYOUT, "@+id/button2", "@+id/android_logo");
     43     }
     44 
     45     private void checkRefactoring(String basename, String fqcn, String... ids) throws Exception {
     46         assertTrue(ids.length > 0);
     47 
     48         IFile file = getLayoutFile(getProject(), basename);
     49         TestContext info = setupTestContext(file, basename);
     50         TestLayoutEditorDelegate layoutEditor = info.mLayoutEditorDelegate;
     51         List<Element> selectedElements = getElements(info.mElement, ids);
     52 
     53         WrapInRefactoring refactoring = new WrapInRefactoring(selectedElements,
     54                 layoutEditor);
     55         refactoring.setType(fqcn);
     56         List<Change> changes = refactoring.computeChanges(new NullProgressMonitor());
     57         checkEdits(basename, changes);
     58     }
     59 }
     60