001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing;
021:
022: import java.awt.FlowLayout;
023: import java.awt.GridLayout;
024: import java.awt.LayoutManager;
025: import java.io.IOException;
026: import javax.accessibility.AccessibleRole;
027: import javax.swing.plaf.PanelUI;
028: import javax.swing.plaf.basic.BasicPanelUI;
029:
030: public class JPanelTest extends SwingTestCase {
031: /**
032: * @param arg0
033: */
034: public JPanelTest(final String arg0) {
035: super (arg0);
036: }
037:
038: protected JPanel panel = null;
039:
040: public static void main(final String[] args) {
041: junit.textui.TestRunner.run(JPanelTest.class);
042: }
043:
044: /*
045: * @see TestCase#setUp()
046: */
047: @Override
048: protected void setUp() throws Exception {
049: super .setUp();
050: panel = new JPanel();
051: }
052:
053: /*
054: * @see TestCase#tearDown()
055: */
056: @Override
057: protected void tearDown() throws Exception {
058: super .tearDown();
059: }
060:
061: /*
062: * Class under test for void updateUI()
063: */
064: public void testUpdateUI() {
065: panel.setUI(null);
066: panel.updateUI();
067: assertTrue(panel.getUI() != null);
068: }
069:
070: /*
071: * Class under test for void JPanel(LayoutManager, boolean)
072: */
073: public void testJPanelLayoutManagerboolean() {
074: final LayoutManager layout1 = new GridLayout(2, 2);
075: panel = new JPanel(layout1, true);
076: assertTrue(panel.isOpaque());
077: assertSame(layout1, panel.getLayout());
078: assertTrue(panel.isDoubleBuffered());
079: final LayoutManager layout2 = new FlowLayout();
080: panel = new JPanel(layout2, false);
081: assertTrue(panel.isOpaque());
082: assertSame(layout2, panel.getLayout());
083: assertFalse(panel.isDoubleBuffered());
084: }
085:
086: /*
087: * Class under test for void JPanel(LayoutManager)
088: */
089: public void testJPanelLayoutManager() {
090: final LayoutManager layout1 = new GridLayout(2, 2);
091: panel = new JPanel(layout1);
092: assertTrue(panel.isOpaque());
093: assertSame(layout1, panel.getLayout());
094: assertTrue(panel.isDoubleBuffered());
095: final LayoutManager layout2 = new FlowLayout();
096: panel = new JPanel(layout2);
097: assertTrue(panel.isOpaque());
098: assertSame(layout2, panel.getLayout());
099: assertTrue(panel.isDoubleBuffered());
100: }
101:
102: /*
103: * Class under test for void JPanel(boolean)
104: */
105: public void testJPanelboolean() {
106: panel = new JPanel(true);
107: assertTrue(panel.isOpaque());
108: assertTrue(panel.getLayout().getClass() == FlowLayout.class);
109: assertTrue(panel.isDoubleBuffered());
110: panel = new JPanel(false);
111: assertTrue(panel.isOpaque());
112: assertTrue(panel.getLayout().getClass() == FlowLayout.class);
113: assertFalse(panel.isDoubleBuffered());
114: }
115:
116: /*
117: * Class under test for void JPanel()
118: */
119: public void testJPanel() {
120: assertTrue(panel.isOpaque());
121: assertTrue(panel.getLayout().getClass() == FlowLayout.class);
122: assertTrue(panel.isDoubleBuffered());
123: }
124:
125: /*
126: * Class under test for void setUI(PanelUI)
127: */
128: public void testSetUIPanelUI() {
129: PanelUI panelUI = null;
130: panel.setUI(panelUI);
131: assertEquals(panelUI, panel.getUI());
132: panelUI = new BasicPanelUI();
133: panel.setUI(panelUI);
134: assertEquals(panelUI, panel.getUI());
135: }
136:
137: public void testGetUI() {
138: testSetUIPanelUI();
139: }
140:
141: /*
142: * Class under test for AccessibleContext getAccessibleContext()
143: */
144: public void testGetAccessibleContext() {
145: boolean assertedValue = (panel.getAccessibleContext() != null && panel
146: .getAccessibleContext().getClass().getName().equals(
147: "javax.swing.JPanel$AccessibleJPanel"));
148: assertTrue(assertedValue);
149: assertTrue(panel.getAccessibleContext().getAccessibleRole()
150: .equals(AccessibleRole.PANEL));
151: }
152:
153: /*
154: * Class under test for String paramString()
155: */
156: public void testParamString() {
157: class TestingPanel extends JPanel {
158: private static final long serialVersionUID = 1L;
159:
160: public String getParamString() {
161: return paramString();
162: }
163: }
164: TestingPanel testingPanel = new TestingPanel();
165: assertTrue(testingPanel.getParamString() != null);
166: assertTrue(testingPanel.getParamString() != "");
167: }
168:
169: /*
170: * Class under test for String getUIClassID()
171: */
172: public void testGetUIClassID() {
173: assertEquals("PanelUI", panel.getUIClassID());
174: }
175:
176: public void testWriteObject() throws IOException {
177: /*
178: JPanel button1 = new JPanel();
179: JPanel button2 = new JPanel();
180: FileOutputStream fo = new FileOutputStream("tmp");
181: ObjectOutputStream so = new ObjectOutputStream(fo);
182: so.writeObject(button1);
183: so.flush();
184: fo = new FileOutputStream("tmp");
185: so = new ObjectOutputStream(fo);
186: so.writeObject(button1);
187: so.flush();
188: */
189: }
190:
191: public void testReadObject() throws IOException,
192: ClassNotFoundException {
193: /*
194: JPanel button1 = new JPanel();
195: JPanel button2 = new JPanel();
196: FileOutputStream fo = new FileOutputStream("tmp");
197: ObjectOutputStream so = new ObjectOutputStream(fo);
198: so.writeObject(button1);
199: so.flush();
200: FileInputStream fi = new FileInputStream("tmp");
201: ObjectInputStream si = new ObjectInputStream(fi);
202: JPanel ressurectedButton = (JPanel)si.readObject();
203: fo = new FileOutputStream("tmp");
204: so = new ObjectOutputStream(fo);
205: so.writeObject(button2);
206: so.flush();
207: fi = new FileInputStream("tmp");
208: si = new ObjectInputStream(fi);
209: ressurectedButton = (JPanel)si.readObject();
210: */
211: }
212: }
|