|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| WindowMonitorT.java | 50% | 97.1% | 85.7% | 93% |
|
||||||||||||||
| 1 |
package junit.extensions.jfcunit;
|
|
| 2 |
|
|
| 3 |
import junit.extensions.jfcunit.finder.JMenuItemFinder;
|
|
| 4 |
|
|
| 5 |
import java.awt.Window;
|
|
| 6 |
import java.awt.event.ActionEvent;
|
|
| 7 |
import java.util.Arrays;
|
|
| 8 |
import java.util.Vector;
|
|
| 9 |
|
|
| 10 |
import javax.swing.JButton;
|
|
| 11 |
import javax.swing.AbstractAction;
|
|
| 12 |
import javax.swing.JFrame;
|
|
| 13 |
import javax.swing.JMenuItem;
|
|
| 14 |
import javax.swing.JPopupMenu;
|
|
| 15 |
|
|
| 16 |
/**
|
|
| 17 |
* Test class to exercise the WindowMonitor class.
|
|
| 18 |
*
|
|
| 19 |
* @author Kevin Wilson
|
|
| 20 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
| 21 |
*/
|
|
| 22 |
public class WindowMonitorT |
|
| 23 |
extends AbstractTestCase {
|
|
| 24 |
/**
|
|
| 25 |
* <code>Window</code> which is being tested.
|
|
| 26 |
*/
|
|
| 27 |
private Window m_window = null; |
|
| 28 |
|
|
| 29 |
/**
|
|
| 30 |
* Constructor.
|
|
| 31 |
*
|
|
| 32 |
* @param name Test case name.
|
|
| 33 |
*/
|
|
| 34 | 2 |
public WindowMonitorT(final String name) {
|
| 35 | 2 |
super(name);
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
/**
|
|
| 39 |
* Setup the test case.
|
|
| 40 |
*
|
|
| 41 |
* @exception Exception An instance of java.lang.Exception can be thrown
|
|
| 42 |
*/
|
|
| 43 | 2 |
protected void setUp() throws Exception { |
| 44 | 2 |
super.setUp();
|
| 45 | 2 |
if (getHelper() == null) { |
| 46 | 2 |
setHelper(new JFCTestHelper());
|
| 47 |
} |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
/**
|
|
| 51 |
* Overridden method that is used to remove the test fixtures.
|
|
| 52 |
*
|
|
| 53 |
* @exception Exception An instance of java.lang.Exception can be thrown
|
|
| 54 |
*/
|
|
| 55 | 2 |
protected void tearDown() throws Exception { |
| 56 | 2 |
TestHelper.disposeWindow(m_window, this);
|
| 57 | 2 |
super.tearDown();
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/** Flag to check if ABC was pressed. */
|
|
| 61 |
private boolean m_abcPressed = false; |
|
| 62 |
|
|
| 63 |
/** Flag to check if DEF was pressed. */
|
|
| 64 |
private boolean m_defPressed = false; |
|
| 65 |
|
|
| 66 |
/**
|
|
| 67 |
* Validate that we can capture the Heavy Weight
|
|
| 68 |
* popup window.
|
|
| 69 |
*/
|
|
| 70 | 1 |
public void testGetPopupMenu() { |
| 71 | 1 |
JButton button = new JButton("TEST"); |
| 72 | 1 |
JPopupMenu menu = new JPopupMenu("TEST Menu"); |
| 73 | 1 |
menu.setLightWeightPopupEnabled(false);
|
| 74 | 1 |
menu.add(new AbstractAction("ABC") { |
| 75 | 1 |
public void actionPerformed(final ActionEvent ae) { |
| 76 | 1 |
m_abcPressed = true;
|
| 77 |
} |
|
| 78 |
}); |
|
| 79 | 1 |
menu.add(new AbstractAction("DEF") { |
| 80 | 0 |
public void actionPerformed(final ActionEvent ae) { |
| 81 | 0 |
m_defPressed = true;
|
| 82 |
} |
|
| 83 |
}); |
|
| 84 |
|
|
| 85 | 1 |
JFrame frame = createJFrame(null);
|
| 86 | 1 |
m_window = frame; // register this to be destroyed at the end
|
| 87 | 1 |
frame.getContentPane().add(button); |
| 88 | 1 |
frame.pack(); |
| 89 | 1 |
frame.setTitle("testPopup");
|
| 90 | 1 |
frame.setVisible(true);
|
| 91 | 1 |
menu.show(button, 30, 30); |
| 92 |
|
|
| 93 | 1 |
flushAWT(); |
| 94 |
|
|
| 95 | 1 |
setHelper(new JFCTestHelper());
|
| 96 | 1 |
JMenuItem item = (JMenuItem) new JMenuItemFinder("ABC").find(0); |
| 97 | 1 |
assertNotNull("Could not find the first item in menu:", item);
|
| 98 | 1 |
getHelper().enterClickAndLeave(new junit.extensions.jfcunit.eventdata.
|
| 99 |
MouseEventData(this, item));
|
|
| 100 | 1 |
assertTrue("ABC not pressed", m_abcPressed);
|
| 101 |
|
|
| 102 | 1 |
menu.show(button, 30, 30); |
| 103 | 1 |
item = (JMenuItem) new JMenuItemFinder("DEF").find(0); |
| 104 | 1 |
assertNotNull("Could not find the second item in menu:", item);
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/**
|
|
| 108 |
* Validate that we can capture the JWindow.
|
|
| 109 |
*/
|
|
| 110 | 1 |
public void testGetWindowsJWindow() { |
| 111 | 1 |
SplashScreen splashScreen = new SplashScreen();
|
| 112 |
|
|
| 113 | 1 |
Window[] windows = WindowMonitor.getWindows(); |
| 114 | 1 |
Vector results = new Vector(Arrays.asList(windows));
|
| 115 | 1 |
assertTrue("Windows are not the same", results.contains(splashScreen));
|
| 116 | 1 |
m_window = splashScreen; // register this to be destroyed at the end
|
| 117 |
} |
|
| 118 |
} |
|
| 119 |
|
|
||||||||||