01: package org.uispec4j;
02:
03: import junit.framework.AssertionFailedError;
04: import org.uispec4j.utils.AssertionFailureNotDetectedError;
05: import org.uispec4j.utils.UIComponentFactory;
06: import org.uispec4j.xml.XmlAssert;
07:
08: import javax.swing.*;
09:
10: public class MenuBarTest extends UIComponentTestCase {
11: private MenuBar menuBar;
12: private JMenuBar jMenuBar;
13: private JMenu jFileMenu;
14: private JMenu jEditMenu;
15:
16: protected void setUp() throws Exception {
17: super .setUp();
18: jMenuBar = new JMenuBar();
19: jFileMenu = new JMenu("File");
20: jFileMenu.setName("fileMenu");
21: jMenuBar.add(jFileMenu);
22: jEditMenu = new JMenu("Edit");
23: jEditMenu.setName("editMenu");
24: jMenuBar.add(jEditMenu);
25: jMenuBar.setName("myMenuBar");
26: menuBar = (MenuBar) UIComponentFactory
27: .createUIComponent(jMenuBar);
28: }
29:
30: public void testGetComponentTypeName() throws Exception {
31: assertEquals("menuBar", menuBar.getDescriptionTypeName());
32: }
33:
34: public void testGetDescription() throws Exception {
35: XmlAssert.assertEquivalent("<menuBar name='myMenuBar'>"
36: + " <menu name='fileMenu'/>"
37: + " <menu name='editMenu'/>" + "</menuBar>", menuBar
38: .getDescription());
39: }
40:
41: public void testFactory() throws Exception {
42: checkFactory(new JMenuBar(), MenuBar.class);
43: }
44:
45: protected UIComponent createComponent() {
46: return menuBar;
47: }
48:
49: public void testGetContents() throws Exception {
50: assertTrue(menuBar
51: .contentEquals(new String[] { "File", "Edit" }));
52: }
53:
54: public void testGetContentsError() throws Exception {
55: try {
56: assertTrue(menuBar.contentEquals(new String[] { "File",
57: "Other" }));
58: throw new AssertionFailureNotDetectedError();
59: } catch (AssertionFailedError e) {
60: }
61: }
62:
63: public void testGetMenu() throws Exception {
64: assertEquals(menuBar.getMenu("File").getAwtComponent(),
65: jFileMenu);
66: assertEquals(menuBar.getMenu("Edit").getAwtComponent(),
67: jEditMenu);
68: }
69: }
|