1 6 7 package org.jdesktop.swing; 8 9 import java.awt.BorderLayout ; 10 import java.awt.Point ; 11 12 import java.lang.reflect.Method ; 13 14 import javax.swing.JComponent ; 15 import javax.swing.JFrame ; 16 import javax.swing.JScrollPane ; 17 import javax.swing.JToolBar ; 18 19 41 public abstract class InteractiveTestCase extends junit.framework.TestCase { 42 private Point frameLocation = new Point (0,0); 43 44 protected InteractiveTestCase(String testTitle) { 45 super(testTitle); 46 } 47 48 public JFrame wrapWithScrollingInFrame(JComponent component, String title) { 49 JScrollPane scroller = new JScrollPane (component); 50 return wrapInFrame(scroller, title); 51 } 52 53 public JFrame wrapInFrame(JComponent component, String title) { 54 JFrame frame = new JFrame (title); 55 JToolBar toolbar = new JToolBar (); 56 frame.getContentPane().add(BorderLayout.CENTER, component); 57 frame.getContentPane().add(BorderLayout.NORTH, toolbar); 58 frame.pack(); 59 frame.setLocation(frameLocation); 60 if (frameLocation.x == 0) { 61 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 62 frame.setTitle(title+" [close me and all tests will close]"); 63 } 64 frameLocation.x += 30; 65 frameLocation.y += 30; 66 return frame; 67 } 68 69 74 public void runInteractiveTests(String regexPattern) throws java.lang.Exception { 75 setUp(); 76 Class testClass = getClass(); 77 Method methods[] = testClass.getMethods(); 78 79 for (int i = 0; i < methods.length; i++) { 80 if (methods[i].getName().matches(regexPattern)) { 81 try { 82 methods[i].invoke(this, null); 83 } 84 catch (Exception e) { 85 System.out.println("could not run interactive test: " + 86 methods[i].getName()); 87 e.printStackTrace(); 88 } 89 } 90 } 91 if (methods.length == 0) { 92 System.out.println("no test methods found matching the pattern: "+ 93 regexPattern); 94 } 95 tearDown(); 96 } 97 98 102 public void runInteractiveTests() throws java.lang.Exception { 103 runInteractiveTests("interactive.*"); 104 } 105 106 107 } 108 | Popular Tags |