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 Vadim L. Bogdanov
019: * @version $Revision$
020: */package javax.swing.text.html;
021:
022: import javax.swing.AbstractAction;
023: import javax.swing.JEditorPane;
024: import javax.swing.SwingTestCase;
025: import javax.swing.text.BadLocationException;
026:
027: public class HTMLEditorKit_InsertHTMLTextActionTest extends
028: SwingTestCase {
029: private final String name = "name";
030: private final HTML.Tag addTag = HTML.Tag.I;
031: private final HTML.Tag alternateAddTag = HTML.Tag.B;
032: private final HTML.Tag alternateParentTag = HTML.Tag.I;
033: private final String html = "<i><b>html text</b></i>";
034: private final HTML.Tag parentTag = HTML.Tag.B;
035:
036: private HTMLEditorKit.InsertHTMLTextAction action;
037: private JEditorPane pane;
038: private HTMLDocument document;
039:
040: public HTMLEditorKit_InsertHTMLTextActionTest(final String name) {
041: super (name);
042: }
043:
044: protected void setUp() throws Exception {
045: super .setUp();
046: setIgnoreNotImplemented(true);
047:
048: pane = new JEditorPane();
049: pane.setEditorKit(new HTMLEditorKit());
050: document = (HTMLDocument) pane.getDocument();
051:
052: action = new HTMLEditorKit.InsertHTMLTextAction(name, html,
053: parentTag, addTag, alternateParentTag, alternateAddTag);
054: }
055:
056: protected void tearDown() throws Exception {
057: super .tearDown();
058: }
059:
060: public void testInsertHTMLTextActionStringStringTagTagTagTag() {
061: action = new HTMLEditorKit.InsertHTMLTextAction(name, html,
062: parentTag, addTag, alternateParentTag, alternateAddTag);
063: assertSame(name, action.getValue(AbstractAction.NAME));
064: assertSame(html, action.html);
065: assertSame(parentTag, action.parentTag);
066: assertSame(addTag, action.addTag);
067: assertSame(alternateParentTag, action.alternateParentTag);
068: assertSame(alternateAddTag, action.alternateAddTag);
069: }
070:
071: public void testInsertHTMLTextActionStringStringTagTag() {
072: action = new HTMLEditorKit.InsertHTMLTextAction(name, html,
073: parentTag, addTag);
074: assertSame(name, action.getValue(AbstractAction.NAME));
075: assertSame(html, action.html);
076: assertSame(parentTag, action.parentTag);
077: assertSame(addTag, action.addTag);
078: assertNull(action.alternateParentTag);
079: assertNull(action.alternateAddTag);
080: }
081:
082: public void testActionPerformed() {
083: action.actionPerformed(null);
084: // TODO: implement
085: }
086:
087: public void testInsertHTML() throws BadLocationException {
088: action.insertHTML(pane, document, 0, html, 0, 0, addTag);
089: assertEquals("html text", document.getText(0, document
090: .getLength()));
091:
092: testExceptionalCase(new ExceptionalCase() {
093: public Class expectedExceptionClass() {
094: return RuntimeException.class;
095: }
096:
097: public void exceptionalAction() throws Exception {
098: action.insertHTML(pane, document,
099: document.getLength() + 1, html, 0, 0, addTag);
100: }
101: });
102: }
103:
104: public void testInsertAtBoundary() {
105: // TODO: implement
106: }
107: }
|