Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 71595 invoked from network); 26 Nov 2006 20:17:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Nov 2006 20:17:59 -0000 Received: (qmail 19682 invoked by uid 500); 26 Nov 2006 20:18:04 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 19632 invoked by uid 500); 26 Nov 2006 20:18:04 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 19584 invoked by uid 99); 26 Nov 2006 20:18:03 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Nov 2006 12:18:03 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Nov 2006 12:17:44 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id AD8961A9876; Sun, 26 Nov 2006 12:16:17 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r479418 [16/43] - in /harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common: javax/swing/ javax/swing/border/ javax/swing/colorchooser/ javax/swing/event/ javax/swing/filechooser/ javax/swing/plaf/ javax/swing/plaf/basic/ j... Date: Sun, 26 Nov 2006 20:15:55 -0000 To: commits@harmony.apache.org From: ndbeyer@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061126201617.AD8961A9876@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocumentTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocumentTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocumentTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocumentTest.java Sun Nov 26 12:15:43 2006 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * @author Alexey A. Ivanov * @version $Revision$ @@ -26,15 +25,12 @@ import java.util.Dictionary; import java.util.Enumeration; import java.util.Hashtable; - import javax.swing.BasicSwingTestCase; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.AbstractDocument.BranchElement; import javax.swing.text.AbstractDocument.LeafElement; - import junit.framework.TestCase; - import org.apache.harmony.x.swing.StringConstants; /** @@ -42,36 +38,31 @@ * */ public class AbstractDocumentTest extends TestCase { - /** * The content of the document. * (Implementation of AbstractDocument.Content) */ private static GapContent content; + /** * Shared document object. */ private static AbstractDocument doc; + /** * Document property keys. */ - static Integer[] keys = new Integer[] { - new Integer(1), - new Integer(2), - new Integer(3) - }; + static Integer[] keys = new Integer[] { new Integer(1), new Integer(2), new Integer(3) }; + /** * Document property values. */ - static String[] values = new String[] { - "one", - "two", - "three" - }; + static String[] values = new String[] { "one", "two", "three" }; /** * Initializes fixture for tests. */ + @Override protected void setUp() throws Exception { super.setUp(); doc = new DisAbstractedDocument(content = new GapContent()); @@ -82,14 +73,14 @@ * any other. */ protected static class DisAbstractedDocument extends AbstractDocument { + private static final long serialVersionUID = 1L; protected DisAbstractedDocument(final Content content) { super(content); createRoot(); } - public DisAbstractedDocument(final Content content, - final AttributeContext context) { + public DisAbstractedDocument(final Content content, final AttributeContext context) { super(content, context); createRoot(); } @@ -99,20 +90,19 @@ protected void createRoot() { writeLock(); defRoot = new BranchElement(null, null); - defRoot.replace(0, 0, new Element[] { - new LeafElement(defRoot, null, 0, 1) - }); + defRoot.replace(0, 0, new Element[] { new LeafElement(defRoot, null, 0, 1) }); writeUnlock(); } + @Override public Element getParagraphElement(final int offset) { return defRoot.getElement(0); } + @Override public Element getDefaultRootElement() { return defRoot; } - } /** @@ -121,15 +111,13 @@ * AbstractDocument.AttributeContext) */ public void testAbstractDocumentContentAttributeContext() { - GapContent content = new GapContent(); - StyleContext context = new StyleContext(); - AbstractDocument doc = new DisAbstractedDocument(content, context); - + GapContent content = new GapContent(); + StyleContext context = new StyleContext(); + AbstractDocument doc = new DisAbstractedDocument(content, context); assertSame(content, doc.getContent()); assertSame(context, doc.getAttributeContext()); - - Object BidiProperty = BasicSwingTestCase.isHarmony() ? - StringConstants.BIDI_PROPERTY : "i18n"; + Object BidiProperty = BasicSwingTestCase.isHarmony() ? StringConstants.BIDI_PROPERTY + : "i18n"; assertTrue(doc.getProperty(BidiProperty).equals(Boolean.FALSE)); } @@ -137,17 +125,14 @@ * Tests constructor AbstractDocument(AbstractDocument.Content) */ public void testAbstractDocumentContent() { - GapContent content = new GapContent(); - AbstractDocument doc = new DisAbstractedDocument(content); - + GapContent content = new GapContent(); + AbstractDocument doc = new DisAbstractedDocument(content); assertSame(content, doc.getContent()); - assertSame(StyleContext.getDefaultStyleContext(), - doc.getAttributeContext()); + assertSame(StyleContext.getDefaultStyleContext(), doc.getAttributeContext()); } public void testBAD_LOCATION() { - assertEquals("document location failure", - AbstractDocument.BAD_LOCATION); + assertEquals("document location failure", AbstractDocument.BAD_LOCATION); } public void testCreateLeafElement() throws BadLocationException { @@ -156,15 +141,12 @@ assertNull(leaf.getParentElement()); assertEquals(0, leaf.getStartOffset()); assertEquals(1, leaf.getEndOffset()); - doc.insertString(0, "01234", null); - Element leaf2 = doc.createLeafElement(leaf, null, 1, 3); assertTrue(leaf2 instanceof LeafElement); assertSame(leaf, leaf2.getParentElement()); assertEquals(1, leaf2.getStartOffset()); assertEquals(3, leaf2.getEndOffset()); - doc.remove(0, 5); assertEquals(0, leaf2.getStartOffset()); assertEquals(0, leaf2.getEndOffset()); @@ -174,10 +156,8 @@ Element branch = doc.createBranchElement(null, null); assertTrue(branch instanceof BranchElement); assertNull(branch.getParentElement()); - assertNull(branch.getElement(0)); assertNull(branch.getElement(1)); - assertEquals(0, branch.getElementCount()); // Since this branch element has no children yet, it has no start and // end offsets. Thus calling get{Start,End}Offset on an empty branch @@ -186,28 +166,26 @@ // Our implementation try { assertEquals(0, branch.getStartOffset()); - - fail("getStartOffset on an empty BranchElement " - + "causes exception"); - } catch (ArrayIndexOutOfBoundsException e) { } + fail("getStartOffset on an empty BranchElement " + "causes exception"); + } catch (ArrayIndexOutOfBoundsException e) { + } try { assertEquals(1, branch.getEndOffset()); - fail("getEndOffset on an empty BranchElement causes exception"); - } catch (ArrayIndexOutOfBoundsException e) { } + } catch (ArrayIndexOutOfBoundsException e) { + } } else { // Reference implementation try { assertEquals(0, branch.getStartOffset()); - - fail("getStartOffset on an empty BranchElement " - + "causes exception"); - } catch (NullPointerException e) { } + fail("getStartOffset on an empty BranchElement " + "causes exception"); + } catch (NullPointerException e) { + } try { assertEquals(1, branch.getEndOffset()); - fail("getEndOffset on an empty BranchElement causes exception"); - } catch (ArrayIndexOutOfBoundsException e) { } + } catch (ArrayIndexOutOfBoundsException e) { + } } } @@ -218,18 +196,15 @@ int length = doc.getLength(); assertEquals(0, length); assertEquals("", doc.getText(0, length)); - doc.insertString(0, "01234", null); - length = doc.getLength(); assertEquals(5, length); assertEquals("01234", doc.getText(0, length)); - try { doc.insertString(-1, "invalid", null); - fail("BadLocationException should be thrown"); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } /** @@ -239,36 +214,30 @@ int length = doc.getLength(); assertEquals(0, length); assertEquals("", doc.getText(0, length)); - doc.insertString(0, null, null); - // Try to insert null at inappropriate position doc.insertString(-1, null, null); } public void testRemove() throws BadLocationException { doc.insertString(0, "01234", null); - doc.remove(1, 2); assertEquals("034", doc.getText(0, doc.getLength())); - // Invalid offset into the model but remove length is zero - nothing // is done (no exception) doc.remove(-1, 0); - // Invalid offset and non-zero remove length - exception is thrown try { doc.remove(-1, 1); - fail("BadLocationException 'invalid offset' should be thrown"); - } catch (BadLocationException e) { } - + } catch (BadLocationException e) { + } // Invalid length try { doc.remove(0, 4); - fail("BadLocationException 'invalid length' should be thrown"); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } /** @@ -276,29 +245,24 @@ */ public void testReplace01() throws BadLocationException { doc.insertString(0, "01234", null); - doc.replace(1, 2, "abcde", null); assertEquals("0abcde34", doc.getText(0, doc.getLength())); - doc.replace(0, 5, null, null); assertEquals("e34", doc.getText(0, doc.getLength())); - doc.replace(0, 2, "", null); assertEquals("4", doc.getText(0, doc.getLength())); - // Invalid offset into the model try { doc.replace(-1, 0, "some text", null); - fail("BadLocationException 'invalid offset' should be thrown"); - } catch (BadLocationException e) { } - + } catch (BadLocationException e) { + } // Invalid length try { doc.replace(0, 4, "some text", null); - fail("BadLocationException 'invalid length' should be thrown"); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } /** @@ -307,17 +271,19 @@ */ public void testReplace02() throws BadLocationException { doc.insertString(0, "01234", null); - final class DocListener implements DocumentListener { private boolean insert = false; + private boolean remove = false; public void changedUpdate(final DocumentEvent event) { fail("changedUpdate is not expected to be called"); } + public void insertUpdate(final DocumentEvent event) { insert = true; } + public void removeUpdate(final DocumentEvent event) { remove = true; } @@ -325,23 +291,17 @@ public void check(final boolean eInsert, final boolean eRemove) { assertEquals(eInsert, insert); assertEquals(eRemove, remove); - insert = remove = false; } } - DocListener listener = new DocListener(); - doc.addDocumentListener(listener); - doc.replace(0, 2, null, null); assertEquals("234", doc.getText(0, doc.getLength())); listener.check(false, true); - doc.replace(0, 2, "", null); assertEquals("4", doc.getText(0, doc.getLength())); listener.check(false, true); - doc.replace(0, 0, "", null); listener.check(false, false); } @@ -353,12 +313,10 @@ for (int i = 0; i < keys.length; i++) { doc.putProperty(keys[i], values[i]); } - // Check for (int i = 0; i < keys.length; i++) { assertEquals(values[i], doc.getProperty(keys[i])); } - // Test property removal doc.putProperty(keys[0], null); assertNull(doc.getProperty(keys[0])); @@ -369,49 +327,45 @@ */ public void testGetTextintintSegment() throws BadLocationException { Segment txt = new Segment(); - doc.insertString(0, "01234abcde", null); doc.insertString(5, "!", null); - doc.getText(0, 5, txt); assertEquals("01234", txt.toString()); assertEquals(0, txt.offset); assertEquals(5, txt.count); assertSame(content.getArray(), txt.array); - doc.getText(6, 5, txt); assertEquals("abcde", txt.toString()); int gapLength = content.getGapEnd() - content.getGapStart(); - assertEquals(6 + gapLength, txt.offset); assertEquals(5, txt.count); assertSame(content.getArray(), txt.array); - doc.getText(0, 11, txt); assertEquals("01234!abcde", txt.toString()); assertEquals(0, txt.offset); assertEquals(11, txt.count); assertNotSame(content.getArray(), txt.array); - txt.setPartialReturn(true); doc.getText(0, 11, txt); assertEquals("01234!", txt.toString()); assertEquals(0, txt.offset); assertEquals(6, txt.count); assertSame(content.getArray(), txt.array); - try { doc.getText(-1, 5, txt); fail("BadLocationException: \"invalid offset\" must be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } try { doc.getText(12, 1, txt); fail("BadLocationException: \"invalid offset\" must be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } try { doc.getText(0, 13, txt); fail("BadLocationException: \"invalid length\" must be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } /** @@ -420,26 +374,27 @@ public void testGetTextintint() throws BadLocationException { doc.insertString(0, "01234abcde", null); doc.insertString(5, "!", null); - // before the gap assertEquals("01234", doc.getText(0, 5)); // after the gap assertEquals("abcde", doc.getText(6, 5)); // the gap is the middle assertEquals("01234!abcde", doc.getText(0, 11)); - try { doc.getText(-1, 5); fail("BadLocationException: \"invalid offset\" must be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } try { doc.getText(12, 1); fail("BadLocationException: \"invalid offset\" must be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } try { doc.getText(0, 13); fail("BadLocationException: \"invalid length\" must be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } /** @@ -448,21 +403,17 @@ public void testCreatePosition() throws BadLocationException { try { doc.createPosition(-2); - if (BasicSwingTestCase.isHarmony()) { fail("BadLocationException should be thrown"); } - } catch (BadLocationException e) { } - + } catch (BadLocationException e) { + } Position pos0 = doc.createPosition(0); Position pos5 = doc.createPosition(5); - assertEquals(0, pos0.getOffset()); assertEquals(5, pos5.getOffset()); - doc.insertString(0, "01234", null); - - assertEquals(0, pos0.getOffset()); + assertEquals(0, pos0.getOffset()); assertEquals(10, pos5.getOffset()); } @@ -472,21 +423,17 @@ */ public void testGetStartEndPosition() throws BadLocationException { Position start = doc.getStartPosition(); - Position end = doc.getEndPosition(); + Position end = doc.getEndPosition(); assertEquals(0, start.getOffset()); assertEquals(1, end.getOffset()); - doc.insertString(0, "01234", null); assertEquals(0, start.getOffset()); assertEquals(6, end.getOffset()); - doc.insertString(2, "abcde", null); assertEquals(0, start.getOffset()); assertEquals(11, end.getOffset()); - assertSame(start, doc.getStartPosition()); assertSame(end, doc.getEndPosition()); - doc.remove(0, 6); assertEquals("e234", doc.getText(0, doc.getLength())); assertEquals(0, start.getOffset()); @@ -498,7 +445,6 @@ assertEquals(2, roots.length); assertNotNull(roots[0]); assertSame(roots[0], doc.getDefaultRootElement()); - assertNotNull(roots[1]); assertSame(roots[1], doc.getBidiRootElement()); } @@ -510,12 +456,12 @@ assertEquals("bidi root", root.getName()); assertEquals(0, root.getStartOffset()); assertEquals(1, root.getEndOffset()); - Enumeration elements = ((BranchElement)root).children(); - Element element = null; + Enumeration elements = ((BranchElement) root).children(); + Element element = null; int count = 0; while (elements.hasMoreElements()) { count++; - element = (Element)elements.nextElement(); + element = (Element) elements.nextElement(); } // if the document is empty there should be only one child assertEquals(1, count); @@ -531,19 +477,16 @@ } public void testGetAttributeContext() { - assertSame(StyleContext.getDefaultStyleContext(), - doc.getAttributeContext()); + assertSame(StyleContext.getDefaultStyleContext(), doc.getAttributeContext()); } public void testSetGetDocumentProperties() { - Hashtable table = new Hashtable(); + Hashtable table = new Hashtable(); for (int i = 0; i < keys.length; i++) { table.put(keys[i], values[i]); } - assertNotSame(table, doc.getDocumentProperties()); doc.setDocumentProperties(table); - assertSame(table, doc.getDocumentProperties()); for (int i = 0; i < keys.length; i++) { assertEquals(values[i], doc.getProperty(keys[i])); @@ -553,17 +496,9 @@ public void testDump() { ByteArrayOutputStream out = new ByteArrayOutputStream(); doc.dump(new PrintStream(out)); - assertEquals("\n" + - " \n" + - " [0,1][\n" + - "]\n" + - "\n" + - " \n" + - " [0,1][\n" + - "]\n", - filterNewLines(out.toString())); + assertEquals("\n" + " \n" + " [0,1][\n" + "]\n" + + "\n" + " \n" + + " [0,1][\n" + "]\n", filterNewLines(out.toString())); } public static String filterNewLines(final String str) { @@ -575,7 +510,6 @@ */ public void testSetGetDocumentFilter() { assertNull(doc.getDocumentFilter()); - DocumentFilter filter = new DocumentFilter(); doc.setDocumentFilter(filter); assertSame(filter, doc.getDocumentFilter()); @@ -584,9 +518,7 @@ public void testGetLength() throws BadLocationException { int length = doc.getLength(); assertEquals(0, length); - doc.insertString(0, "01234", null); - length = doc.getLength(); assertEquals(5, length); } @@ -609,10 +541,9 @@ */ public void testSetGetAsynchronousLoadPriority02() { final String key = "load priority"; - final Dictionary properties = doc.getDocumentProperties(); + final Dictionary properties = doc.getDocumentProperties(); assertEquals(1, properties.size()); assertNotNull(properties.get("i18n")); - // Test the default assertEquals(-1, doc.getAsynchronousLoadPriority()); // Change the default @@ -621,26 +552,22 @@ assertEquals(2, properties.size()); Object value = doc.getProperty(key); assertTrue(value instanceof Integer); - assertEquals(10, ((Integer)value).intValue()); + assertEquals(10, ((Integer) value).intValue()); assertEquals(10, doc.getAsynchronousLoadPriority()); - doc.putProperty(key, new Integer(-255)); assertEquals(-255, doc.getAsynchronousLoadPriority()); - doc.putProperty(key, "123"); if (BasicSwingTestCase.isHarmony()) { assertEquals(-1, doc.getAsynchronousLoadPriority()); } else { try { doc.getAsynchronousLoadPriority(); - fail("ClassCastException is expected"); - } catch (ClassCastException e) { } + } catch (ClassCastException e) { + } } - doc.putProperty(key, null); assertEquals(1, properties.size()); assertEquals(-1, doc.getAsynchronousLoadPriority()); } - } Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElementRTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElementRTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElementRTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElementRTest.java Sun Nov 26 12:15:43 2006 @@ -21,65 +21,81 @@ package javax.swing.text; import java.util.Enumeration; - import javax.swing.text.AbstractDocument.AbstractElement; import javax.swing.text.AbstractDocument.BranchElement; - import junit.framework.TestCase; public class AbstractDocument_AbstractElementRTest extends TestCase { private static class AbstractElementImpl extends AbstractElement { + private static final long serialVersionUID = 1L; + public static final int START_OFFSET = -101; + public static final int END_OFFSET = -10; - public AbstractElementImpl(final AbstractDocument doc, - final Element parent, - final AttributeSet attrs) { + + public AbstractElementImpl(final AbstractDocument doc, final Element parent, + final AttributeSet attrs) { doc.super(parent, attrs); } + @Override public boolean getAllowsChildren() { return false; } + + @Override public boolean isLeaf() { return true; } - public Enumeration children() { + + @SuppressWarnings("unchecked") + @Override + public Enumeration children() { return null; } + + @Override public Element getElement(int index) { return null; } + + @Override public int getElementCount() { return 0; } + + @Override public int getElementIndex(int offset) { return 0; } + + @Override public int getStartOffset() { return START_OFFSET; } + + @Override public int getEndOffset() { return END_OFFSET; } } private AbstractDocument doc; + private Element root; + private Element element; + private MutableAttributeSet attrs; public void testGetNameAbstract() throws Exception { final String name = "Unbekannte"; attrs.addAttribute(AbstractDocument.ElementNameAttribute, name); - element = new AbstractElementImpl(doc, root, attrs); assertSame(name, element.getName()); assertSame(root, element.getParentElement()); - - attrs.removeAttribute(AbstractDocument.ElementNameAttribute); assertEquals(0, attrs.getAttributeCount()); - element = new AbstractElementImpl(doc, root, attrs); assertNull(element.getName()); assertSame(root, element.getParentElement()); @@ -89,7 +105,6 @@ final String name = "Blatt"; attrs.addAttribute(AbstractDocument.ElementNameAttribute, name); element = doc.new LeafElement(root, attrs, 15, 23); - assertSame(name, element.getName()); assertEquals(15, element.getStartOffset()); assertEquals(23, element.getEndOffset()); @@ -100,35 +115,32 @@ final String name = "Ast"; attrs.addAttribute(AbstractDocument.ElementNameAttribute, name); element = doc.new BranchElement(root, attrs); - assertSame(name, element.getName()); assertSame(root, element.getParentElement()); } public void testGetNameNonString() throws Exception { - attrs.addAttribute(AbstractDocument.ElementNameAttribute, - new Integer(10101)); + attrs.addAttribute(AbstractDocument.ElementNameAttribute, new Integer(10101)); element = new AbstractElementImpl(doc, root, attrs); - try { element.getName(); fail("ClassCastException is expected"); - } catch (ClassCastException e) { } + } catch (ClassCastException e) { + } } - + public void testGetNameParent() throws Exception { final String parentName = "parentName"; attrs.addAttribute(AbstractDocument.ElementNameAttribute, parentName); BranchElement parent = doc.new BranchElement(null, attrs); AbstractElement element = new AbstractElementImpl(doc, parent, null); - assertTrue(parent.isDefined(AbstractDocument.ElementNameAttribute)); assertEquals(parentName, parent.getName()); - assertFalse(element.isDefined(AbstractDocument.ElementNameAttribute)); assertNull(element.getName()); } + @Override protected void setUp() throws Exception { super.setUp(); doc = new PlainDocument(); @@ -137,6 +149,7 @@ doc.writeLock(); } + @Override protected void tearDown() throws Exception { super.tearDown(); doc.writeUnlock(); Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElementTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElementTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElementTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElementTest.java Sun Nov 26 12:15:43 2006 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * @author Alexey A. Ivanov * @version $Revision$ @@ -24,31 +23,30 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Enumeration; - import javax.swing.BasicSwingTestCase; import javax.swing.text.AbstractDocument.AbstractElement; - import junit.framework.TestCase; - /** * Tests AbstractDocument.AbstractElement class. * */ public class AbstractDocument_AbstractElementTest extends TestCase { - /** * Shared document object. */ protected static DisAbstractedDocument aDocument; + /** * Shared element object. */ protected static DisAbstractedDocument.DisAbstractedElement aElement; + /** * Shared element with parent (= aElement). */ protected static AbstractElement parented; + /** * Attribute set used to initialize parented. */ @@ -58,6 +56,7 @@ * Implementor of abtract methods in AbstractDocument. */ protected static class DisAbstractedDocument extends AbstractDocument { + private static final long serialVersionUID = 1L; protected DisAbstractedDocument(final Content content) { super(content); @@ -68,61 +67,74 @@ * */ class DisAbstractedElement extends AbstractDocument.AbstractElement { + private static final long serialVersionUID = 1L; public DisAbstractedElement(final Element initParent, - final AttributeSet initAttributes) { + final AttributeSet initAttributes) { super(initParent, initAttributes); } + @Override public Element getElement(final int a0) { return null; } - public Enumeration children() { + @SuppressWarnings("unchecked") + @Override + public Enumeration children() { return null; } + @Override public int getElementIndex(final int a0) { return 0; } + @Override public boolean isLeaf() { return false; } + @Override public boolean getAllowsChildren() { return false; } + @Override public int getStartOffset() { return 0; } + @Override public int getEndOffset() { return 0; } + @Override public int getElementCount() { return 0; } } + @Override public Element getParagraphElement(final int a0) { return null; } + @Override public Element getDefaultRootElement() { return null; } - }; + @Override protected void setUp() throws Exception { super.setUp(); init(); aDocument.writeLock(); } + @Override protected void tearDown() throws Exception { super.tearDown(); aDocument.writeUnlock(); @@ -135,15 +147,10 @@ protected static void init() { StyleContextTest.sc = StyleContext.getDefaultStyleContext(); aSet = StyleContextTest.addAttribute(null, 5, 3); - aDocument = new DisAbstractedDocument(new GapContent()); - aDocument.writeLock(); - - aElement = aDocument.new DisAbstractedElement(null, - StyleContextTest.addAttribute(2)); + aElement = aDocument.new DisAbstractedElement(null, StyleContextTest.addAttribute(2)); parented = aDocument.new DisAbstractedElement(aElement, aSet); - aDocument.writeUnlock(); } @@ -154,11 +161,9 @@ assertSame(aElement, parented.getParentElement()); assertTrue(parented.containsAttributes(aSet)); assertSame(aElement, parented.getResolveParent()); - // Test with null attribute set aElement = aDocument.new DisAbstractedElement(null, null); assertEquals(0, aElement.getAttributeCount()); - // Following assertion fails, the reason being Element contains method // doesn't take into account parent element //assertTrue(parented.containsAttributes(aElement)); @@ -169,18 +174,14 @@ */ public void testAbstractElement02() { aDocument.writeUnlock(); - // When attributes are null, the exception isn't thrown aElement = aDocument.new DisAbstractedElement(null, null); - try { // When attributes are not null, though empty, the exception // is thrown. - aElement = aDocument.new DisAbstractedElement(null, - StyleContext.getDefaultStyleContext().getEmptySet()); - - fail("Error 'Illegal cast to MutableAttributeSet' " - + "should be thrown"); + aElement = aDocument.new DisAbstractedElement(null, StyleContext + .getDefaultStyleContext().getEmptySet()); + fail("Error 'Illegal cast to MutableAttributeSet' " + "should be thrown"); } catch (Error e) { // Do nothing } finally { @@ -198,7 +199,6 @@ assertNull(copy.getResolveParent()); assertNull(aElement.getResolveParent()); assertTrue(copy.isEqual(aElement)); - copy = parented.copyAttributes(); assertNotSame(copy, parented); assertFalse(copy instanceof Element); @@ -224,96 +224,58 @@ } public void testDump() throws BadLocationException { - String dump1 = - "\n" + - " \n" + - " [0,6][01234\n" + - "]\n" + - "\n" + - " [0,3][012]\n"; - - String dump2 = - "\n" + - " \n" + - " [0,6][01234\n" + - "]\n" + - "\n" + - " [0,3][012]\n"; - + String dump1 = "\n" + " \n" + + " [0,6][01234\n" + "]\n" + "\n" + " [0,3][012]\n"; + String dump2 = "\n" + " \n" + + " [0,6][01234\n" + "]\n" + "\n" + " [0,3][012]\n"; ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(out); aDocument.insertString(0, "01234", null); - ((AbstractElement)aDocument.getBidiRootElement()).dump(ps, 0); + ((AbstractElement) aDocument.getBidiRootElement()).dump(ps, 0); aDocument.new LeafElement(null, null, 0, 3).dump(ps, 0); - String dump = BasicSwingTestCase.isHarmony() ? dump2 : dump1; assertEquals(dump, AbstractDocumentTest.filterNewLines(out.toString())); } - private static final String dumpTextAtLimit = - "123456789\n" + // 10 chars / 10 - "123456789\n" + // 10 chars / 20 - "123456789\n" + // 10 chars / 30 - "aaabbbccc"; // 9 chars / 39 + 1 def '\n' - private static final String dumpTextBeyondLimit = - "123456789\n" + // 10 chars / 10 - "123456789\n" + // 10 chars / 20 - "123456789\n" + // 10 chars / 30 - "aaabbbccc1234567890"; // 19 chars / 49 + 1 def '\n' + private static final String dumpTextAtLimit = "123456789\n" + // 10 chars / 10 + "123456789\n" + // 10 chars / 20 + "123456789\n" + // 10 chars / 30 + "aaabbbccc"; // 9 chars / 39 + 1 def '\n' + + private static final String dumpTextBeyondLimit = "123456789\n" + // 10 chars / 10 + "123456789\n" + // 10 chars / 20 + "123456789\n" + // 10 chars / 30 + "aaabbbccc1234567890"; // 19 chars / 49 + 1 def '\n' public void testDumpAtTextLimit() throws BadLocationException { - String dump = - "\n" + - " \n" + - " [0,40][123456789\n" + - "123456789\n" + - "123456789\n" + - "aaabbbccc\n" + - "]\n"; - + String dump = "\n" + " \n" + + " [0,40][123456789\n" + "123456789\n" + "123456789\n" + "aaabbbccc\n" + + "]\n"; ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(out); aDocument.insertString(0, dumpTextAtLimit, null); - ((AbstractElement)aDocument.getBidiRootElement()).dump(ps, 0); - + ((AbstractElement) aDocument.getBidiRootElement()).dump(ps, 0); assertEquals(dump, AbstractDocumentTest.filterNewLines(out.toString())); } public void testDumpBeyondTextLimit() throws BadLocationException { - String dump = - "\n" + - " \n" + - " [0,50][123456789\n" + - "123456789\n" + - "123456789\n" + - "aaabbbccc1...]\n"; - + String dump = "\n" + " \n" + + " [0,50][123456789\n" + "123456789\n" + "123456789\n" + "aaabbbccc1...]\n"; ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(out); aDocument.insertString(0, dumpTextBeyondLimit, null); - ((AbstractElement)aDocument.getBidiRootElement()).dump(ps, 0); - + ((AbstractElement) aDocument.getBidiRootElement()).dump(ps, 0); assertEquals(dump, AbstractDocumentTest.filterNewLines(out.toString())); } public void testGetAttributeThruParent() { assertFalse(parented.isDefined(StyleContextTest.attr[0])); assertTrue(aElement.isDefined(StyleContextTest.attr[0])); - // containsAttribute method DOES NOT look up attributes in parent - assertFalse(parented.containsAttribute(StyleContextTest.attr[1], - parented.getAttribute(StyleContextTest.attr[0]))); + assertFalse(parented.containsAttribute(StyleContextTest.attr[1], parented + .getAttribute(StyleContextTest.attr[0]))); // getAttribute DOES look up attributes in parent - assertSame(StyleContextTest.attr[1], - parented.getAttribute(StyleContextTest.attr[0])); + assertSame(StyleContextTest.attr[1], parented.getAttribute(StyleContextTest.attr[0])); } public void testGetResolveParent() { @@ -330,12 +292,14 @@ protected static class OtherElement implements Element { public static final String key = "OE_Key"; + public static final String value = "OE_Value"; private MutableAttributeSet attrs = new SimpleAttributeSet(); { attrs.addAttribute(key, value); } + public boolean isAttrsNull; public AttributeSet getAttributes() { @@ -377,7 +341,6 @@ public boolean isLeaf() { return true; } - } public void testGetAttributesOtherParent() throws Exception { @@ -385,7 +348,6 @@ parented = aDocument.new DisAbstractedElement(parent, null); assertSame(OtherElement.value, parented.getAttribute(OtherElement.key)); assertFalse(parented.isDefined(OtherElement.key)); - parent.isAttrsNull = true; assertNull(parented.getAttribute(OtherElement.key)); } @@ -395,35 +357,33 @@ parented = aDocument.new DisAbstractedElement(parent, null); assertNotSame(parent, parent.getAttributes()); assertSame(parent.getAttributes(), parented.getResolveParent()); - parent.isAttrsNull = true; assertNull(parented.getResolveParent()); } - // These are tests for abstract methods /* - public void testIsLeaf() { + public void testIsLeaf() { - } + } - public void testChildren() { + public void testChildren() { - } + } - public void testGetAllowsChildren() { + public void testGetAllowsChildren() { - } + } - public void testGetStartOffset() { + public void testGetStartOffset() { - } + } - public void testGetEndOffset() { + public void testGetEndOffset() { - } + } - public void testGetElementCount() { + public void testGetElementCount() { - } - */ + } + */ } Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_MASNoLockTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_MASNoLockTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_MASNoLockTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_MASNoLockTest.java Sun Nov 26 12:15:43 2006 @@ -14,14 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * @author Alexey A. Ivanov * @version $Revision$ */ package javax.swing.text; - import junit.framework.Test; import junit.framework.TestSuite; @@ -32,9 +30,8 @@ * those test-methods which modify the attribute set. * */ -public class AbstractDocument_AbstractElement_MASNoLockTest - extends AbstractDocument_AbstractElement_MASTest { - +public class AbstractDocument_AbstractElement_MASNoLockTest extends + AbstractDocument_AbstractElement_MASTest { public AbstractDocument_AbstractElement_MASNoLockTest(final String name) { super(name); } @@ -43,86 +40,94 @@ TestSuite suite = new TestSuite(); suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest("testAddAttribute")); suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest("testAddAttributes")); - suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest("testRemoveAttribute")); - suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest("testRemoveAttributesAttributeSetDiff")); - suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest("testRemoveAttributesAttributeSetSame")); - suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest("testRemoveAttributesEnumeration")); - suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest("testAddAttributeAnotherThread")); + suite + .addTest(new AbstractDocument_AbstractElement_MASNoLockTest( + "testRemoveAttribute")); + suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest( + "testRemoveAttributesAttributeSetDiff")); + suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest( + "testRemoveAttributesAttributeSetSame")); + suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest( + "testRemoveAttributesEnumeration")); + suite.addTest(new AbstractDocument_AbstractElement_MASNoLockTest( + "testAddAttributeAnotherThread")); return suite; } + @Override protected void setUp() throws Exception { super.setUp(); aDocument.writeUnlock(); } + @Override protected void tearDown() throws Exception { // Lock the document 'cause super tearDown unlocks it aDocument.writeLock(); super.tearDown(); } + @Override public void testAddAttribute() { try { super.testAddAttribute(); - - fail("Error should be thrown, the reason " - + "being no write lock acquired"); - } catch (Error e) { } + fail("Error should be thrown, the reason " + "being no write lock acquired"); + } catch (Error e) { + } } + @Override public void testAddAttributes() { try { super.testAddAttributes(); - - fail("Error should be thrown, the reason " - + "being no write lock acquired"); - } catch (Error e) { } + fail("Error should be thrown, the reason " + "being no write lock acquired"); + } catch (Error e) { + } } + @Override public void testRemoveAttribute() { try { super.testRemoveAttribute(); - - fail("Error should be thrown, the reason " - + "being no write lock acquired"); - } catch (Error e) { } + fail("Error should be thrown, the reason " + "being no write lock acquired"); + } catch (Error e) { + } } + @Override public void testRemoveAttributesAttributeSetDiff() { try { super.testRemoveAttributesAttributeSetDiff(); - - fail("Error should be thrown, the reason " - + "being no write lock acquired"); - } catch (Error e) { } + fail("Error should be thrown, the reason " + "being no write lock acquired"); + } catch (Error e) { + } } + @Override public void testRemoveAttributesAttributeSetSame() { try { super.testRemoveAttributesAttributeSetSame(); - - fail("Error should be thrown, the reason " - + "being no write lock acquired"); - } catch (Error e) { } + fail("Error should be thrown, the reason " + "being no write lock acquired"); + } catch (Error e) { + } } + @Override public void testRemoveAttributesEnumeration() { try { super.testRemoveAttributesEnumeration(); - - fail("Error should be thrown, the reason " - + "being no write lock acquired"); - } catch (Error e) { } + fail("Error should be thrown, the reason " + "being no write lock acquired"); + } catch (Error e) { + } } + @Override public void testSetResolveParent() { try { super.testSetResolveParent(); - - fail("Error should be thrown, the reason " - + "being no write lock acquired"); - } catch (Error e) { } + fail("Error should be thrown, the reason " + "being no write lock acquired"); + } catch (Error e) { + } } /** @@ -139,7 +144,6 @@ */ public void testAddAttributeAnotherThread() throws InterruptedException { aDocument.writeLock(); - new Thread(new Runnable() { public void run() { try { @@ -149,9 +153,7 @@ } } }).start(); - Thread.sleep(500); - assertTrue(exceptionThrown); } } Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_MASTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_MASTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_MASTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_MASTest.java Sun Nov 26 12:15:43 2006 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * @author Alexey A. Ivanov * @version $Revision$ @@ -31,30 +30,32 @@ * execution of test-methods. * */ -public class AbstractDocument_AbstractElement_MASTest - extends MutableAttributeSetTest { - +public class AbstractDocument_AbstractElement_MASTest extends MutableAttributeSetTest { protected DisAbstractedDocument aDocument; - protected DisAbstractedElement aElement; - protected AbstractElement parented; - protected AttributeSet aSet; + + protected DisAbstractedElement aElement; + + protected AbstractElement parented; + + protected AttributeSet aSet; public AbstractDocument_AbstractElement_MASTest(final String name) { super(name); } + @Override protected void setUp() throws Exception { super.setUp(); aDocument = new DisAbstractedDocument(new GapContent()); aDocument.writeLock(); - aElement = aDocument.new DisAbstractedElement(null, mas); + aElement = aDocument.new DisAbstractedElement(null, mas); mas = aElement; - as = aElement; + as = aElement; } + @Override protected void tearDown() throws Exception { super.tearDown(); aDocument.writeUnlock(); } - } Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_TreeNodeTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_TreeNodeTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_TreeNodeTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AbstractElement_TreeNodeTest.java Sun Nov 26 12:15:43 2006 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * @author Alexey A. Ivanov * @version $Revision$ @@ -23,7 +22,6 @@ import javax.swing.text.AbstractDocument.AbstractElement; import javax.swing.tree.TreeNode; - import junit.framework.TestCase; /** @@ -36,18 +34,22 @@ */ public class AbstractDocument_AbstractElement_TreeNodeTest extends TestCase { protected AbstractDocument doc; - protected AbstractElement aElement; - protected AbstractElement parented; - protected AbstractElement parent; + protected AbstractElement aElement; + + protected AbstractElement parented; + + protected AbstractElement parent; + + @Override protected void setUp() throws Exception { // Initialize static variables of enclosing class AbstractDocument_AbstractElementTest.init(); // Copy their values to instance variables - doc = AbstractDocument_AbstractElementTest.aDocument; + doc = AbstractDocument_AbstractElementTest.aDocument; aElement = AbstractDocument_AbstractElementTest.aElement; parented = AbstractDocument_AbstractElementTest.parented; - parent = aElement; + parent = aElement; } public void testGetChildCount() { @@ -56,10 +58,10 @@ } public void testGetChildAt() { - assertSame(aElement.getElement(0), aElement.getChildAt(0)); - assertSame(aElement.getElement(1), aElement.getChildAt(1)); - assertSame(aElement.getElement(2), aElement.getChildAt(2)); - assertSame(aElement.getElement(5), aElement.getChildAt(5)); + assertSame(aElement.getElement(0), aElement.getChildAt(0)); + assertSame(aElement.getElement(1), aElement.getChildAt(1)); + assertSame(aElement.getElement(2), aElement.getChildAt(2)); + assertSame(aElement.getElement(5), aElement.getChildAt(5)); assertSame(aElement.getElement(10), aElement.getChildAt(10)); } @@ -74,16 +76,13 @@ // the second one will come into play. Any way we get what we // want. assertTrue(node == null || (0 == aElement.getIndex(node))); - assertTrue((node = aElement.getChildAt(1)) == null || - (1 == aElement.getIndex(node))); + assertTrue((node = aElement.getChildAt(1)) == null || (1 == aElement.getIndex(node))); } public void testGetParent() { assertNull(aElement.getParent()); assertNotNull(parented.getParent()); assertSame(parent, parented.getParent()); - assertSame(parented.getParentElement(), parented.getParent()); } - } Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AttributeContextTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AttributeContextTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AttributeContextTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_AttributeContextTest.java Sun Nov 26 12:15:43 2006 @@ -23,12 +23,12 @@ import junit.framework.TestCase; public class AbstractDocument_AttributeContextTest extends TestCase { - private AbstractDocument.AttributeContext context; /* * @see TestCase#setUp() */ + @Override protected void setUp() throws Exception { super.setUp(); context = StyleContext.getDefaultStyleContext(); @@ -37,11 +37,9 @@ public void testGetEmptySet() { AttributeSet as = context.getEmptySet(); assertFalse(as.containsAttribute("key", "value")); - MutableAttributeSet sas = new SimpleAttributeSet(); sas.addAttribute("key", "value"); assertFalse(as.containsAttributes(sas)); - assertEquals(as, SimpleAttributeSet.EMPTY); assertNull(as.getAttribute("key")); assertFalse(as.isDefined("key")); @@ -72,10 +70,7 @@ */ public void testRemoveAttributesAttributeSetEnumeration() { AttributeSet as = getFilledAttributeSet(); - - AttributeSet result = context.removeAttributes(as, - as.getAttributeNames()); - + AttributeSet result = context.removeAttributes(as, as.getAttributeNames()); assertEquals(context.getEmptySet(), result); } Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElementTest.java Sun Nov 26 12:15:43 2006 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * @author Alexey A. Ivanov * @version $Revision$ @@ -22,7 +21,6 @@ package javax.swing.text; import java.util.Enumeration; - import javax.swing.BasicSwingTestCase; import javax.swing.text.AbstractDocument.BranchElement; import javax.swing.text.AbstractDocument.LeafElement; @@ -33,36 +31,36 @@ */ public class AbstractDocument_BranchElementTest extends BasicSwingTestCase { protected AbstractDocument doc; - protected BranchElement bidi; - protected BranchElement par; - protected Element leaf1; - protected Element leaf2; - protected Element leaf3; - protected AttributeSet[] as; + protected BranchElement bidi; + + protected BranchElement par; + + protected Element leaf1; + + protected Element leaf2; + + protected Element leaf3; + + protected AttributeSet[] as; protected static final String RTL = "\u05DC\u05DD"; - protected static final String LTR = "\u0061\u0062"; + protected static final String LTR = "\u0061\u0062"; + @Override protected void setUp() throws Exception { super.setUp(); - StyleContextTest.sc = StyleContext.getDefaultStyleContext(); - as = new AttributeSet[] { - StyleContextTest.addAttribute(1), - StyleContextTest.addAttribute(2), - StyleContextTest.addAttribute(null, 3, 2) - }; - + as = new AttributeSet[] { StyleContextTest.addAttribute(1), + StyleContextTest.addAttribute(2), StyleContextTest.addAttribute(null, 3, 2) }; doc = new PlainDocument(); doc.insertString(0, LTR + RTL + LTR + RTL + "\n01234", as[0]); - - bidi = (BranchElement)doc.getBidiRootElement(); - leaf1 = (LeafElement)bidi.getElement(0).getElement(0); - par = (BranchElement)doc.getDefaultRootElement(); - leaf2 = (LeafElement)par.getElement(0); - leaf3 = (LeafElement)par.getElement(1); + bidi = (BranchElement) doc.getBidiRootElement(); + leaf1 = bidi.getElement(0).getElement(0); + par = (BranchElement) doc.getDefaultRootElement(); + leaf2 = par.getElement(0); + leaf3 = par.getElement(1); } public void testGetElement() { @@ -74,13 +72,9 @@ assertNull(par.getElement(2)); } - public void testChildren() { - Enumeration elements = par.children(); - Element[] children = new Element[] { - par.getElement(0), - par.getElement(1) - }; + Enumeration elements = par.children(); + Element[] children = new Element[] { par.getElement(0), par.getElement(1) }; int index = 0; while (elements.hasMoreElements()) { Object child = elements.nextElement(); @@ -113,14 +107,13 @@ */ public void testGetElementIndex02() { BranchElement root = doc.new BranchElement(null, null); - LeafElement[] leaves = { - doc.new LeafElement(root, null, 0, 0), // [0] - doc.new LeafElement(root, null, 0, 1), // [1] - doc.new LeafElement(root, null, 0, 1), // [2] - doc.new LeafElement(root, null, 1, 1), // [3] - doc.new LeafElement(root, null, 1, 1), // [4] - doc.new LeafElement(root, null, 1, 2), // [5] - doc.new LeafElement(root, null, 2, 3) // [6] + LeafElement[] leaves = { doc.new LeafElement(root, null, 0, 0), // [0] + doc.new LeafElement(root, null, 0, 1), // [1] + doc.new LeafElement(root, null, 0, 1), // [2] + doc.new LeafElement(root, null, 1, 1), // [3] + doc.new LeafElement(root, null, 1, 1), // [4] + doc.new LeafElement(root, null, 1, 2), // [5] + doc.new LeafElement(root, null, 2, 3) // [6] }; root.replace(0, 0, leaves); assertEquals(0, root.getElementIndex(-1)); @@ -139,19 +132,18 @@ BranchElement root = doc.new BranchElement(null, null); try { assertEquals(-1, root.getElementIndex(-1)); - if (!BasicSwingTestCase.isHarmony()) { fail("NullPointerException should be thrown"); } - } catch (NullPointerException e) { } - + } catch (NullPointerException e) { + } try { assertEquals(-1, root.getElementIndex(0)); - if (!BasicSwingTestCase.isHarmony()) { fail("NullPointerException should be thrown"); } - } catch (NullPointerException e) { } + } catch (NullPointerException e) { + } } /** @@ -159,24 +151,18 @@ * The document has default length. */ public void testGetElementIndex04() throws BadLocationException { - final Element[] leaves = new Element[] { - createLeaf(1, 2), - createLeaf(3, 5), - createLeaf(5, 8), - createLeaf(15, 20) - }; + final Element[] leaves = new Element[] { createLeaf(1, 2), createLeaf(3, 5), + createLeaf(5, 8), createLeaf(15, 20) }; assertEquals(14, doc.getLength()); par.replace(0, par.getElementCount(), leaves); - - final int[] indexes = new int[] { - 0, 0, 0, 0, 1, // [ 0] - [ 4] - 1, 1, 2, 2, 2, // [ 5] - [ 9] - 3, 3, 3, 3, 3, // [10] - [14] - 3, 3, 3, 3, 3, // [15] - [19] - 3, 3, 3, 3, 3}; // [20] - [24] + final int[] indexes = new int[] { 0, 0, 0, 0, 1, // [ 0] - [ 4] + 1, 1, 2, 2, 2, // [ 5] - [ 9] + 3, 3, 3, 3, 3, // [10] - [14] + 3, 3, 3, 3, 3, // [15] - [19] + 3, 3, 3, 3, 3 }; // [20] - [24] for (int offset = -2, i = 0; offset < 23; offset++, i++) { - assertEquals("offset = " + offset + ", i = " + i, - indexes[i], par.getElementIndex(offset)); + assertEquals("offset = " + offset + ", i = " + i, indexes[i], par + .getElementIndex(offset)); } } @@ -187,23 +173,17 @@ public void testGetElementIndex05() throws BadLocationException { doc.getContent().remove(0, doc.getLength()); assertEquals(0, doc.getLength()); - final Element[] leaves = new Element[] { - createLeaf(1, 2), - createLeaf(3, 5), - createLeaf(5, 8), - createLeaf(15, 20) - }; + final Element[] leaves = new Element[] { createLeaf(1, 2), createLeaf(3, 5), + createLeaf(5, 8), createLeaf(15, 20) }; par.replace(0, par.getElementCount(), leaves); - - final int[] indexes = new int[] { - 0, 0, 0, 0, 1, // [ 0] - [ 4] - 1, 1, 2, 2, 2, // [ 5] - [ 9] - 3, 3, 3, 3, 3, // [10] - [14] - 3, 3, 3, 3, 3, // [15] - [19] - 3, 3, 3, 3, 3}; // [20] - [24] + final int[] indexes = new int[] { 0, 0, 0, 0, 1, // [ 0] - [ 4] + 1, 1, 2, 2, 2, // [ 5] - [ 9] + 3, 3, 3, 3, 3, // [10] - [14] + 3, 3, 3, 3, 3, // [15] - [19] + 3, 3, 3, 3, 3 }; // [20] - [24] for (int offset = -2, i = 0; offset < 23; offset++, i++) { - assertEquals("offset = " + offset + ", i = " + i, - indexes[i], par.getElementIndex(offset)); + assertEquals("offset = " + offset + ", i = " + i, indexes[i], par + .getElementIndex(offset)); } } @@ -241,7 +221,7 @@ assertSame(par, bidi.getParentElement()); assertEquals(0, bidi.getElementCount()); assertNull(bidi.getElement(0)); - Enumeration elements = bidi.children(); + Enumeration elements = bidi.children(); assertNull(elements); } @@ -253,13 +233,11 @@ bidi.replace(0, bidi.getElementCount(), new Element[] {}); assertEquals(0, bidi.getElementCount()); assertNull(bidi.children()); - - bidi.replace(0, 0, new Element[] {leaf1, leaf2, leaf3}); + bidi.replace(0, 0, new Element[] { leaf1, leaf2, leaf3 }); assertEquals(3, bidi.getElementCount()); - bidi = doc.new BranchElement(null, null); assertEquals(0, bidi.getElementCount()); - bidi.replace(0, 0, new Element[] {leaf2}); + bidi.replace(0, 0, new Element[] { leaf2 }); } /** @@ -267,18 +245,12 @@ */ public void testReplace02() { assertEquals(5, bidi.getElementCount()); - Element[] copy = new Element[] { - bidi.getElement(0), - bidi.getElement(1), - bidi.getElement(2), - bidi.getElement(3), - bidi.getElement(4), - }; - bidi.replace(1, 3, new Element[] {leaf2}); - + Element[] copy = new Element[] { bidi.getElement(0), bidi.getElement(1), + bidi.getElement(2), bidi.getElement(3), bidi.getElement(4), }; + bidi.replace(1, 3, new Element[] { leaf2 }); assertEquals(3, bidi.getElementCount()); assertSame(copy[0], bidi.getElement(0)); - assertSame(leaf2, bidi.getElement(1)); + assertSame(leaf2, bidi.getElement(1)); assertSame(copy[4], bidi.getElement(2)); } @@ -289,14 +261,13 @@ assertEquals(5, bidi.getElementCount()); try { bidi.replace(0, 2, null); - fail("NPE exception expected"); - } catch (NullPointerException e) { } - + } catch (NullPointerException e) { + } /* - // When NPE isn't thrown, the following assertion must be true - assertEquals(3, bidi.getElementCount()); - */ + // When NPE isn't thrown, the following assertion must be true + assertEquals(3, bidi.getElementCount()); + */ } public void testPositionToElement() { @@ -317,5 +288,4 @@ private Element createLeaf(final int start, final int end) { return doc.new LeafElement(par, null, start, end); } - } Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElement_TreeNodeTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElement_TreeNodeTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElement_TreeNodeTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_BranchElement_TreeNodeTest.java Sun Nov 26 12:15:43 2006 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * @author Alexey A. Ivanov * @version $Revision$ @@ -28,18 +27,17 @@ * implementing TreeNode interface. * */ -public class AbstractDocument_BranchElement_TreeNodeTest - extends AbstractDocument_AbstractElement_TreeNodeTest { - +public class AbstractDocument_BranchElement_TreeNodeTest extends + AbstractDocument_AbstractElement_TreeNodeTest { + @Override protected void setUp() throws Exception { doc = new PlainDocument(); doc.insertString(0, AbstractDocument_BranchElementTest.LTR - + AbstractDocument_BranchElementTest.RTL - + AbstractDocument_BranchElementTest.LTR - + AbstractDocument_BranchElementTest.RTL - + "\n01234", null); + + AbstractDocument_BranchElementTest.RTL + + AbstractDocument_BranchElementTest.LTR + + AbstractDocument_BranchElementTest.RTL + "\n01234", null); doc.writeLock(); - aElement = (AbstractElement)doc.getDefaultRootElement(); + aElement = (AbstractElement) doc.getDefaultRootElement(); parented = doc.new BranchElement(parent = aElement, null); doc.writeUnlock(); } Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_ContentTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_ContentTest.java?view=diff&rev=479418&r1=479417&r2=479418 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_ContentTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/AbstractDocument_ContentTest.java Sun Nov 26 12:15:43 2006 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - /** * @author Alexey A. Ivanov * @version $Revision$ @@ -37,6 +36,7 @@ * 0123456789012345678901 */ Content obj; + /** * Shared segment of text which is used in testGetCharsXXX methods. */ @@ -50,12 +50,14 @@ super(name); } + @Override protected void setUp() throws Exception { super.setUp(); obj = new GapContent(); obj.insertString(0, "This is a test string."); text = new Segment(); } + /** * Tests that Position IS NOT changed, after an insertion has occured * after this Position. @@ -99,11 +101,11 @@ public void testCreatePositionInvalid() { try { obj.createPosition(-1); - if (BasicSwingTestCase.isHarmony()) { fail("BadLocationException should be thrown"); } - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testCreatePositionFarAway() throws BadLocationException { @@ -115,7 +117,6 @@ public void testGetCharsAfterGap() throws BadLocationException { // Move the gap obj.insertString(10, "big "); - obj.getChars(19, 8, text); assertEquals("string.\n", text.toString()); } @@ -129,31 +130,30 @@ public void testGetCharsInvalidPosition() { try { obj.getChars(30, 4, text); - fail("BadLocationException should be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testGetCharsInvalidLength() { try { obj.getChars(15, 15, text); - fail("BadLocationException should be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testGetCharsNegativeLength() { try { obj.getChars(0, -2, new Segment()); - fail("BadLocationException must be thrown: negative length"); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testGetCharsPartial() throws BadLocationException { // Move the gap obj.insertString(10, "big "); - text.setPartialReturn(true); obj.getChars(8, 10, text); assertEquals("a big ", text.toString()); @@ -162,7 +162,6 @@ public void testGetCharsWithGap() throws BadLocationException { // Move the gap obj.insertString(10, "big "); - obj.getChars(8, 10, text); assertEquals("a big test", text.toString()); } @@ -192,25 +191,25 @@ public void testGetStringInvalidLength() { try { obj.getString(15, 15); - fail("BadLocationException should be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testGetStringNegativeLength() { try { obj.getString(0, -2); - fail("BadLocationException must be thrown: negative length"); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testGetStringInvalidPosition() { try { obj.getString(30, 5); - fail("BadLocationException should be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testGetStringWithGap() throws BadLocationException { @@ -237,9 +236,9 @@ public void testInsertStringInvalid() { try { obj.insertString(30, "text"); - fail("BadLocationException should be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testLength() { @@ -280,25 +279,24 @@ public void testRemoveImplicit() { try { obj.remove(22, 1); - fail("BadLocationException should be thrown"); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testRemoveInvalidLength() { try { obj.remove(15, 15); - fail("BadLocationException should be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } public void testRemoveInvalidPosition() { try { obj.remove(30, 15); - fail("BadLocationException should be thrown."); - } catch (BadLocationException e) { } + } catch (BadLocationException e) { + } } - }