01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Anton Avtamonov
19: * @version $Revision$
20: */package javax.swing.event;
21:
22: import javax.swing.JTextField;
23: import javax.swing.undo.AbstractUndoableEdit;
24: import javax.swing.undo.UndoableEdit;
25: import junit.framework.TestCase;
26:
27: public class UndoableEditEventTest extends TestCase {
28: private TestUndoableEditListener listener;
29:
30: private Object source;
31:
32: public UndoableEditEventTest(final String name) {
33: super (name);
34: }
35:
36: @Override
37: protected void setUp() throws Exception {
38: listener = new TestUndoableEditListener();
39: source = new Object();
40: }
41:
42: @Override
43: protected void tearDown() throws Exception {
44: listener = null;
45: source = null;
46: }
47:
48: public void testUndoableEditEvent() throws Exception {
49: UndoableEditEvent event = new UndoableEditEvent(source, null);
50: assertEquals(source, event.getSource());
51: }
52:
53: public void testGetEdit() throws Exception {
54: UndoableEdit edit = new AbstractUndoableEdit();
55: UndoableEditEvent event = new UndoableEditEvent(source, edit);
56: assertEquals(edit, event.getEdit());
57: }
58:
59: public void testEventProperlyInitialized() throws Exception {
60: UndoableEditEvent event = new UndoableEditEvent(new Object(),
61: new AbstractUndoableEdit());
62: assertNotNull(event.getSource());
63: assertNotNull(event.getEdit());
64: }
65:
66: public void testEventOccured() throws Exception {
67: JTextField field = new JTextField();
68: field.getDocument().addUndoableEditListener(listener);
69: field.setText("new text");
70: assertNotNull(listener.getEvent());
71: assertNotNull(listener.getEvent().getSource());
72: assertNotNull(listener.getEvent().getEdit());
73: }
74:
75: private class TestUndoableEditListener implements
76: UndoableEditListener {
77: private UndoableEditEvent event;
78:
79: public void undoableEditHappened(final UndoableEditEvent e) {
80: event = e;
81: }
82:
83: public UndoableEditEvent getEvent() {
84: return event;
85: }
86: }
87: }
|