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 org.eclipse.core.resources.IFile;
     19 import org.eclipse.core.runtime.NullProgressMonitor;
     20 import org.eclipse.ltk.core.refactoring.Change;
     21 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
     22 import org.w3c.dom.Element;
     23 
     24 import java.util.List;
     25 
     26 public class UnwrapRefactoringTest extends RefactoringTest {
     27 
     28     public void testUnwrap1() throws Exception {
     29         // Unwrap view with parent, no children - this will unwrap the parent (frame layout)
     30         checkRefactoring("unwrap.xml", "@+id/button");
     31     }
     32 
     33     public void testUnwrap2() throws Exception {
     34         // Unwrap view with parent and children; this should unwrap the element itself
     35         checkRefactoring("unwrap.xml", "@+id/frame");
     36     }
     37 
     38     public void testUnwrap3() throws Exception {
     39         // Unwrap root: should transfer namespace
     40         checkRefactoring("unwrap.xml", "@+id/linear");
     41     }
     42 
     43     private void checkRefactoring(String basename, String id) throws Exception {
     44         IFile file = getLayoutFile(getProject(), basename);
     45         TestContext info = setupTestContext(file, basename);
     46         TestLayoutEditorDelegate layoutEditor = info.mLayoutEditorDelegate;
     47         List<Element> selectedElements = getElements(info.mElement, id);
     48         assertEquals(1, selectedElements.size());
     49 
     50         UnwrapRefactoring refactoring = new UnwrapRefactoring(selectedElements,
     51                 layoutEditor);
     52 
     53         RefactoringStatus status = refactoring.checkInitialConditions(new NullProgressMonitor());
     54         assertFalse(status.hasError());
     55         List<Change> changes = refactoring.computeChanges(new NullProgressMonitor());
     56         checkEdits(basename, changes);
     57     }
     58 }
     59