1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.ui.IEditorInput; 15 import org.eclipse.ui.IEditorPart; 16 import org.eclipse.ui.IPersistableElement; 17 import org.eclipse.ui.IPropertyListener; 18 import org.eclipse.ui.IViewPart; 19 import org.eclipse.ui.IWorkbenchPart; 20 import org.eclipse.ui.IWorkbenchPart2; 21 22 public class PartTester { 23 private PartTester() { 24 } 25 26 36 public static void testEditor(IEditorPart part) throws Exception { 37 testWorkbenchPart(part); 38 39 Assert.isTrue(part.getEditorSite() == part.getSite(), 40 "The part's editor site must be the same as the part's site"); IEditorInput input = part.getEditorInput(); 42 Assert.isNotNull(input, "The editor input must be non-null"); testEditorInput(input); 44 45 part.isDirty(); 46 part.isSaveAsAllowed(); 47 part.isSaveOnCloseNeeded(); 48 } 49 50 public static void testEditorInput(IEditorInput input) throws Exception { 51 input.getAdapter(Object .class); 52 53 57 Assert.isNotNull(input.getName(), 58 "The editor input must have a non-null name"); Assert.isNotNull(input.getToolTipText(), 60 "The editor input must have a non-null tool tip"); 62 IPersistableElement persistableElement = input.getPersistable(); 64 if (persistableElement != null) { 65 Assert 66 .isNotNull(persistableElement.getFactoryId(), 67 "The persistable element for the editor input must have a non-null factory id"); } 69 } 70 71 78 private static void testWorkbenchPart(IWorkbenchPart part) throws Exception { 79 IPropertyListener testListener = new IPropertyListener() { 80 public void propertyChanged(Object source, int propId) { 81 82 } 83 }; 84 85 part.addPropertyListener(testListener); 87 88 part.removePropertyListener(testListener); 90 91 Assert.isTrue(part.equals(part), "A part must be equal to itself"); Assert.isTrue(!part.equals(new Integer (32)), 94 "A part must have a meaningful equals method"); 96 Object partAdapter = part.getAdapter(part.getClass()); 98 Assert.isTrue(partAdapter == null || partAdapter == part, 99 "A part must adapter to itself or return null"); 101 Assert.isNotNull(part.getTitle(), "A part's title must be non-null"); 104 Assert.isNotNull(part.getTitleImage(), 106 "A part's title image must be non-null"); 108 Assert.isNotNull(part.getTitleToolTip(), 110 "A part's title tool tip must be non-null"); 112 Assert.isNotNull(part.toString(), 114 "A part's toString method must return a non-null value"); 116 part.hashCode(); 118 119 if (part instanceof IWorkbenchPart2) { 120 testWorkbenchPart2((IWorkbenchPart2)part); 121 } 122 } 123 124 private static void testWorkbenchPart2(IWorkbenchPart2 part) 125 throws Exception { 126 Assert.isNotNull(part.getContentDescription(), 127 "A part must return a non-null content description"); Assert.isNotNull(part.getPartName(), 129 "A part must return a non-null part name"); } 131 132 142 public static void testView(IViewPart part) throws Exception { 143 Assert.isTrue(part.getSite() == part.getViewSite(), 144 "A part's site must be the same as a part's view site"); testWorkbenchPart(part); 146 } 147 } 148 | Popular Tags |