harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r479418 [24/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 GMT
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_CreateElementTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_CreateElementTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_CreateElementTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_CreateElementTest.java Sun Nov 26 12:15:43 2006
@@ -22,7 +22,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-
 import junit.framework.TestCase;
 
 /**
@@ -37,13 +36,16 @@
 public class DefaultStyledDocument_CreateElementTest extends TestCase {
     private static class LeafChild {
         public final Element parent;
+
         public final AttributeSet attrs;
+
         public final int start;
+
         public final int end;
+
         public final Element child;
 
-        public LeafChild(Element parent, AttributeSet attrs,
-                         int start, int end, Element child) {
+        public LeafChild(Element parent, AttributeSet attrs, int start, int end, Element child) {
             this.parent = parent;
             this.attrs = attrs;
             this.end = end;
@@ -51,8 +53,8 @@
             this.child = child;
         }
 
-        public void assertExpected(Element parent, AttributeSet attrs,
-                                   int start, int end, Element child) {
+        public void assertExpected(Element parent, AttributeSet attrs, int start, int end,
+                Element child) {
             assertSame(parent, this.parent);
             assertEquals(attrs, new SimpleAttributeSet(this.attrs));
             assertEquals(start, this.start);
@@ -63,17 +65,18 @@
 
     private static class BranchChild {
         public final Element parent;
+
         public final AttributeSet attrs;
+
         public final Element child;
-        public BranchChild(Element parent, AttributeSet attrs,
-                           Element child) {
+
+        public BranchChild(Element parent, AttributeSet attrs, Element child) {
             this.parent = parent;
             this.attrs = attrs;
             this.child = child;
         }
 
-        public void assertExpected(Element parent, AttributeSet attrs,
-                                   Element child) {
+        public void assertExpected(Element parent, AttributeSet attrs, Element child) {
             assertSame(parent, this.parent);
             assertEquals(attrs, new SimpleAttributeSet(this.attrs));
             assertSame(child, this.child);
@@ -81,32 +84,35 @@
     }
 
     private DefaultStyledDocument doc;
+
     private Element root;
 
-    private List branches;
-    private List leaves;
+    private List<BranchChild> branches;
 
+    private List<LeafChild> leaves;
+
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
-        branches = new ArrayList();
-        leaves = new ArrayList();
+        branches = new ArrayList<BranchChild>();
+        leaves = new ArrayList<LeafChild>();
         doc = new DefaultStyledDocument() {
-            protected Element createBranchElement(Element parent,
-                                                  AttributeSet as) {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            protected Element createBranchElement(Element parent, AttributeSet as) {
                 Element child = super.createBranchElement(parent, as);
                 branches.add(new BranchChild(parent, as, child));
                 return child;
             }
 
-            protected Element createLeafElement(Element parent,
-                                                AttributeSet as,
-                                                int start,
-                                                int end) {
+            @Override
+            protected Element createLeafElement(Element parent, AttributeSet as, int start,
+                    int end) {
                 Element child = super.createLeafElement(parent, as, start, end);
                 leaves.add(new LeafChild(parent, as, start, end, child));
                 return child;
             }
-
         };
         root = doc.getDefaultRootElement();
         doc.insertString(0, "012abc\ntwo\nthree", null);
@@ -121,37 +127,26 @@
         MutableAttributeSet attrs = new SimpleAttributeSet();
         StyleConstants.setBold(attrs, true);
         doc.setCharacterAttributes(2, 2, attrs, false);
-
         assertEquals(0, branches.size());
         assertEquals(3, leaves.size());
         final Element parent = root.getElement(0);
-        ((LeafChild)leaves.get(0)).assertExpected(parent,
-                                                  SimpleAttributeSet.EMPTY,
-                                                  0, 2,
-                                                  parent.getElement(0));
-        assertEquals(SimpleAttributeSet.EMPTY,
-                     parent.getElement(0).getAttributes());
-        ((LeafChild)leaves.get(1)).assertExpected(parent,
-                                                  SimpleAttributeSet.EMPTY,
-                                                  2, 4,
-                                                  parent.getElement(1));
+        leaves.get(0).assertExpected(parent, SimpleAttributeSet.EMPTY, 0, 2,
+                parent.getElement(0));
+        assertEquals(SimpleAttributeSet.EMPTY, parent.getElement(0).getAttributes());
+        leaves.get(1).assertExpected(parent, SimpleAttributeSet.EMPTY, 2, 4,
+                parent.getElement(1));
         assertEquals(attrs, parent.getElement(1).getAttributes());
-        ((LeafChild)leaves.get(2)).assertExpected(parent,
-                                                  SimpleAttributeSet.EMPTY,
-                                                  4, 7,
-                                                  parent.getElement(2));
-        assertEquals(SimpleAttributeSet.EMPTY,
-                     parent.getElement(2).getAttributes());
+        leaves.get(2).assertExpected(parent, SimpleAttributeSet.EMPTY, 4, 7,
+                parent.getElement(2));
+        assertEquals(SimpleAttributeSet.EMPTY, parent.getElement(2).getAttributes());
     }
 
     /*
      * DefaultStyledDocument.setLogicalStyle()
      */
     public void testSetLogicalStyle() {
-        Style style = doc.addStyle("aStyle",
-                                   doc.getStyle(StyleContext.DEFAULT_STYLE));
+        Style style = doc.addStyle("aStyle", doc.getStyle(StyleContext.DEFAULT_STYLE));
         doc.setLogicalStyle(3, style);
-
         assertEquals(0, branches.size());
         assertEquals(0, leaves.size());
     }
@@ -163,7 +158,6 @@
         MutableAttributeSet attrs = new SimpleAttributeSet();
         StyleConstants.setBold(attrs, true);
         doc.setParagraphAttributes(3, 6, attrs, false);
-
         assertEquals(0, branches.size());
         assertEquals(0, leaves.size());
     }
@@ -173,21 +167,15 @@
      */
     public void testInsertString() throws BadLocationException {
         doc.insertString(7, "^^^\n", null);
-
         assertEquals(1, branches.size());
         assertEquals(2, leaves.size());
-
         MutableAttributeSet logStyle = new SimpleAttributeSet();
         logStyle.setResolveParent(doc.getStyle(StyleContext.DEFAULT_STYLE));
-        ((BranchChild)branches.get(0)).assertExpected(root, logStyle,
-                                                      root.getElement(1));
-
-        ((LeafChild)leaves.get(0)).assertExpected(
-                root.getElement(0), SimpleAttributeSet.EMPTY, 0, 7,
-                root.getElement(0).getElement(0));
-        ((LeafChild)leaves.get(1)).assertExpected(
-                root.getElement(1), SimpleAttributeSet.EMPTY, 7, 11,
-                root.getElement(1).getElement(0));
+        branches.get(0).assertExpected(root, logStyle, root.getElement(1));
+        leaves.get(0).assertExpected(root.getElement(0),
+                SimpleAttributeSet.EMPTY, 0, 7, root.getElement(0).getElement(0));
+        leaves.get(1).assertExpected(root.getElement(1),
+                SimpleAttributeSet.EMPTY, 7, 11, root.getElement(1).getElement(0));
     }
 
     /*
@@ -195,21 +183,14 @@
      */
     public void testRemove() throws BadLocationException {
         doc.remove(3, 4);
-
         assertEquals(1, branches.size());
         assertEquals(2, leaves.size());
-
         MutableAttributeSet logStyle = new SimpleAttributeSet();
         logStyle.setResolveParent(doc.getStyle(StyleContext.DEFAULT_STYLE));
-        ((BranchChild)branches.get(0)).assertExpected(root, logStyle,
-                                                      root.getElement(0));
-
-        ((LeafChild)leaves.get(0)).assertExpected(
-                root.getElement(0), SimpleAttributeSet.EMPTY, 0, 7,
-                root.getElement(0).getElement(0));
-        ((LeafChild)leaves.get(1)).assertExpected(
-                root.getElement(0), SimpleAttributeSet.EMPTY, 7, 11,
-                root.getElement(0).getElement(1));
+        branches.get(0).assertExpected(root, logStyle, root.getElement(0));
+        leaves.get(0).assertExpected(root.getElement(0),
+                SimpleAttributeSet.EMPTY, 0, 7, root.getElement(0).getElement(0));
+        leaves.get(1).assertExpected(root.getElement(0),
+                SimpleAttributeSet.EMPTY, 7, 11, root.getElement(0).getElement(1));
     }
-
 }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_CreateInsertTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_CreateInsertTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_CreateInsertTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_CreateInsertTest.java Sun Nov 26 12:15:43 2006
@@ -21,7 +21,6 @@
 package javax.swing.text;
 
 import java.util.List;
-
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import javax.swing.event.DocumentEvent.EventType;
@@ -30,7 +29,6 @@
 import javax.swing.text.DefaultStyledDocument.AttributeUndoableEdit;
 import javax.swing.text.DefaultStyledDocument.ElementBuffer;
 import javax.swing.text.DefaultStyledDocument.ElementSpec;
-
 import junit.framework.TestCase;
 
 /**
@@ -38,23 +36,31 @@
  * DefaultStyledDocument.
  *
  */
-public class DefaultStyledDocument_CreateInsertTest extends TestCase
-    implements DocumentListener {
-
+public class DefaultStyledDocument_CreateInsertTest extends TestCase implements
+        DocumentListener {
     private DefaultStyledDocument doc;
+
     private ElementBuffer buf;
+
     private Element root;
+
     private DocumentEvent event;
 
     private static final String plainText = "plain";
+
     private static final String boldText = "bold";
+
     private static final String italicText = "italic";
+
     private static final String newLine = "\n";
+
     private static final String paragraph2Text = "line\n";
 
     private static final AttributeSet bold = DefStyledDoc_Helpers.bold;
+
     private static final AttributeSet italic = DefStyledDoc_Helpers.italic;
 
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
         doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
@@ -70,77 +76,58 @@
      */
     public void testCreateWithoutText() throws BadLocationException {
         final ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-
-            new ElementSpec(null, ElementSpec.ContentType,
-                            plainText.toCharArray(), 0, plainText.length()),
-            new ElementSpec(bold, ElementSpec.ContentType,
-                            boldText.toCharArray(), 0, boldText.length()),
-            new ElementSpec(italic, ElementSpec.ContentType,
-                            italicText.toCharArray(), 0,
-                            italicText.length()),
-            new ElementSpec(null, ElementSpec.ContentType,
-                            newLine.toCharArray(), 0, newLine.length()),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType,
-                            paragraph2Text.toCharArray(), 0,
-                            paragraph2Text.length()),
-            new ElementSpec(null, ElementSpec.EndTagType),
-        };
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, plainText.toCharArray(), 0,
+                        plainText.length()),
+                new ElementSpec(bold, ElementSpec.ContentType, boldText.toCharArray(), 0,
+                        boldText.length()),
+                new ElementSpec(italic, ElementSpec.ContentType, italicText.toCharArray(), 0,
+                        italicText.length()),
+                new ElementSpec(null, ElementSpec.ContentType, newLine.toCharArray(), 0,
+                        newLine.length()),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, paragraph2Text.toCharArray(), 0,
+                        paragraph2Text.length()),
+                new ElementSpec(null, ElementSpec.EndTagType), };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
-
         // Add an attribute to the root
         doc.writeLock();
         try {
-            ((AbstractElement)root).addAttributes(bold);
+            ((AbstractElement) root).addAttributes(bold);
         } finally {
             doc.writeUnlock();
         }
-
         doc.addDocumentListener(this);
-
         assertNull(event);
         doc.create(specs);
         assertNotNull(event);
-
         assertEquals(0, event.getOffset());
-        assertEquals(plainText.length() + boldText.length()
-                     + italicText.length() + newLine.length()
-                     + paragraph2Text.length(),
-                     event.getLength());
+        assertEquals(plainText.length() + boldText.length() + italicText.length()
+                + newLine.length() + paragraph2Text.length(), event.getLength());
         assertSame(EventType.INSERT, event.getType());
-
-        assertChildren(root.getElement(0), plainText + boldText
-                                           + italicText + newLine,
-                       new int[] {0, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, null});
-        assertChildren(root.getElement(1), paragraph2Text,
-                       new int[] {16, 21},
-                       new AttributeSet[] {null});
+        assertChildren(root.getElement(0), plainText + boldText + italicText + newLine,
+                new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] { null, bold,
+                        italic, null });
+        assertChildren(root.getElement(1), paragraph2Text, new int[] { 16, 21 },
+                new AttributeSet[] { null });
         assertEquals(0, root.getElement(1).getAttributes().getAttributeCount());
-        assertChildren(root.getElement(2), newLine,
-                       new int[] {21, 22},
-                       new AttributeSet[] {null});
-
-        final List edits =
-            DefStyledDoc_Helpers.getEdits((DefaultDocumentEvent)event);
+        assertChildren(root.getElement(2), newLine, new int[] { 21, 22 },
+                new AttributeSet[] { null });
+        final List<?> edits = DefStyledDoc_Helpers.getEdits((DefaultDocumentEvent) event);
         assertEquals(6, edits.size());
-        final AttributeUndoableEdit undo = (AttributeUndoableEdit)edits.get(1);
+        final AttributeUndoableEdit undo = (AttributeUndoableEdit) edits.get(1);
         assertSame(root, undo.element);
         assertTrue(undo.copy.isEqual(bold));
         assertEquals(0, undo.newAttributes.getAttributeCount());
         assertTrue(undo.isReplacing);
-
-        assertChange(edits.get(2), root.getElement(root.getElementCount() - 1),
-                     0, new int[] {0, 22}, new int[] {21, 22});
-        assertChange(edits.get(3), root.getElement(0),
-                     0, new int[] {}, new int[] {0, 5, 5, 9, 9, 15, 15, 16});
-        assertChange(edits.get(4), root.getElement(1),
-                     0, new int[] {}, new int[] {16, 21});
-        assertChange(edits.get(5), root,
-                     0, new int[] {}, new int[] {0, 16, 16, 21});
+        assertChange(edits.get(2), root.getElement(root.getElementCount() - 1), 0, new int[] {
+                0, 22 }, new int[] { 21, 22 });
+        assertChange(edits.get(3), root.getElement(0), 0, new int[] {}, new int[] { 0, 5, 5, 9,
+                9, 15, 15, 16 });
+        assertChange(edits.get(4), root.getElement(1), 0, new int[] {}, new int[] { 16, 21 });
+        assertChange(edits.get(5), root, 0, new int[] {}, new int[] { 0, 16, 16, 21 });
     }
 
     /**
@@ -151,117 +138,86 @@
     public void testCreateWithText() throws BadLocationException {
         doc.insertString(0, "some text", bold);
         doc.insertString(doc.getLength(), "\nmore text", italic);
-
         final ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-
-            new ElementSpec(null, ElementSpec.ContentType,
-                            plainText.toCharArray(), 0, plainText.length()),
-            new ElementSpec(bold, ElementSpec.ContentType,
-                            boldText.toCharArray(), 0, boldText.length()),
-            new ElementSpec(italic, ElementSpec.ContentType,
-                            italicText.toCharArray(), 0,
-                            italicText.length()),
-            new ElementSpec(null, ElementSpec.ContentType,
-                            newLine.toCharArray(), 0, newLine.length()),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType,
-                            paragraph2Text.toCharArray(), 0,
-                            paragraph2Text.length()),
-            new ElementSpec(null, ElementSpec.EndTagType),
-        };
-
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, plainText.toCharArray(), 0,
+                        plainText.length()),
+                new ElementSpec(bold, ElementSpec.ContentType, boldText.toCharArray(), 0,
+                        boldText.length()),
+                new ElementSpec(italic, ElementSpec.ContentType, italicText.toCharArray(), 0,
+                        italicText.length()),
+                new ElementSpec(null, ElementSpec.ContentType, newLine.toCharArray(), 0,
+                        newLine.length()),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, paragraph2Text.toCharArray(), 0,
+                        paragraph2Text.length()),
+                new ElementSpec(null, ElementSpec.EndTagType), };
         doc.addDocumentListener(this);
-
         assertNull(event);
         doc.create(specs);
         assertNotNull(event);
-
         assertEquals(0, event.getOffset());
-        assertEquals(plainText.length() + boldText.length()
-                     + italicText.length() + newLine.length()
-                     + paragraph2Text.length(),
-                     event.getLength());
+        assertEquals(plainText.length() + boldText.length() + italicText.length()
+                + newLine.length() + paragraph2Text.length(), event.getLength());
         assertSame(EventType.INSERT, event.getType());
-
-        assertChildren(root.getElement(0), plainText + boldText
-                                           + italicText + newLine,
-                       new int[] {0, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, null});
-        assertChildren(root.getElement(1), paragraph2Text,
-                       new int[] {16, 21},
-                       new AttributeSet[] {null});
+        assertChildren(root.getElement(0), plainText + boldText + italicText + newLine,
+                new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] { null, bold,
+                        italic, null });
+        assertChildren(root.getElement(1), paragraph2Text, new int[] { 16, 21 },
+                new AttributeSet[] { null });
         assertEquals(0, root.getElement(1).getAttributes().getAttributeCount());
-        assertChildren(root.getElement(2), newLine,
-                       new int[] {21, 22},
-                       new AttributeSet[] {null});
-
-        final List edits =
-            DefStyledDoc_Helpers.getEdits((DefaultDocumentEvent)event);
+        assertChildren(root.getElement(2), newLine, new int[] { 21, 22 },
+                new AttributeSet[] { null });
+        final List<?> edits = DefStyledDoc_Helpers.getEdits((DefaultDocumentEvent) event);
         assertEquals(6, edits.size());
-
-        assertChange(edits.get(2), root.getElement(root.getElementCount() - 1),
-                     0, new int[] {0, 22}, new int[] {21, 22});
-        assertChange(edits.get(3), root.getElement(0),
-                     0, new int[] {}, new int[] {0, 5, 5, 9, 9, 15, 15, 16});
-        assertChange(edits.get(4), root.getElement(1),
-                     0, new int[] {}, new int[] {16, 21});
-        assertChange(edits.get(5), root,
-                     0, new int[] {}, new int[] {0, 16, 16, 21});
+        assertChange(edits.get(2), root.getElement(root.getElementCount() - 1), 0, new int[] {
+                0, 22 }, new int[] { 21, 22 });
+        assertChange(edits.get(3), root.getElement(0), 0, new int[] {}, new int[] { 0, 5, 5, 9,
+                9, 15, 15, 16 });
+        assertChange(edits.get(4), root.getElement(1), 0, new int[] {}, new int[] { 16, 21 });
+        assertChange(edits.get(5), root, 0, new int[] {}, new int[] { 0, 16, 16, 21 });
     }
 
     public void testInsertWithStartTag() throws BadLocationException {
-      doc.insertString(0, "some  text", bold);
-      doc.insertString(doc.getLength(), "\nmore text", italic);
-
-      ElementSpec[] specs = {
-          new ElementSpec(null, ElementSpec.ContentType,
-                          plainText.toCharArray(), 0, plainText.length()),
-          new ElementSpec(bold, ElementSpec.ContentType,
-                          boldText.toCharArray(), 0, boldText.length()),
-          new ElementSpec(italic, ElementSpec.ContentType,
-                          italicText.toCharArray(), 0,
-                          italicText.length()),
-          new ElementSpec(null, ElementSpec.ContentType,
-                          newLine.toCharArray(), 0, newLine.length()),
-          new ElementSpec(null, ElementSpec.EndTagType),
-          new ElementSpec(null, ElementSpec.StartTagType),
-          new ElementSpec(null, ElementSpec.ContentType,
-                          paragraph2Text.toCharArray(), 0,
-                          paragraph2Text.length()),
-          //It is mandatory for our implementation.
-          new ElementSpec(null, ElementSpec.EndTagType),
-          new ElementSpec(null, ElementSpec.StartTagType)
-      };
-      specs[specs.length - 1].setDirection(ElementSpec.JoinFractureDirection);
-
-      doc.addDocumentListener(this);
-      assertNull(event);
-      doc.insert(5, specs);
-      assertNotNull(event);
-
-      assertEquals(5, event.getOffset());
-      assertEquals(plainText.length() + boldText.length() + italicText.length()
-                   + newLine.length() + paragraph2Text.length(),
-                   event.getLength());
-      assertSame(EventType.INSERT, event.getType());
-
-      assertChildren(root.getElement(0), "some " + plainText + boldText
-                                         + italicText + newLine,
-                     new int[] {0, 5, 5, 10, 10, 14, 14, 20, 20, 21},
-                     new AttributeSet[] {bold, null, bold, italic, null});
-      assertChildren(root.getElement(1), paragraph2Text,
-                     new int[] {21, 26},
-                     new AttributeSet[] {null});
-      assertEquals(0, root.getElement(1).getAttributes().getAttributeCount());
-      assertChildren(root.getElement(2), " text\n",
-                     new int[] {26, 31, 31, 32},
-                     new AttributeSet[] {bold, italic});
-      assertChildren(root.getElement(3), "more text\n",
-                     new int[] {32, 41, 41, 42},
-                     new AttributeSet[] {italic, null});
+        doc.insertString(0, "some  text", bold);
+        doc.insertString(doc.getLength(), "\nmore text", italic);
+        ElementSpec[] specs = {
+                new ElementSpec(null, ElementSpec.ContentType, plainText.toCharArray(), 0,
+                        plainText.length()),
+                new ElementSpec(bold, ElementSpec.ContentType, boldText.toCharArray(), 0,
+                        boldText.length()),
+                new ElementSpec(italic, ElementSpec.ContentType, italicText.toCharArray(), 0,
+                        italicText.length()),
+                new ElementSpec(null, ElementSpec.ContentType, newLine.toCharArray(), 0,
+                        newLine.length()),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, paragraph2Text.toCharArray(), 0,
+                        paragraph2Text.length()),
+                //It is mandatory for our implementation.
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
+        specs[specs.length - 1].setDirection(ElementSpec.JoinFractureDirection);
+        doc.addDocumentListener(this);
+        assertNull(event);
+        doc.insert(5, specs);
+        assertNotNull(event);
+        assertEquals(5, event.getOffset());
+        assertEquals(plainText.length() + boldText.length() + italicText.length()
+                + newLine.length() + paragraph2Text.length(), event.getLength());
+        assertSame(EventType.INSERT, event.getType());
+        assertChildren(root.getElement(0), "some " + plainText + boldText + italicText
+                + newLine, new int[] { 0, 5, 5, 10, 10, 14, 14, 20, 20, 21 },
+                new AttributeSet[] { bold, null, bold, italic, null });
+        assertChildren(root.getElement(1), paragraph2Text, new int[] { 21, 26 },
+                new AttributeSet[] { null });
+        assertEquals(0, root.getElement(1).getAttributes().getAttributeCount());
+        assertChildren(root.getElement(2), " text\n", new int[] { 26, 31, 31, 32 },
+                new AttributeSet[] { bold, italic });
+        assertChildren(root.getElement(3), "more text\n", new int[] { 32, 41, 41, 42 },
+                new AttributeSet[] { italic, null });
     }
 
     /**
@@ -270,71 +226,47 @@
      * <code>StartTagType</code> specs.
      */
     public void testInsertNoStartTags() throws BadLocationException {
-      doc.insertString(0, "some  text", bold);
-      doc.insertString(doc.getLength(), "\nmore text", italic);
-
-      ElementSpec[] specs = {
-          new ElementSpec(null, ElementSpec.ContentType,
-                          plainText.toCharArray(), 0, plainText.length()),
-          new ElementSpec(bold, ElementSpec.ContentType,
-                          boldText.toCharArray(), 0, boldText.length()),
-          new ElementSpec(italic, ElementSpec.ContentType,
-                          italicText.toCharArray(), 0,
-                          italicText.length()),
-          new ElementSpec(null, ElementSpec.ContentType,
-                          newLine.toCharArray(), 0, newLine.length()),
-          new ElementSpec(null, ElementSpec.ContentType,
-                          paragraph2Text.toCharArray(), 0,
-                          paragraph2Text.length()),
-      };
-
-      doc.addDocumentListener(this);
-      assertNull(event);
-      doc.insert(5, specs);
-      assertNotNull(event);
-
-      assertEquals(5, event.getOffset());
-      assertEquals(plainText.length() + boldText.length() + italicText.length()
-                   + newLine.length() + paragraph2Text.length(),
-                   event.getLength());
-      assertSame(EventType.INSERT, event.getType());
-
-      assertChildren(root.getElement(0), "some " + plainText + boldText
-                                         + italicText + newLine
-                                         + paragraph2Text + " text\n",
-                     new int[] {0, 5, 5, 10, 10, 14, 14, 20, 20, 21,
-                                21, 26, 26, 31, 31, 32},
-                     new AttributeSet[] {bold, null, bold, italic, null,
-                                         null, bold, italic});
-      assertChildren(root.getElement(1), "more text\n",
-                     new int[] {32, 41, 41, 42},
-                     new AttributeSet[] {italic, null});
+        doc.insertString(0, "some  text", bold);
+        doc.insertString(doc.getLength(), "\nmore text", italic);
+        ElementSpec[] specs = {
+                new ElementSpec(null, ElementSpec.ContentType, plainText.toCharArray(), 0,
+                        plainText.length()),
+                new ElementSpec(bold, ElementSpec.ContentType, boldText.toCharArray(), 0,
+                        boldText.length()),
+                new ElementSpec(italic, ElementSpec.ContentType, italicText.toCharArray(), 0,
+                        italicText.length()),
+                new ElementSpec(null, ElementSpec.ContentType, newLine.toCharArray(), 0,
+                        newLine.length()),
+                new ElementSpec(null, ElementSpec.ContentType, paragraph2Text.toCharArray(), 0,
+                        paragraph2Text.length()), };
+        doc.addDocumentListener(this);
+        assertNull(event);
+        doc.insert(5, specs);
+        assertNotNull(event);
+        assertEquals(5, event.getOffset());
+        assertEquals(plainText.length() + boldText.length() + italicText.length()
+                + newLine.length() + paragraph2Text.length(), event.getLength());
+        assertSame(EventType.INSERT, event.getType());
+        assertChildren(root.getElement(0), "some " + plainText + boldText + italicText
+                + newLine + paragraph2Text + " text\n", new int[] { 0, 5, 5, 10, 10, 14, 14,
+                20, 20, 21, 21, 26, 26, 31, 31, 32 }, new AttributeSet[] { bold, null, bold,
+                italic, null, null, bold, italic });
+        assertChildren(root.getElement(1), "more text\n", new int[] { 32, 41, 41, 42 },
+                new AttributeSet[] { italic, null });
     }
 
+    private static void assertChange(final Object change, final Element element,
+            final int index, final int[] removedOffsets, final int[] addedOffsets) {
+        DefStyledDoc_Helpers.assertChange(change, element, index, removedOffsets, addedOffsets);
+    }
 
-    private static void assertChange(final Object change,
-                                     final Element element,
-                                     final int index,
-                                     final int[] removedOffsets,
-                                     final int[] addedOffsets) {
-        DefStyledDoc_Helpers.assertChange(change, element, index,
-                                          removedOffsets, addedOffsets);
-    }
-
-    private static void assertChildren(final Element element,
-                                       final String text,
-                                       final int[] offsets,
-                                       final AttributeSet[] attributes)
-        throws BadLocationException {
-
+    private static void assertChildren(final Element element, final String text,
+            final int[] offsets, final AttributeSet[] attributes) throws BadLocationException {
         DefStyledDoc_Helpers.assertChildren(element, offsets, attributes);
-        assertEquals("element.text " + element,
-                     text, getText(element));
+        assertEquals("element.text " + element, text, getText(element));
     }
 
-    private static String getText(final Element element)
-        throws BadLocationException {
-
+    private static String getText(final Element element) throws BadLocationException {
         final int start = element.getStartOffset();
         final int end = element.getEndOffset();
         return element.getDocument().getText(start, end - start);
@@ -350,5 +282,4 @@
     public void changedUpdate(DocumentEvent e) {
         fail("changedUpdate is not expected to be called");
     }
-
 }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBufferTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBufferTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBufferTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBufferTest.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 javax.swing.text.DefaultStyledDocument.ElementBuffer;
-
 import junit.framework.TestCase;
 
 /**
@@ -33,8 +31,10 @@
  */
 public class DefaultStyledDocument_ElementBufferTest extends TestCase {
     private DefaultStyledDocument doc;
+
     private ElementBuffer buf;
 
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
         doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
@@ -69,13 +69,11 @@
             Element par1 = root.getElement(0);
             Element par2 = root.getElement(1);
             Element line = par1.getElement(0);
-
             Element cloned = buf.clone(par2, line);
             assertNotSame(line, cloned);
             assertEquals(line.getStartOffset(), cloned.getStartOffset());
             assertEquals(line.getEndOffset(), cloned.getEndOffset());
             assertEquals(bold, cloned.getAttributes());
-
             assertSame(par1, line.getParentElement());
             assertSame(par2, cloned.getParentElement());
         } finally {
@@ -98,7 +96,6 @@
             attrs = new SimpleAttributeSet();
             StyleConstants.setAlignment(attrs, 0);
             doc.insertString(doc.getLength(), "two\nthree", attrs);
-
             attrs = new SimpleAttributeSet();
             StyleConstants.setFontSize(attrs, 25);
             doc.setParagraphAttributes(0, 1, attrs, false);
@@ -106,7 +103,6 @@
             final Element root = doc.getDefaultRootElement();
             final Element par1 = root.getElement(0);
             final Element par2 = root.getElement(1);
-
             final Element cloned = buf.clone(par2, par1);
             assertNotSame(par1, cloned);
             assertEquals(par1.getStartOffset(), cloned.getStartOffset());
@@ -114,7 +110,6 @@
             final AttributeSet clonedAttrs = cloned.getAttributes();
             assertTrue(clonedAttrs.containsAttributes(fontSize));
             assertTrue(clonedAttrs.isDefined(AttributeSet.ResolveAttribute));
-
             assertSame(root, par1.getParentElement());
             assertSame(par2, cloned.getParentElement());
             assertSame(root, par2.getParentElement());
@@ -127,7 +122,6 @@
         Element docRoot = doc.getDefaultRootElement();
         Element bufRoot = buf.getRootElement();
         assertSame(docRoot, bufRoot);
-
         bufRoot = doc.new BranchElement(null, null);
         buf = doc.new ElementBuffer(bufRoot);
         doc.buffer = buf;

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_ChangeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_ChangeTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_ChangeTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_ChangeTest.java Sun Nov 26 12:15:43 2006
@@ -21,14 +21,12 @@
 package javax.swing.text;
 
 import java.util.List;
-
 import javax.swing.event.DocumentEvent.ElementChange;
 import javax.swing.event.DocumentEvent.EventType;
 import javax.swing.text.AbstractDocument.BranchElement;
 import javax.swing.text.AbstractDocument.Content;
 import javax.swing.text.AbstractDocument.DefaultDocumentEvent;
 import javax.swing.text.DefaultStyledDocument.ElementBuffer;
-
 import junit.framework.TestCase;
 
 /**
@@ -38,15 +36,22 @@
  */
 public class DefaultStyledDocument_ElementBuffer_ChangeTest extends TestCase {
     private DefaultStyledDocument doc;
+
     private Element root;
+
     private ElementBuffer buf;
+
     private DefaultDocumentEvent event;
+
     private Content content;
+
     private Element paragraph;
 
     private static final AttributeSet bold = DefStyledDoc_Helpers.bold;
+
     private static final AttributeSet italic = DefStyledDoc_Helpers.italic;
 
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
         doc = new DefaultStyledDocument();
@@ -54,7 +59,6 @@
         buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root);
         doc.buffer = buf;
         paragraph = root.getElement(0);
-
         content = doc.getContent();
         content.insertString(0, "plainbolditalic\ntext");
         // Create the structure equivalent to this sequence:
@@ -62,24 +66,21 @@
         //doc.insertString(doc.getLength(), "bold", bold);     // 4 chars
         //doc.insertString(doc.getLength(), "italic", italic); // 6 chars
         //doc.insertString(doc.getLength(), "\ntext", null);   // 5 chars
-
         doc.writeLock(); // Write lock needed to modify document structure
-
         Element[] leaves = new Element[4];
         leaves[0] = doc.createLeafElement(paragraph, null, 0, 5);
         leaves[1] = doc.createLeafElement(paragraph, bold, 5, 9);
         leaves[2] = doc.createLeafElement(paragraph, italic, 9, 15);
         leaves[3] = doc.createLeafElement(paragraph, null, 15, 16);
-        ((BranchElement)paragraph).replace(0, 1, leaves);
-
-        BranchElement branch = (BranchElement)doc.createBranchElement(root,
-                                                                      null);
+        ((BranchElement) paragraph).replace(0, 1, leaves);
+        BranchElement branch = (BranchElement) doc.createBranchElement(root, null);
         leaves = new Element[1];
         leaves[0] = doc.createLeafElement(branch, null, 16, 21);
         branch.replace(0, 0, leaves);
-        ((BranchElement)root).replace(1, 0, new Element[] {branch});
+        ((BranchElement) root).replace(1, 0, new Element[] { branch });
     }
 
+    @Override
     protected void tearDown() throws Exception {
         super.tearDown();
         doc.writeUnlock();
@@ -94,11 +95,9 @@
         int offset = boldElement.getStartOffset();
         int length = boldElement.getEndOffset() - offset;
         buf.change(offset, length, createEvent(offset, length));
-
         assertEquals(0, getEdits(event).size());
-
-        assertChildren(paragraph, new int[] {0, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, null});
+        assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
+                null, bold, italic, null });
     }
 
     /**
@@ -110,14 +109,11 @@
         int offset = boldElement.getStartOffset();
         int length = (boldElement.getEndOffset() - offset) / 2;
         buf.change(offset, length, createEvent(offset, length));
-
-        final List edits = getEdits(event);
+        final List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), paragraph, 1,
-                     new int[] {5, 9}, new int[] {5, 7, 7, 9});
-
-        assertChildren(paragraph, new int[] {0, 5, 5, 7, 7, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, bold, italic, null});
+        assertChange(edits.get(0), paragraph, 1, new int[] { 5, 9 }, new int[] { 5, 7, 7, 9 });
+        assertChildren(paragraph, new int[] { 0, 5, 5, 7, 7, 9, 9, 15, 15, 16 },
+                new AttributeSet[] { null, bold, bold, italic, null });
     }
 
     /**
@@ -126,18 +122,14 @@
      */
     public void testChangeElementEnd() throws Exception {
         Element boldElement = paragraph.getElement(1);
-        int offset = (boldElement.getStartOffset()
-                     + boldElement.getEndOffset()) / 2;
+        int offset = (boldElement.getStartOffset() + boldElement.getEndOffset()) / 2;
         int length = boldElement.getEndOffset() - offset;
         buf.change(offset, length, createEvent(offset, length));
-
-        final List edits = getEdits(event);
+        final List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), paragraph, 1,
-                     new int[] {5, 9}, new int[] {5, 7, 7, 9});
-
-        assertChildren(paragraph, new int[] {0, 5, 5, 7, 7, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, bold, italic, null});
+        assertChange(edits.get(0), paragraph, 1, new int[] { 5, 9 }, new int[] { 5, 7, 7, 9 });
+        assertChildren(paragraph, new int[] { 0, 5, 5, 7, 7, 9, 9, 15, 15, 16 },
+                new AttributeSet[] { null, bold, bold, italic, null });
     }
 
     /**
@@ -150,11 +142,9 @@
         int offset = plainElement.getStartOffset();
         int length = boldElement.getEndOffset() - offset;
         buf.change(offset, length, createEvent(offset, length));
-
         assertEquals(0, getEdits(event).size());
-
-        assertChildren(paragraph, new int[] {0, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, null});
+        assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
+                null, bold, italic, null });
     }
 
     /**
@@ -166,17 +156,13 @@
         Element plainElement = paragraph.getElement(0);
         Element boldElement = paragraph.getElement(1);
         int offset = plainElement.getStartOffset();
-        int length = (boldElement.getStartOffset()
-                      + boldElement.getEndOffset()) / 2;
+        int length = (boldElement.getStartOffset() + boldElement.getEndOffset()) / 2;
         buf.change(offset, length, createEvent(offset, length));
-
-        final List edits = getEdits(event);
+        final List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), paragraph, 1,
-                     new int[] {5, 9}, new int[] {5, 7, 7, 9});
-
-        assertChildren(paragraph, new int[] {0, 5, 5, 7, 7, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, bold, bold, italic, null});
+        assertChange(edits.get(0), paragraph, 1, new int[] { 5, 9 }, new int[] { 5, 7, 7, 9 });
+        assertChildren(paragraph, new int[] { 0, 5, 5, 7, 7, 9, 9, 15, 15, 16 },
+                new AttributeSet[] { null, bold, bold, italic, null });
     }
 
     /**
@@ -187,18 +173,14 @@
     public void testChange2ElementsEnd() throws Exception {
         Element plainElement = paragraph.getElement(0);
         Element boldElement = paragraph.getElement(1);
-        int offset = (plainElement.getStartOffset()
-                      + plainElement.getEndOffset()) / 2;
+        int offset = (plainElement.getStartOffset() + plainElement.getEndOffset()) / 2;
         int length = boldElement.getEndOffset() - offset;
         buf.change(offset, length, createEvent(offset, length));
-
-        final List edits = getEdits(event);
+        final List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), paragraph, 0,
-                     new int[] {0, 5}, new int[] {0, 2, 2, 5});
-
-        assertChildren(paragraph, new int[] {0, 2, 2, 5, 5, 9, 9, 15, 15, 16},
-                       new AttributeSet[] {null, null, bold, italic, null});
+        assertChange(edits.get(0), paragraph, 0, new int[] { 0, 5 }, new int[] { 0, 2, 2, 5 });
+        assertChildren(paragraph, new int[] { 0, 2, 2, 5, 5, 9, 9, 15, 15, 16 },
+                new AttributeSet[] { null, null, bold, italic, null });
     }
 
     /**
@@ -213,28 +195,21 @@
     public void testChange3ElementsStartEnd() throws Exception {
         Element plainElement = paragraph.getElement(0);
         Element italicElement = paragraph.getElement(2);
-        int offset = (plainElement.getStartOffset()
-                     + plainElement.getEndOffset()) / 2;
-        int length = (italicElement.getStartOffset()
-                      + italicElement.getEndOffset()) / 2 - offset;
+        int offset = (plainElement.getStartOffset() + plainElement.getEndOffset()) / 2;
+        int length = (italicElement.getStartOffset() + italicElement.getEndOffset()) / 2
+                - offset;
         buf.change(offset, length, createEvent(offset, length));
-
-        final List edits = getEdits(event);
+        final List<?> edits = getEdits(event);
         assertEquals(1, edits.size());
-        assertChange(edits.get(0), paragraph, 0,
-                     new int[] {0, 5, 5, 9, 9, 15},
-                     new int[] {0, 2, 2, 5, 5, 9, 9, 12, 12, 15});
-
+        assertChange(edits.get(0), paragraph, 0, new int[] { 0, 5, 5, 9, 9, 15 }, new int[] {
+                0, 2, 2, 5, 5, 9, 9, 12, 12, 15 });
         // Merge of two changes is performed by copying elements which
         // lie between split ones
-        ElementChange change = (ElementChange)edits.get(0);
+        ElementChange change = (ElementChange) edits.get(0);
         assertSame(change.getChildrenRemoved()[1], // bold [5, 9]
-                   change.getChildrenAdded()[2]);
-
-        assertChildren(paragraph,
-                       new int[] {0, 2, 2, 5, 5, 9, 9, 12, 12, 15, 15, 16},
-                       new AttributeSet[] {null, null, bold,
-                                           italic, italic, null});
+                change.getChildrenAdded()[2]);
+        assertChildren(paragraph, new int[] { 0, 2, 2, 5, 5, 9, 9, 12, 12, 15, 15, 16 },
+                new AttributeSet[] { null, null, bold, italic, italic, null });
     }
 
     /**
@@ -243,46 +218,37 @@
     public void testChange2Paragraphs() throws Exception {
         Element italicElement = paragraph.getElement(2);
         Element paragraph2 = root.getElement(1);
-        int offset = (italicElement.getStartOffset()
-                     + italicElement.getEndOffset()) / 2;
-        int length = (paragraph2.getStartOffset()
-                      + paragraph2.getEndOffset()) / 2 - offset;
+        int offset = (italicElement.getStartOffset() + italicElement.getEndOffset()) / 2;
+        int length = (paragraph2.getStartOffset() + paragraph2.getEndOffset()) / 2 - offset;
         buf.change(offset, length, createEvent(offset, length));
-
-        final List edits = getEdits(event);
+        final List<?> edits = getEdits(event);
         assertEquals(2, edits.size());
-        assertChange(edits.get(0), paragraph, 2,
-                     new int[] {9, 15}, new int[] {9, 12, 12, 15});
-        assertChange(edits.get(1), paragraph2, 0,
-                     new int[] {16, 21}, new int[] {16, 18, 18, 21});
-
-        assertChildren(paragraph, new int[] {0, 5, 5, 9, 9, 12, 12, 15, 15, 16},
-                       new AttributeSet[] {null, bold, italic, italic, null});
-        assertChildren(paragraph2, new int[] {16, 18, 18, 21},
-                       new AttributeSet[] {null, null});
-    }
-
-    private static void assertChange(final Object change,
-                                     final Element element,
-                                     final int index,
-                                     final int[] removed, final int[] added) {
-        DefStyledDoc_Helpers.assertChange(change, element, index,
-                                          removed, added);
-    }
-
-    private static void assertChildren(final Element element,
-                                       final int[] offsets,
-                                       final AttributeSet[] attributes) {
+        assertChange(edits.get(0), paragraph, 2, new int[] { 9, 15 },
+                new int[] { 9, 12, 12, 15 });
+        assertChange(edits.get(1), paragraph2, 0, new int[] { 16, 21 }, new int[] { 16, 18, 18,
+                21 });
+        assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 12, 12, 15, 15, 16 },
+                new AttributeSet[] { null, bold, italic, italic, null });
+        assertChildren(paragraph2, new int[] { 16, 18, 18, 21 }, new AttributeSet[] { null,
+                null });
+    }
+
+    private static void assertChange(final Object change, final Element element,
+            final int index, final int[] removed, final int[] added) {
+        DefStyledDoc_Helpers.assertChange(change, element, index, removed, added);
+    }
+
+    private static void assertChildren(final Element element, final int[] offsets,
+            final AttributeSet[] attributes) {
         DefStyledDoc_Helpers.assertChildren(element, offsets, attributes);
     }
 
-    private DefaultDocumentEvent createEvent(final int offset,
-                                             final int length) {
+    private DefaultDocumentEvent createEvent(final int offset, final int length) {
         event = doc.new DefaultDocumentEvent(offset, length, EventType.CHANGE);
         return event;
     }
 
-    private static List getEdits(final DefaultDocumentEvent event) {
+    private static List<?> getEdits(final DefaultDocumentEvent event) {
         return DefStyledDoc_Helpers.getEdits(event);
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertMiscTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertMiscTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertMiscTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_ElementBuffer_InsertMiscTest.java Sun Nov 26 12:15:43 2006
@@ -21,7 +21,6 @@
 package javax.swing.text;
 
 import java.util.List;
-
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import javax.swing.event.DocumentEvent.ElementChange;
@@ -30,7 +29,6 @@
 import javax.swing.text.AbstractDocument.DefaultDocumentEvent;
 import javax.swing.text.DefaultStyledDocument.ElementBuffer;
 import javax.swing.text.DefaultStyledDocument.ElementSpec;
-
 import junit.framework.TestCase;
 
 /**
@@ -41,35 +39,43 @@
  * expected set of <code>ElementSpec</code>s.
  *
  */
-public class DefaultStyledDocument_ElementBuffer_InsertMiscTest
-    extends TestCase implements DocumentListener {
-
+public class DefaultStyledDocument_ElementBuffer_InsertMiscTest extends TestCase implements
+        DocumentListener {
     private DefaultStyledDocument doc;
+
     private ElementBuffer buf;
+
     private Element root;
+
     private Content content;
+
     private DefaultDocumentEvent event;
+
     private DefaultDocumentEvent insertEvent;
+
     private ElementSpec[] insertSpecs;
 
+    @Override
     protected void setUp() throws Exception {
         super.setUp();
         doc = new DefaultStyledDocument();
         root = doc.getDefaultRootElement();
         buf = new DefStyledDoc_Helpers.ElementBufferWithLogging(doc, root) {
+            private static final long serialVersionUID = 1L;
+
+            @Override
             public void insert(int offset, int length, ElementSpec[] spec,
-                               DefaultDocumentEvent event) {
+                    DefaultDocumentEvent event) {
                 super.insert(offset, length, insertSpecs = spec, event);
             }
         };
         doc.buffer = buf;
         content = doc.getContent();
-
         doc.addDocumentListener(this);
-
         doc.writeLock();
     }
 
+    @Override
     protected void tearDown() throws Exception {
         super.tearDown();
         doc.writeUnlock();
@@ -85,39 +91,27 @@
         final int textLen = text.length();
         //doc.insertString(0, text, null);
         content.insertString(0, text);
-        event = doc.new DefaultDocumentEvent(0, textLen,
-                                             EventType.INSERT);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, 6),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, 7),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, 5),
-        };
+        event = doc.new DefaultDocumentEvent(0, textLen, EventType.INSERT);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, 6),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, 7),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, 5), };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[specs.length - 2].setDirection(ElementSpec.JoinFractureDirection);
         specs[specs.length - 1].setDirection(ElementSpec.JoinNextDirection);
-
         buf.insert(0, textLen, specs, event);
-
-        List edits = getEdits(event);
+        List<?> edits = getEdits(event);
         assertEquals(4, edits.size());
-
-        assertChange(edits.get(0), 0, new int[] {0, 19}, new int[] {0, 6});
-        assertChange(edits.get(1), 0, new int[] {}, new int[] {6, 13});
-        assertChange(edits.get(2), 0, new int[] {18, 19}, new int[] {13, 19});
-        assertChange(edits.get(3), 1, new int[] {}, new int[] {6, 13, 13, 19});
-
-        assertChildren(root.getElement(0), new int[] {0, 6},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1), new int[] {6, 13},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2), new int[] {13, 19},
-                       new AttributeSet[] {null});
-
+        assertChange(edits.get(0), 0, new int[] { 0, 19 }, new int[] { 0, 6 });
+        assertChange(edits.get(1), 0, new int[] {}, new int[] { 6, 13 });
+        assertChange(edits.get(2), 0, new int[] { 18, 19 }, new int[] { 13, 19 });
+        assertChange(edits.get(3), 1, new int[] {}, new int[] { 6, 13, 13, 19 });
+        assertChildren(root.getElement(0), new int[] { 0, 6 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 6, 13 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 13, 19 }, new AttributeSet[] { null });
         assertEquals("first\n", getText(doc.getCharacterElement(0)));
         assertEquals("second\n", getText(doc.getCharacterElement(0 + 6)));
         assertEquals("third\n", getText(doc.getCharacterElement(0 + 6 + 7)));
@@ -132,38 +126,27 @@
     public void testInsertUpdateThreePars() throws Exception {
         final String text = "first\nsecond\nthird";
         doc.insertString(0, text, null);
-//        doc.dump(System.out);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.ContentType, 6),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, 7),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, 5),
-        };
+        //        doc.dump(System.out);
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, 6),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, 7),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, 5), };
         specs[0].setDirection(ElementSpec.JoinPreviousDirection);
         specs[specs.length - 2].setDirection(ElementSpec.JoinFractureDirection);
         specs[specs.length - 1].setDirection(ElementSpec.JoinNextDirection);
-
         assertSpecs(specs, insertSpecs);
-
-        List edits = getEdits(insertEvent);
+        List<?> edits = getEdits(insertEvent);
         assertEquals(5, edits.size());
-
-        assertChange(edits.get(1), 0, new int[] {0, 19}, new int[] {0, 6});
-        assertChange(edits.get(2), 0, new int[] {}, new int[] {6, 13});
-        assertChange(edits.get(3), 0, new int[] {18, 19}, new int[] {13, 19});
-        assertChange(edits.get(4), 1, new int[] {}, new int[] {6, 13, 13, 19});
-
-        assertChildren(root.getElement(0), new int[] {0, 6},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1), new int[] {6, 13},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2), new int[] {13, 19},
-                       new AttributeSet[] {null});
-
+        assertChange(edits.get(1), 0, new int[] { 0, 19 }, new int[] { 0, 6 });
+        assertChange(edits.get(2), 0, new int[] {}, new int[] { 6, 13 });
+        assertChange(edits.get(3), 0, new int[] { 18, 19 }, new int[] { 13, 19 });
+        assertChange(edits.get(4), 1, new int[] {}, new int[] { 6, 13, 13, 19 });
+        assertChildren(root.getElement(0), new int[] { 0, 6 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 6, 13 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 13, 19 }, new AttributeSet[] { null });
         assertEquals("first\n", getText(doc.getCharacterElement(0)));
         assertEquals("second\n", getText(doc.getCharacterElement(0 + 6)));
         assertEquals("third\n", getText(doc.getCharacterElement(0 + 6 + 7)));
@@ -174,39 +157,26 @@
         doc.insertString(0, initialText, null);
         final int offset = root.getElement(0).getEndOffset();
         doc.insertString(offset, "^^^\n", null);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, 4),
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType)
-        };
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, 4),
+                new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType) };
         specs[specs.length - 1].setDirection(ElementSpec.JoinNextDirection);
-
         assertSpecs(specs, insertSpecs);
-
-        List edits = getEdits(insertEvent);
+        List<?> edits = getEdits(insertEvent);
         assertEquals(4, edits.size());
-
-        assertChange(edits.get(1), 0, new int[] {0, 8}, new int[] {0, 4});
-        assertChange(edits.get(2), 0, new int[] {}, new int[] {4, 8});
-        assertChange(edits.get(3), 1, new int[] {}, new int[] {4, 8});
-
-        assertChildren(root.getElement(0), new int[] {0, 4},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1), new int[] {4, 8},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2), new int[] {8, 12},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(3), new int[] {12, 18},
-                       new AttributeSet[] {null});
-
+        assertChange(edits.get(1), 0, new int[] { 0, 8 }, new int[] { 0, 4 });
+        assertChange(edits.get(2), 0, new int[] {}, new int[] { 4, 8 });
+        assertChange(edits.get(3), 1, new int[] {}, new int[] { 4, 8 });
+        assertChildren(root.getElement(0), new int[] { 0, 4 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 4, 8 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 8, 12 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(3), new int[] { 12, 18 }, new AttributeSet[] { null });
         assertEquals("one\n", getText(doc.getCharacterElement(0)));
         assertEquals("^^^\n", getText(doc.getCharacterElement(0 + 4)));
         assertEquals("two\n", getText(doc.getCharacterElement(0 + 4 + 4)));
-        assertEquals("three\n", getText(doc.getCharacterElement(0 + 4 + 4
-                                                                + 4)));
+        assertEquals("three\n", getText(doc.getCharacterElement(0 + 4 + 4 + 4)));
     }
 
     public void testInsertRightAfterNewLineWithoutNewLine() throws Exception {
@@ -214,67 +184,49 @@
         doc.insertString(0, initialText, null);
         final int offset = root.getElement(0).getEndOffset();
         doc.insertString(offset, "^^^", null);
-
-        ElementSpec[] specs = {
-            new ElementSpec(null, ElementSpec.EndTagType),
-            new ElementSpec(null, ElementSpec.StartTagType),
-            new ElementSpec(null, ElementSpec.ContentType, 3),
-        };
+        ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
+                new ElementSpec(null, ElementSpec.StartTagType),
+                new ElementSpec(null, ElementSpec.ContentType, 3), };
         specs[specs.length - 2].setDirection(ElementSpec.JoinNextDirection);
         specs[specs.length - 1].setDirection(ElementSpec.JoinNextDirection);
-
         assertSpecs(specs, insertSpecs);
-
-        List edits = getEdits(insertEvent);
+        List<?> edits = getEdits(insertEvent);
         assertEquals(3, edits.size());
-
-        assertChange(edits.get(1), 0, new int[] {0, 7}, new int[] {0, 4});
-        assertChange(edits.get(2), 0, new int[] {7, 11}, new int[] {4, 11});
-
-        assertChildren(root.getElement(0), new int[] {0, 4},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(1), new int[] {4, 11},
-                       new AttributeSet[] {null});
-        assertChildren(root.getElement(2), new int[] {11, 17},
-                       new AttributeSet[] {null});
-
+        assertChange(edits.get(1), 0, new int[] { 0, 7 }, new int[] { 0, 4 });
+        assertChange(edits.get(2), 0, new int[] { 7, 11 }, new int[] { 4, 11 });
+        assertChildren(root.getElement(0), new int[] { 0, 4 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(1), new int[] { 4, 11 }, new AttributeSet[] { null });
+        assertChildren(root.getElement(2), new int[] { 11, 17 }, new AttributeSet[] { null });
         assertEquals("one\n", getText(doc.getCharacterElement(0)));
         assertEquals("^^^two\n", getText(doc.getCharacterElement(0 + 4)));
         assertEquals("three\n", getText(doc.getCharacterElement(0 + 4 + 7)));
     }
 
-    private String getText(final int offset, final int length)
-        throws BadLocationException {
-
+    private String getText(final int offset, final int length) throws BadLocationException {
         return doc.getText(offset, length);
     }
 
     private String getText(final Element element) throws BadLocationException {
-        return getText(element.getStartOffset(),
-                       element.getEndOffset() - element.getStartOffset());
+        return getText(element.getStartOffset(), element.getEndOffset()
+                - element.getStartOffset());
+    }
+
+    private static void assertChange(final Object change, final int index,
+            final int[] removedOffsets, final int[] addedOffsets) {
+        assertEquals("Change index", index, ((ElementChange) change).getIndex());
+        DefStyledDoc_Helpers.assertChange((ElementChange) change, removedOffsets, addedOffsets);
     }
 
-    private static void assertChange(final Object change,
-                                     final int index,
-                                     final int[] removedOffsets,
-                                     final int[] addedOffsets) {
-        assertEquals("Change index", index, ((ElementChange)change).getIndex());
-        DefStyledDoc_Helpers.assertChange((ElementChange)change,
-                                          removedOffsets, addedOffsets);
-    }
-
-    private static void assertChildren(final Element element,
-                                       final int[] offsets,
-                                       final AttributeSet[] attributes) {
+    private static void assertChildren(final Element element, final int[] offsets,
+            final AttributeSet[] attributes) {
         DefStyledDoc_Helpers.assertChildren(element, offsets, attributes);
     }
 
-    private static void assertSpecs(final ElementSpec[] specs,
-                                    final ElementSpec[] insertSpecs) {
+    private static void assertSpecs(final ElementSpec[] specs, final ElementSpec[] insertSpecs) {
         DefStyledDoc_Helpers.assertSpecs(specs, insertSpecs);
     }
 
-    private static List getEdits(final DefaultDocumentEvent event) {
+    private static List<?> getEdits(final DefaultDocumentEvent event) {
         return DefStyledDoc_Helpers.getEdits(event);
     }
 
@@ -282,7 +234,7 @@
     }
 
     public void insertUpdate(DocumentEvent e) {
-        insertEvent = (DefaultDocumentEvent)e;
+        insertEvent = (DefaultDocumentEvent) e;
     }
 
     public void removeUpdate(DocumentEvent e) {



Mime
View raw message