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_RADIO_BUTTON; 19 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.core.runtime.NullProgressMonitor; 22 import org.eclipse.ltk.core.refactoring.Change; 23 import org.w3c.dom.Element; 24 25 import java.util.List; 26 27 public class ChangeViewRefactoringTest extends RefactoringTest { 28 29 public void testChangeView1() throws Exception { 30 checkRefactoring("sample1a.xml", FQCN_RADIO_BUTTON, "@+id/button1", "@+id/button6"); 31 } 32 33 public void testChangeView2() throws Exception { 34 // Tests (1) updating references to the renamed id of the changed widgets 35 // (e.g. button3 is renamed to imageButton1 and layout references to button3 36 // must be updated), and (2) removal of attributes not available in the new type 37 // (the text property is removed since it is not available on the new widget 38 // type ImageButton) 39 checkRefactoring("sample2.xml", "android.widget.ImageButton", 40 "@+id/button3", "@+id/button5"); 41 } 42 43 private void checkRefactoring(String basename, String newType, 44 String... ids) throws Exception { 45 assertTrue(ids.length > 0); 46 47 IFile file = getLayoutFile(getProject(), basename); 48 TestContext info = setupTestContext(file, basename); 49 TestLayoutEditorDelegate layoutEditor = info.mLayoutEditorDelegate; 50 List<Element> selectedElements = getElements(info.mElement, ids); 51 52 ChangeViewRefactoring refactoring = new ChangeViewRefactoring(selectedElements, 53 layoutEditor); 54 refactoring.setType(newType); 55 56 List<Change> changes = refactoring.computeChanges(new NullProgressMonitor()); 57 checkEdits(basename, changes); 58 } 59 } 60