You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/11/26 21:15:55 UTC
svn commit: r479418 [23/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...
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultGlyphPainterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultGlyphPainterTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultGlyphPainterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultGlyphPainterTest.java Sun Nov 26 12:15:43 2006
@@ -24,12 +24,10 @@
import java.awt.FontMetrics;
import java.awt.Rectangle;
import java.awt.Toolkit;
-
import javax.swing.BasicSwingTestCase;
import javax.swing.SwingConstants;
import javax.swing.text.GlyphView.GlyphPainter;
import javax.swing.text.Position.Bias;
-
import junit.framework.TestCase;
/**
@@ -38,325 +36,230 @@
*/
public class DefaultGlyphPainterTest extends TestCase {
private GlyphPainter painter;
+
private GlyphView view;
+
private StyledDocument doc;
+
private Element root;
+
private Element leaf;
+
private Rectangle alloc;
private Font font;
+
private FontMetrics metrics;
- private static final String FULL_TEXT =
- "this text to check how view breaks";
- // 0123456789012345678901234567890123
+ private static final String FULL_TEXT = "this text to check how view breaks";
+ // 0123456789012345678901234567890123
private static final int startOffset = 5;
+
private static final int endOffset = 28;
+
private static final int length = endOffset - startOffset;
- private static final String LEAF_TEXT =
- FULL_TEXT.substring(startOffset, endOffset);
+ private static final String LEAF_TEXT = FULL_TEXT.substring(startOffset, endOffset);
+ @SuppressWarnings("deprecation")
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new DefaultStyledDocument();
root = doc.getDefaultRootElement();
doc.insertString(0, FULL_TEXT, null);
- doc.setCharacterAttributes(startOffset, length,
- SimpleAttributeSet.EMPTY, false);
+ doc.setCharacterAttributes(startOffset, length, SimpleAttributeSet.EMPTY, false);
leaf = root.getElement(0).getElement(1);
-
view = new GlyphView(leaf);
view.checkPainter();
painter = view.getGlyphPainter();
-
font = view.getFont();
metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
alloc = new Rectangle(12, 21, 129, 17);
alloc.width = getX(length - 1) - 1 - alloc.x;
}
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
}
public void testGetSpan() {
- assertEquals(metrics.stringWidth(LEAF_TEXT),
- (int)painter.getSpan(view, startOffset, endOffset,
- null, 0));
-
+ assertEquals(metrics.stringWidth(LEAF_TEXT), (int) painter.getSpan(view, startOffset,
+ endOffset, null, 0));
final int end = LEAF_TEXT.indexOf(' ') + 1;
- assertEquals(metrics.stringWidth(LEAF_TEXT.substring(0, end)),
- (int)painter.getSpan(view, startOffset, startOffset + end,
- null, 0));
+ assertEquals(metrics.stringWidth(LEAF_TEXT.substring(0, end)), (int) painter.getSpan(
+ view, startOffset, startOffset + end, null, 0));
}
public void testGetHeight() {
- assertEquals(metrics.getHeight(), (int)painter.getHeight(view));
+ assertEquals(metrics.getHeight(), (int) painter.getHeight(view));
}
public void testGetAscent() {
- assertEquals(metrics.getAscent(), (int)painter.getAscent(view));
+ assertEquals(metrics.getAscent(), (int) painter.getAscent(view));
}
public void testGetDescent() {
- assertEquals(metrics.getDescent(), (int)painter.getDescent(view));
+ assertEquals(metrics.getDescent(), (int) painter.getDescent(view));
}
public void testModelToView() throws BadLocationException {
- assertEquals(new Rectangle(alloc.x, alloc.y, 0, metrics.getHeight()),
- painter.modelToView(view, startOffset, Bias.Forward,
- alloc));
-
- assertEquals(new Rectangle(alloc.x, alloc.y, 0, metrics.getHeight()),
- painter.modelToView(view, startOffset, Bias.Backward,
- alloc));
-
- assertEquals(new Rectangle(getX(1), alloc.y, 0, metrics.getHeight()),
- painter.modelToView(view, startOffset + 1, Bias.Forward,
- alloc));
-
- assertEquals(new Rectangle(getX(2), alloc.y, 0, metrics.getHeight()),
- painter.modelToView(view, startOffset + 2, Bias.Forward,
- alloc));
-
- assertEquals(new Rectangle(getX(length - 1), alloc.y,
- 0, metrics.getHeight()),
- painter.modelToView(view, endOffset - 1, Bias.Forward,
- alloc));
+ assertEquals(new Rectangle(alloc.x, alloc.y, 0, metrics.getHeight()), painter
+ .modelToView(view, startOffset, Bias.Forward, alloc));
+ assertEquals(new Rectangle(alloc.x, alloc.y, 0, metrics.getHeight()), painter
+ .modelToView(view, startOffset, Bias.Backward, alloc));
+ assertEquals(new Rectangle(getX(1), alloc.y, 0, metrics.getHeight()), painter
+ .modelToView(view, startOffset + 1, Bias.Forward, alloc));
+ assertEquals(new Rectangle(getX(2), alloc.y, 0, metrics.getHeight()), painter
+ .modelToView(view, startOffset + 2, Bias.Forward, alloc));
+ assertEquals(new Rectangle(getX(length - 1), alloc.y, 0, metrics.getHeight()), painter
+ .modelToView(view, endOffset - 1, Bias.Forward, alloc));
assertTrue(getX(length - 1) > alloc.x + alloc.width);
-
- assertEquals(new Rectangle(BasicSwingTestCase.isHarmony()
- ? getX(length)
- : alloc.x + alloc.width,
- alloc.y, 0, metrics.getHeight()),
- painter.modelToView(view, endOffset, Bias.Forward,
- alloc));
+ assertEquals(new Rectangle(BasicSwingTestCase.isHarmony() ? getX(length) : alloc.x
+ + alloc.width, alloc.y, 0, metrics.getHeight()), painter.modelToView(view,
+ endOffset, Bias.Forward, alloc));
}
public void testViewToModel() {
Bias[] bias = new Bias[1];
- assertEquals(startOffset,
- painter.viewToModel(view, alloc.x - 1, alloc.y,
- alloc, bias));
+ assertEquals(startOffset, painter.viewToModel(view, alloc.x - 1, alloc.y, alloc, bias));
assertSame(Bias.Forward, bias[0]);
- assertEquals(startOffset,
- painter.viewToModel(view, alloc.x, alloc.y - 1,
- alloc, bias));
+ assertEquals(startOffset, painter.viewToModel(view, alloc.x, alloc.y - 1, alloc, bias));
assertSame(Bias.Forward, bias[0]);
- assertEquals(startOffset,
- painter.viewToModel(view, alloc.x, alloc.y,
- alloc, bias));
+ assertEquals(startOffset, painter.viewToModel(view, alloc.x, alloc.y, alloc, bias));
assertSame(Bias.Forward, bias[0]);
-
- assertEquals(startOffset + 1,
- painter.viewToModel(view, getX(1), alloc.y,
- alloc, bias));
+ assertEquals(startOffset + 1, painter.viewToModel(view, getX(1), alloc.y, alloc, bias));
assertSame(Bias.Forward, bias[0]);
- assertEquals(startOffset + 2,
- painter.viewToModel(view, getX(2), alloc.y,
- alloc, bias));
+ assertEquals(startOffset + 2, painter.viewToModel(view, getX(2), alloc.y, alloc, bias));
assertSame(Bias.Forward, bias[0]);
-
- assertEquals(endOffset - 1,
- painter.viewToModel(view, getX(length - 1), alloc.y,
- alloc, bias));
+ assertEquals(endOffset - 1, painter.viewToModel(view, getX(length - 1), alloc.y, alloc,
+ bias));
assertSame(Bias.Forward, bias[0]);
- assertEquals(endOffset - 1,
- painter.viewToModel(view, getX(length), alloc.y,
- alloc, bias));
+ assertEquals(endOffset - 1, painter.viewToModel(view, getX(length), alloc.y, alloc,
+ bias));
assertSame(Bias.Forward, bias[0]);
-
- assertEquals(endOffset - 1,
- painter.viewToModel(view, getX(length) + 100, alloc.y,
- alloc, bias));
+ assertEquals(endOffset - 1, painter.viewToModel(view, getX(length) + 100, alloc.y,
+ alloc, bias));
assertSame(Bias.Forward, bias[0]);
- assertEquals(endOffset - 1,
- painter.viewToModel(view, getX(length),
- alloc.y + alloc.height + 10,
- alloc, bias));
+ assertEquals(endOffset - 1, painter.viewToModel(view, getX(length), alloc.y
+ + alloc.height + 10, alloc, bias));
assertSame(Bias.Forward, bias[0]);
}
public void testGetBoundedPosition() {
// No char can fit; the same offset is returned
- assertEquals(startOffset + 1,
- painter.getBoundedPosition(view, startOffset + 1,
- alloc.x, 1));
-
+ assertEquals(startOffset + 1, painter.getBoundedPosition(view, startOffset + 1,
+ alloc.x, 1));
// width is the width of the first char
float width = metrics.stringWidth(LEAF_TEXT.substring(0, 1));
- assertEquals(startOffset,
- painter.getBoundedPosition(view, startOffset,
- alloc.x, width - 0.01f));
- assertEquals(startOffset + 1,
- painter.getBoundedPosition(view, startOffset,
- alloc.x, width));
- assertEquals(startOffset + 1,
- painter.getBoundedPosition(view, startOffset,
- alloc.x, width + 0.01f));
-
+ assertEquals(startOffset, painter.getBoundedPosition(view, startOffset, alloc.x,
+ width - 0.01f));
+ assertEquals(startOffset + 1, painter.getBoundedPosition(view, startOffset, alloc.x,
+ width));
+ assertEquals(startOffset + 1, painter.getBoundedPosition(view, startOffset, alloc.x,
+ width + 0.01f));
// width includes two chars
width = metrics.stringWidth(LEAF_TEXT.substring(0, 2));
- assertEquals(startOffset + 2,
- painter.getBoundedPosition(view, startOffset,
- alloc.x, width));
-
+ assertEquals(startOffset + 2, painter.getBoundedPosition(view, startOffset, alloc.x,
+ width));
// Two chars (the second and the third) starting not at the beginning
// of the view
width = metrics.stringWidth(LEAF_TEXT.substring(1, 3));
- assertEquals(startOffset + 3,
- painter.getBoundedPosition(view, startOffset + 1,
- alloc.x, width));
-
+ assertEquals(startOffset + 3, painter.getBoundedPosition(view, startOffset + 1,
+ alloc.x, width));
// Can't return offset greater than view.getEndOffset()
- assertEquals(endOffset,
- painter.getBoundedPosition(view, endOffset,
- alloc.x, width));
+ assertEquals(endOffset, painter.getBoundedPosition(view, endOffset, alloc.x, width));
}
public void testGetPainter() {
assertSame(painter, painter.getPainter(view, startOffset, endOffset));
- assertSame(painter, painter.getPainter(new GlyphView(leaf),
- startOffset, endOffset));
+ assertSame(painter, painter.getPainter(new GlyphView(leaf), startOffset, endOffset));
assertSame(painter, painter.getPainter(view, 0, 4));
- assertSame(painter, painter.getPainter(view,
- endOffset + 5, endOffset + 10));
+ assertSame(painter, painter.getPainter(view, endOffset + 5, endOffset + 10));
}
- public void testGetNextVisualPositionFromWest()
- throws BadLocationException {
-
+ public void testGetNextVisualPositionFromWest() throws BadLocationException {
final boolean isHarmony = BasicSwingTestCase.isHarmony();
Bias[] bias = new Bias[1];
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, startOffset,
- Bias.Forward, alloc,
- SwingConstants.WEST,
- bias));
- assertNull(bias[0]);
- assertEquals(isHarmony ? -1 : startOffset - 2,
- painter.getNextVisualPositionFrom(view, startOffset - 1,
- Bias.Forward, alloc,
- SwingConstants.WEST,
- bias));
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, startOffset, Bias.Forward,
+ alloc, SwingConstants.WEST, bias));
+ assertNull(bias[0]);
+ assertEquals(isHarmony ? -1 : startOffset - 2, painter.getNextVisualPositionFrom(view,
+ startOffset - 1, Bias.Forward, alloc, SwingConstants.WEST, bias));
if (isHarmony) {
assertNull(bias[0]);
} else {
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
}
- assertEquals(startOffset,
- painter.getNextVisualPositionFrom(view, startOffset + 1,
- Bias.Forward, alloc,
- SwingConstants.WEST,
- bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
- assertEquals(startOffset + 1,
- painter.getNextVisualPositionFrom(view, startOffset + 2,
- Bias.Forward, alloc,
- SwingConstants.WEST,
- bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
+ assertEquals(startOffset, painter.getNextVisualPositionFrom(view, startOffset + 1,
+ Bias.Forward, alloc, SwingConstants.WEST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
+ assertEquals(startOffset + 1, painter.getNextVisualPositionFrom(view, startOffset + 2,
+ Bias.Forward, alloc, SwingConstants.WEST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
}
- public void testGetNextVisualPositionFromEast()
- throws BadLocationException {
-
+ public void testGetNextVisualPositionFromEast() throws BadLocationException {
final boolean isHarmony = BasicSwingTestCase.isHarmony();
Bias[] bias = new Bias[1];
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, endOffset,
- Bias.Forward, alloc,
- SwingConstants.EAST,
- bias));
- assertNull(bias[0]);
- assertEquals(isHarmony ? -1 : endOffset + 2,
- painter.getNextVisualPositionFrom(view, endOffset + 1,
- Bias.Forward, alloc,
- SwingConstants.EAST,
- bias));
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, endOffset, Bias.Forward,
+ alloc, SwingConstants.EAST, bias));
+ assertNull(bias[0]);
+ assertEquals(isHarmony ? -1 : endOffset + 2, painter.getNextVisualPositionFrom(view,
+ endOffset + 1, Bias.Forward, alloc, SwingConstants.EAST, bias));
if (isHarmony) {
assertNull(bias[0]);
} else {
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
}
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, endOffset - 1,
- Bias.Forward, alloc,
- SwingConstants.EAST,
- bias));
- assertNull(bias[0]);
- assertEquals(endOffset - 1,
- painter.getNextVisualPositionFrom(view, endOffset - 2,
- Bias.Forward, alloc,
- SwingConstants.EAST,
- bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, endOffset - 1, Bias.Forward,
+ alloc, SwingConstants.EAST, bias));
+ assertNull(bias[0]);
+ assertEquals(endOffset - 1, painter.getNextVisualPositionFrom(view, endOffset - 2,
+ Bias.Forward, alloc, SwingConstants.EAST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
}
- public void testGetNextVisualPositionFromNorth()
- throws BadLocationException {
-
+ public void testGetNextVisualPositionFromNorth() throws BadLocationException {
Bias[] bias = new Bias[1];
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, startOffset,
- Bias.Forward, alloc,
- SwingConstants.NORTH,
- bias));
- assertNull(bias[0]);
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, startOffset - 1,
- Bias.Forward, alloc,
- SwingConstants.NORTH,
- bias));
- assertNull(bias[0]);
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, startOffset + 1,
- Bias.Forward, alloc,
- SwingConstants.NORTH,
- bias));
- assertNull(bias[0]);
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, startOffset + 2,
- Bias.Forward, alloc,
- SwingConstants.NORTH,
- bias));
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, startOffset, Bias.Forward,
+ alloc, SwingConstants.NORTH, bias));
+ assertNull(bias[0]);
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, startOffset - 1, Bias.Forward,
+ alloc, SwingConstants.NORTH, bias));
+ assertNull(bias[0]);
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, startOffset + 1, Bias.Forward,
+ alloc, SwingConstants.NORTH, bias));
+ assertNull(bias[0]);
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, startOffset + 2, Bias.Forward,
+ alloc, SwingConstants.NORTH, bias));
assertNull(bias[0]);
}
- public void testGetNextVisualPositionFromSouth()
- throws BadLocationException {
-
+ public void testGetNextVisualPositionFromSouth() throws BadLocationException {
Bias[] bias = new Bias[1];
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, endOffset,
- Bias.Forward, alloc,
- SwingConstants.SOUTH,
- bias));
- assertNull(bias[0]);
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, endOffset + 1,
- Bias.Forward, alloc,
- SwingConstants.SOUTH,
- bias));
- assertNull(bias[0]);
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, endOffset - 1,
- Bias.Forward, alloc,
- SwingConstants.SOUTH,
- bias));
- assertNull(bias[0]);
- assertEquals(-1,
- painter.getNextVisualPositionFrom(view, endOffset - 2,
- Bias.Forward, alloc,
- SwingConstants.SOUTH,
- bias));
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, endOffset, Bias.Forward,
+ alloc, SwingConstants.SOUTH, bias));
+ assertNull(bias[0]);
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, endOffset + 1, Bias.Forward,
+ alloc, SwingConstants.SOUTH, bias));
+ assertNull(bias[0]);
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, endOffset - 1, Bias.Forward,
+ alloc, SwingConstants.SOUTH, bias));
+ assertNull(bias[0]);
+ assertEquals(-1, painter.getNextVisualPositionFrom(view, endOffset - 2, Bias.Forward,
+ alloc, SwingConstants.SOUTH, bias));
assertNull(bias[0]);
}
private int getX(final int end) {
return metrics.stringWidth(LEAF_TEXT.substring(0, end)) + alloc.x;
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultHighlighterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultHighlighterTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultHighlighterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultHighlighterTest.java Sun Nov 26 12:15:43 2006
@@ -47,6 +47,7 @@
Object obj5;
+ @Override
protected void setUp() throws Exception {
super.setUp();
jta = new JTextArea("JTextArea for DefaultHighlight Tesing");
@@ -67,6 +68,7 @@
jf.pack();
}
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
@@ -77,19 +79,15 @@
assertNotNull(dh1);
}
- void assertEqualsHighlight(final Highlighter.Highlight h,
- final int start, final int end,
- final Highlighter.HighlightPainter pnt) {
+ void assertEqualsHighlight(final Highlighter.Highlight h, final int start, final int end,
+ final Highlighter.HighlightPainter pnt) {
assertEquals(start, h.getStartOffset());
assertEquals(end, h.getEndOffset());
assertEquals(pnt, h.getPainter());
}
-
-
public void testAddHighlightBadLocationException() {
bWasException = false;
-
try {
dh.addHighlight(-8, -1, lpnt);
} catch (BadLocationException e) {
@@ -98,7 +96,6 @@
if (isHarmony()) {
assertTrue(bWasException);
}
-
bWasException = false;
try {
dh.addHighlight(8, 1, lpnt);
@@ -111,19 +108,16 @@
}
public void testAddHighlight() throws Exception {
-
try {
obj1 = dh.addHighlight(1, 5, lpnt);
} catch (BadLocationException e) {
bWasException = true;
s = e.getMessage();
}
-
assertNotNull(obj1);
dh.getHighlights();
assertEquals(1, dh.getHighlights().length);
assertEqualsHighlight(dh.getHighlights()[0], 1, 5, lpnt);
-
try {
obj2 = dh.addHighlight(3, 7, lpnt);
} catch (BadLocationException e) {
@@ -138,7 +132,6 @@
}
public void testInstall() throws Exception {
-
try {
obj1 = dh.addHighlight(1, 5, lpnt);
} catch (BadLocationException e) {
@@ -146,7 +139,6 @@
s = e.getMessage();
}
assertFalse("Unexpected exception: " + s, bWasException);
-
try {
obj2 = dh.addHighlight(3, 7, lpnt);
} catch (BadLocationException e) {
@@ -154,18 +146,14 @@
s = e.getMessage();
}
assertFalse("Unexpected exception: " + s, bWasException);
-
dh.setDrawsLayeredHighlights(false);
dh.deinstall(jta);
dh.install(jta);
-
assertEquals(0, dh.getHighlights().length);
assertFalse(dh.getDrawsLayeredHighlights());
-
}
public void testDeinstall() throws Exception {
-
try {
obj1 = dh.addHighlight(1, 5, lpnt);
} catch (BadLocationException e) {
@@ -173,7 +161,6 @@
s = e.getMessage();
}
assertFalse("Unexpected exception: " + s, bWasException);
-
try {
obj2 = dh.addHighlight(3, 7, lpnt);
} catch (BadLocationException e) {
@@ -183,13 +170,11 @@
assertFalse("Unexpected exception: " + s, bWasException);
dh.setDrawsLayeredHighlights(false);
dh.deinstall(new JTextArea());
-
assertEquals(2, dh.getHighlights().length);
assertFalse(dh.getDrawsLayeredHighlights());
}
public void testChangeHighlight() throws Exception {
-
try {
obj1 = dh.addHighlight(1, 5, lpnt);
} catch (BadLocationException e) {
@@ -221,7 +206,6 @@
assertEquals(2, dh.getHighlights().length);
assertEqualsHighlight(dh.getHighlights()[0], 1, 8, lpnt);
assertEqualsHighlight(dh.getHighlights()[1], 2, 6, lpnt);
-
}
public void testChangeHighlightBadLocationException() {
@@ -233,22 +217,20 @@
s = e.getMessage();
}
assertFalse("Unexpected exception: " + s, bWasException);
-
bWasException = false;
try {
dh.changeHighlight(obj1, -1, -8);
} catch (BadLocationException e) {
- bWasException = true;
+ bWasException = true;
}
if (isHarmony()) {
assertTrue(bWasException);
}
-
bWasException = false;
try {
dh.changeHighlight(obj1, 8, 1);
} catch (BadLocationException e) {
- bWasException = true;
+ bWasException = true;
}
if (isHarmony()) {
assertTrue(bWasException);
@@ -256,7 +238,6 @@
}
public void testRemoveHighlight() throws Exception {
-
try {
obj1 = dh.addHighlight(1, 5, lpnt);
} catch (BadLocationException e) {
@@ -264,7 +245,6 @@
s = e.getMessage();
}
assertFalse("Unexpected exception: " + s, bWasException);
-
try {
obj2 = dh.addHighlight(3, 7, lpnt);
} catch (BadLocationException e) {
@@ -272,25 +252,20 @@
s = e.getMessage();
}
assertFalse("Unexpected exception: " + s, bWasException);
-
dh.removeHighlight(obj2);
assertEquals(1, dh.getHighlights().length);
assertEqualsHighlight(dh.getHighlights()[0], 1, 5, lpnt);
dh.removeHighlight(obj1);
assertEquals(0, dh.getHighlights().length);
-
}
public void testSetGetDrawsLayeredHighlights() throws Exception {
assertTrue(dh.getDrawsLayeredHighlights());
-
dh.setDrawsLayeredHighlights(false);
-
assertFalse(dh.getDrawsLayeredHighlights());
}
public void testRemoveAllHighlights() throws Exception {
-
try {
dh.addHighlight(0, 1, lpnt);
dh.addHighlight(0, 4, lpnt);
@@ -299,21 +274,16 @@
bWasException = true;
s = e.getMessage();
}
-
assertFalse("Unexpected exception: " + s, bWasException);
-
assertEquals(3, dh.getHighlights().length);
dh.removeAllHighlights();
assertEquals(0, dh.getHighlights().length);
-
}
public void testGetHighlights() throws Exception {
final int N = 50;
final int M = 25;
-
Object[] obj = new Object[N];
-
for (int i = 0; i < N; i++) {
try {
obj[i] = dh.addHighlight(i, i + 1, lpnt);
@@ -323,11 +293,9 @@
}
assertFalse("Unexpected exception: " + s, bWasException);
}
-
for (int i = 0; i < N; i = i + 2) {
dh.removeHighlight(obj[i]);
}
-
for (int i = M; i < N; i++) {
try {
dh.addHighlight(i + 12000, i + 12100, lpnt);
@@ -339,15 +307,10 @@
}
Highlighter.Highlight highlights[] = dh.getHighlights();
for (int i = 0; i < M; i++) {
- assertEqualsHighlight(highlights[i], 2 * i + 1,
- 2 * (i + 1), lpnt);
+ assertEqualsHighlight(highlights[i], 2 * i + 1, 2 * (i + 1), lpnt);
}
-
for (int i = M; i < N; i++) {
- assertEqualsHighlight(highlights[i], i + 12000, i + 12100,
- lpnt);
-
+ assertEqualsHighlight(highlights[i], i + 12000, i + 12100, lpnt);
}
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultHighlighter_DefaultHighlightPainterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultHighlighter_DefaultHighlightPainterTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultHighlighter_DefaultHighlightPainterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultHighlighter_DefaultHighlightPainterTest.java Sun Nov 26 12:15:43 2006
@@ -26,45 +26,63 @@
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Shape;
-
import javax.swing.JFrame;
import javax.swing.JTextArea;
-import javax.swing.SwingUtilities;
import javax.swing.SwingWaitTestCase;
-
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
public class DefaultHighlighter_DefaultHighlightPainterTest extends TestCase {
JTextArea jta;
+
JFrame jf;
+
DefaultHighlighter dh;
+
AssertionFailedError[] afe;
+
DefaultHighlighter.DefaultHighlightPainter lp;
+
boolean bWasException;
+
String s = null;
+
int i = 0;
+
DefPainter dp;
+
String str;
+
Rectangle rectangle;
+
int pos0;
+
int pos1;
+
String sRTL = new String("\u05DC");
- String sLTR = new String("\u0061");
+ String sLTR = new String("\u0061");
class DefPainter extends DefaultHighlighter.DefaultHighlightPainter {
Graphics graphics;
+
int i0;
+
int i1;
+
Shape shape;
+
JTextComponent jtc;
+
View view;
+
DefPainter(final Color c) {
- super(c);
+ super(c);
}
- public Shape paintLayer(final Graphics g, final int p0, final int p1, final Shape sh, final JTextComponent jt, final View v) {
+ @Override
+ public Shape paintLayer(final Graphics g, final int p0, final int p1, final Shape sh,
+ final JTextComponent jt, final View v) {
graphics = g;
i0 = p0;
i1 = p1;
@@ -72,16 +90,17 @@
jtc = jt;
view = v;
return super.paintLayer(g, p0, p1, sh, jt, v);
-
}
+
public Shape paintAgain() {
- return paintLayer(graphics,i0,i1,shape,jtc,view);
+ return paintLayer(graphics, i0, i1, shape, jtc, view);
}
}
/*
* @see TestCase#setUp()
*/
+ @Override
protected void setUp() throws Exception {
jta = new JTextArea();
jf = new JFrame();
@@ -93,8 +112,8 @@
s = null;
jta.setHighlighter(dh);
jf.getContentPane().add(jta);
- jf.setLocation(200,300);
- jf.setSize(200,300);
+ jf.setLocation(200, 300);
+ jf.setSize(200, 300);
jf.setVisible(true);
SwingWaitTestCase.isRealized(jf);
super.setUp();
@@ -103,120 +122,65 @@
/*
* @see TestCase#tearDown()
*/
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
}
- void throwEx(final AssertionFailedError[] e){
- for (int i=0; i < e.length; i++)
- if (e[i] != null ) throw e[i];
+ void throwEx(final AssertionFailedError[] e) {
+ for (int i = 0; i < e.length; i++) {
+ if (e[i] != null) {
+ throw e[i];
+ }
+ }
}
public void testDefaultHighlightPainter() {
assertNotNull(lp);
- assertEquals(Color.red,lp.getColor());
+ assertEquals(Color.red, lp.getColor());
lp = new DefaultHighlighter.DefaultHighlightPainter(null);
assertNotNull(lp);
assertNull(lp.getColor());
}
- private String incString(final String s, final int i ){
- String str = s;
- for(int j =0; j < i ; j++){
- str = str + s;
- }
- return str;
- }
-
- public Shape getShape(final int p0, final int p1, final Shape shape,final View view) {
+ public Shape getShape(final int p0, final int p1, final Shape shape, final View view) {
Rectangle r = null;
Rectangle shapeBounds = shape.getBounds();
-
try {
- r = (Rectangle) view.modelToView(Math.min(p0, p1),
- Position.Bias.Forward, Math.max(p0, p1),
- Position.Bias.Backward, shapeBounds);
- } catch (BadLocationException e) {}
-
- if (r == null)
+ r = (Rectangle) view.modelToView(Math.min(p0, p1), Position.Bias.Forward, Math.max(
+ p0, p1), Position.Bias.Backward, shapeBounds);
+ } catch (BadLocationException e) {
+ }
+ if (r == null) {
return null;
+ }
return r;
}
-
- private void paintCase(final String string, final int p0, final int p1,final Rectangle r) throws Exception{
- str = string;
- pos0 = p0;
- pos1 = p1;
- rectangle = r;
- Runnable test1 = new Runnable() {
- public void run() {
- jta.setText(str);
- try {
- jta.getHighlighter().addHighlight(pos0,pos1,dp);
- } catch(BadLocationException e){
- bWasException = true;
- s = e.getMessage();
- }
- try {
- assertFalse("Unexpected exception: " + s, bWasException);
- } catch (AssertionFailedError e) {
- afe[i] = e;
- i++;
- }
-
- }
- };
- SwingUtilities.invokeAndWait(test1);
- SwingWaitTestCase.isRealized(jf);
-
- Runnable test2 = new Runnable() {
- public void run() {
- try {
- assertEquals(getShape(dp.i0,dp.i1,dp.shape,dp.view),dp.paintAgain());
- }catch(AssertionFailedError e){
- afe[i] = e;
- i++;
- }
-
- }
- };
- SwingUtilities.invokeAndWait(test2);
- Runnable test3 = new Runnable() {
- public void run() {
- jta.getHighlighter().removeAllHighlights();
- }
- };
- SwingUtilities.invokeAndWait(test3);
-
- }
-
-
/* hard link to coordinates
- public void testPaintLayer() throws Exception{
- String s1;
- String s2;
- paintCase("JTextArea",5,7,new Rectangle(28,0,12,16));
- paintCase(incString(sLTR,4) + incString(sRTL,4),3,4,
- new Rectangle(86,0,8,15));
- paintCase(incString(sLTR,4) + "\n" + incString(sRTL,4),3,4,
- new Rectangle(21,0,8,15));
- paintCase(sLTR + sRTL + "\n" + "\n" + sLTR + sRTL + sLTR,2,4,
- new Rectangle(0,15,1,15));
- paintCase("JTex\nArea for D\n\n\nefaultHighlighter testing",15,20,
- new Rectangle(0,60,11,15));
- s1 = incString(sLTR,3);
- s2 = incString(sRTL,1);
- s2 = s2 + "\n" + s2;
- paintCase(s1 + s2 + s1 + s2,15,16,new Rectangle(52,15,1,15));
- paintCase(s1 + s2 + s1 + s2,4,7,new Rectangle(40,0,1,15));
- paintCase(s1 + s2 + s1 + incString(sLTR,1) + "\n" + incString(sLTR,1),
- 15,16,new Rectangle(54,15,1,15));
- paintCase(s1 + s2 + s1 + incString(sLTR,1) + "\n" + incString(sLTR,1),
- 2,5,new Rectangle(46,0,7,15));
-
- throwEx(afe);
- }
- */
+ public void testPaintLayer() throws Exception{
+ String s1;
+ String s2;
+ paintCase("JTextArea",5,7,new Rectangle(28,0,12,16));
+ paintCase(incString(sLTR,4) + incString(sRTL,4),3,4,
+ new Rectangle(86,0,8,15));
+ paintCase(incString(sLTR,4) + "\n" + incString(sRTL,4),3,4,
+ new Rectangle(21,0,8,15));
+ paintCase(sLTR + sRTL + "\n" + "\n" + sLTR + sRTL + sLTR,2,4,
+ new Rectangle(0,15,1,15));
+ paintCase("JTex\nArea for D\n\n\nefaultHighlighter testing",15,20,
+ new Rectangle(0,60,11,15));
+ s1 = incString(sLTR,3);
+ s2 = incString(sRTL,1);
+ s2 = s2 + "\n" + s2;
+ paintCase(s1 + s2 + s1 + s2,15,16,new Rectangle(52,15,1,15));
+ paintCase(s1 + s2 + s1 + s2,4,7,new Rectangle(40,0,1,15));
+ paintCase(s1 + s2 + s1 + incString(sLTR,1) + "\n" + incString(sLTR,1),
+ 15,16,new Rectangle(54,15,1,15));
+ paintCase(s1 + s2 + s1 + incString(sLTR,1) + "\n" + incString(sLTR,1),
+ 2,5,new Rectangle(46,0,7,15));
+ throwEx(afe);
+ }
+ */
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocumentRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocumentRTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocumentRTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocumentRTest.java Sun Nov 26 12:15:43 2006
@@ -30,14 +30,21 @@
public class DefaultStyledDocumentRTest extends BasicSwingTestCase {
private static final String ELEMENT_NAME = AbstractDocument.ElementNameAttribute;
+
private DefaultStyledDocument doc;
+
private Element root;
+
private Element paragraph;
+
private Element child;
+
private int insertOffset = 5;
+
private MutableAttributeSet attrs;
private ElementBuffer buf;
+
private ElementSpec[] specs;
/**
@@ -47,16 +54,13 @@
public void testIconElement() throws Exception {
attrs.addAttribute(ELEMENT_NAME, "icon");
doc.insertString(insertOffset, " ", attrs);
-
assertEquals(3, paragraph.getElementCount());
child = paragraph.getElement(0);
assertEquals(AbstractDocument.ContentElementName, child.getName());
-
child = paragraph.getElement(1);
assertEquals("icon", child.getName());
assertEquals(insertOffset, child.getStartOffset());
assertEquals(insertOffset + 1, child.getEndOffset());
-
child = paragraph.getElement(2);
assertEquals(AbstractDocument.ContentElementName, child.getName());
}
@@ -68,16 +72,13 @@
public void testIconElementTwoSpaces() throws Exception {
attrs.addAttribute(ELEMENT_NAME, "icon");
doc.insertString(insertOffset, " ", attrs);
-
assertEquals(3, paragraph.getElementCount());
child = paragraph.getElement(0);
assertEquals(AbstractDocument.ContentElementName, child.getName());
-
child = paragraph.getElement(1);
assertEquals("icon", child.getName());
assertEquals(insertOffset, child.getStartOffset());
assertEquals(insertOffset + 2, child.getEndOffset());
-
child = paragraph.getElement(2);
assertEquals(AbstractDocument.ContentElementName, child.getName());
}
@@ -89,17 +90,14 @@
public void testIconElementNotSpaces() throws Exception {
attrs.addAttribute(ELEMENT_NAME, "icon");
doc.insertString(insertOffset, "ab", attrs);
-
assertEquals(3, paragraph.getElementCount());
child = paragraph.getElement(0);
assertEquals(AbstractDocument.ContentElementName, child.getName());
-
child = paragraph.getElement(1);
assertEquals("icon", child.getName());
assertEquals(insertOffset, child.getStartOffset());
assertEquals(insertOffset + 2, child.getEndOffset());
assertEquals("ab", doc.getText(insertOffset, 2));
-
child = paragraph.getElement(2);
assertEquals(AbstractDocument.ContentElementName, child.getName());
}
@@ -111,17 +109,14 @@
public void testComponentElement() throws Exception {
attrs.addAttribute(ELEMENT_NAME, "component");
doc.insertString(insertOffset, "ab", attrs);
-
assertEquals(3, paragraph.getElementCount());
child = paragraph.getElement(0);
assertEquals(AbstractDocument.ContentElementName, child.getName());
-
child = paragraph.getElement(1);
assertEquals("component", child.getName());
assertEquals(insertOffset, child.getStartOffset());
assertEquals(insertOffset + 2, child.getEndOffset());
assertEquals("ab", doc.getText(insertOffset, 2));
-
child = paragraph.getElement(2);
assertEquals(AbstractDocument.ContentElementName, child.getName());
}
@@ -130,183 +125,133 @@
initStructure();
attrs.addAttribute(ELEMENT_NAME, "content");
doc.insertString(1, "\n", attrs);
-
assertEquals(7, specs.length);
- assertSpec(specs[0], ElementSpec.EndTagType,
- ElementSpec.OriginateDirection, 0, 0);
- assertSpec(specs[1], ElementSpec.EndTagType,
- ElementSpec.OriginateDirection, 0, 0);
- assertSpec(specs[2], ElementSpec.StartTagType,
- ElementSpec.JoinNextDirection, 0, 0);
- assertSpec(specs[3], ElementSpec.StartTagType,
- ElementSpec.OriginateDirection, 0, 0);
- assertSpec(specs[4], ElementSpec.ContentType,
- ElementSpec.OriginateDirection, 0, 1);
- assertSpec(specs[5], ElementSpec.EndTagType,
- ElementSpec.OriginateDirection, 0, 0);
- assertSpec(specs[6], ElementSpec.StartTagType,
- ElementSpec.JoinNextDirection, 0, 0);
+ assertSpec(specs[0], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
+ assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
+ assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinNextDirection, 0, 0);
+ assertSpec(specs[3], ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, 0);
+ assertSpec(specs[4], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 1);
+ assertSpec(specs[5], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
+ assertSpec(specs[6], ElementSpec.StartTagType, ElementSpec.JoinNextDirection, 0, 0);
}
public void testDeepTreeInsertString02() throws Exception {
initStructure();
attrs.addAttribute(ELEMENT_NAME, "content");
doc.insertString(1, "^", attrs);
-
assertEquals(5, specs.length);
- assertSpec(specs[0], ElementSpec.EndTagType,
- ElementSpec.OriginateDirection, 0, 0);
- assertSpec(specs[1], ElementSpec.EndTagType,
- ElementSpec.OriginateDirection, 0, 0);
- assertSpec(specs[2], ElementSpec.StartTagType,
- ElementSpec.JoinNextDirection, 0, 0);
- assertSpec(specs[3], ElementSpec.StartTagType,
- ElementSpec.JoinNextDirection, 0, 0);
- assertSpec(specs[4], ElementSpec.ContentType,
- ElementSpec.OriginateDirection, 0, 1);
+ assertSpec(specs[0], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
+ assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
+ assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinNextDirection, 0, 0);
+ assertSpec(specs[3], ElementSpec.StartTagType, ElementSpec.JoinNextDirection, 0, 0);
+ assertSpec(specs[4], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 1);
}
-
public void testDeepTreeInsert01() throws Exception {
initStructure();
ElementSpec[] specs = {
- new ElementSpec(null, ElementSpec.EndTagType), // 0
- new ElementSpec(null, ElementSpec.EndTagType), // 1
- new ElementSpec(null, ElementSpec.StartTagType), // 2
- new ElementSpec(null, ElementSpec.StartTagType), // 3
- new ElementSpec(null, ElementSpec.ContentType, // 4
- "\n".toCharArray(), 0, 1),
- new ElementSpec(null, ElementSpec.EndTagType), // 5
- new ElementSpec(null, ElementSpec.StartTagType), // 6
+ new ElementSpec(null, ElementSpec.EndTagType), // 0
+ new ElementSpec(null, ElementSpec.EndTagType), // 1
+ new ElementSpec(null, ElementSpec.StartTagType), // 2
+ new ElementSpec(null, ElementSpec.StartTagType), // 3
+ new ElementSpec(null, ElementSpec.ContentType, // 4
+ "\n".toCharArray(), 0, 1),
+ new ElementSpec(null, ElementSpec.EndTagType), // 5
+ new ElementSpec(null, ElementSpec.StartTagType), // 6
};
specs[2].setDirection(ElementSpec.JoinNextDirection);
specs[6].setDirection(ElementSpec.JoinNextDirection);
-
doc.insert(1, specs);
-
final Element html = doc.getDefaultRootElement();
assertEquals(2, html.getElementCount());
-
final Element head = html.getElement(0);
assertEquals(1, head.getElementCount());
-
Element p = head.getElement(0);
- assertChildren(p, new int[] {0, 1});
-
+ assertChildren(p, new int[] { 0, 1 });
final Element body = html.getElement(1);
assertEquals(2, body.getElementCount());
-
p = body.getElement(0);
assertEquals("paragraph", p.getName());
- assertChildren(p, new int[] {1, 2});
-
+ assertChildren(p, new int[] { 1, 2 });
p = body.getElement(1);
assertEquals("p1", p.getName());
- assertChildren(p, new int[] {2, 6, 6, 7});
+ assertChildren(p, new int[] { 2, 6, 6, 7 });
}
public void testDeepTreeInsert02() throws Exception {
initStructure();
- ElementSpec[] specs = {
- new ElementSpec(null, ElementSpec.EndTagType), // 0
- new ElementSpec(null, ElementSpec.EndTagType), // 1
- new ElementSpec(null, ElementSpec.StartTagType), // 2
- new ElementSpec(null, ElementSpec.StartTagType), // 3
- new ElementSpec(null, ElementSpec.ContentType, // 4
- "^".toCharArray(), 0, 1),
- };
+ ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType), // 0
+ new ElementSpec(null, ElementSpec.EndTagType), // 1
+ new ElementSpec(null, ElementSpec.StartTagType), // 2
+ new ElementSpec(null, ElementSpec.StartTagType), // 3
+ new ElementSpec(null, ElementSpec.ContentType, // 4
+ "^".toCharArray(), 0, 1), };
specs[2].setDirection(ElementSpec.JoinNextDirection);
specs[3].setDirection(ElementSpec.JoinNextDirection);
-
doc.insert(1, specs);
-
final Element html = doc.getDefaultRootElement();
assertEquals(2, html.getElementCount());
-
final Element head = html.getElement(0);
assertEquals(1, head.getElementCount());
-
Element p = head.getElement(0);
- assertChildren(p, new int[] {0, 1});
-
+ assertChildren(p, new int[] { 0, 1 });
final Element body = html.getElement(1);
assertEquals(1, body.getElementCount());
-
p = body.getElement(0);
assertEquals("p1", p.getName());
- assertChildren(p, new int[] {1, 2, 2, 6, 6, 7});
+ assertChildren(p, new int[] { 1, 2, 2, 6, 6, 7 });
}
public void testDeepTreeInsertSpecs() throws Exception {
initStructure();
ElementSpec[] specs = {
- new ElementSpec(null, ElementSpec.ContentType,
- "\n".toCharArray(), 0, 1),
- new ElementSpec(null, ElementSpec.EndTagType),
- new ElementSpec(null, ElementSpec.EndTagType),
- };
+ new ElementSpec(null, ElementSpec.ContentType, "\n".toCharArray(), 0, 1),
+ new ElementSpec(null, ElementSpec.EndTagType),
+ new ElementSpec(null, ElementSpec.EndTagType), };
doc.insert(0, specs);
-
final Element html = doc.getDefaultRootElement();
assertEquals(2, html.getElementCount());
-
final Element head = html.getElement(0);
assertEquals(1, head.getElementCount());
-
Element p = head.getElement(0);
- assertChildren(p, new int[] {0, 1, 1, 2});
+ assertChildren(p, new int[] { 0, 1, 1, 2 });
assertEquals("\n\n", doc.getText(0, 2));
-
final Element body = html.getElement(1);
assertEquals(1, body.getElementCount());
-
p = body.getElement(0);
assertEquals("p1", p.getName());
- assertChildren(p, new int[] {2, 6, 6, 7});
+ assertChildren(p, new int[] { 2, 6, 6, 7 });
}
public void testHTMLInsert() throws Exception {
createEmptyHTMLStructure();
doc.insertString(0, "0000", DefStyledDoc_Helpers.bold);
- ElementSpec[] specs = {
- new ElementSpec(null, ElementSpec.EndTagType),
- new ElementSpec(null, ElementSpec.ContentType,
- "^^^^".toCharArray(), 0, 4),
- };
+ ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
+ new ElementSpec(null, ElementSpec.ContentType, "^^^^".toCharArray(), 0, 4), };
doc.insert(0, specs);
-
final Element html = doc.getDefaultRootElement();
assertEquals(1, html.getElementCount());
-
final Element body = html.getElement(0);
assertEquals(2, body.getElementCount());
-
Element child = body.getElement(0);
assertEquals("content", child.getName());
assertTrue(child.isLeaf());
-
child = body.getElement(1);
assertEquals("p", child.getName());
- assertChildren(child, new int[] {4, 8, 8, 9});
+ assertChildren(child, new int[] { 4, 8, 8, 9 });
}
public void testCreate01() throws Exception {
- ElementSpec[] specs = {
- new ElementSpec(null, ElementSpec.StartTagType),
- new ElementSpec(null, ElementSpec.ContentType,
- "^".toCharArray(), 0, 1),
- new ElementSpec(null, ElementSpec.EndTagType),
- };
+ ElementSpec[] specs = { new ElementSpec(null, ElementSpec.StartTagType),
+ new ElementSpec(null, ElementSpec.ContentType, "^".toCharArray(), 0, 1),
+ new ElementSpec(null, ElementSpec.EndTagType), };
doc.create(specs);
-
root = doc.getDefaultRootElement();
assertEquals(2, root.getElementCount());
-
Element child = root.getElement(0);
assertTrue(child.isLeaf());
assertEquals(0, child.getStartOffset());
assertEquals(1, child.getEndOffset());
-
child = root.getElement(1);
assertFalse(child.isLeaf());
assertEquals(1, child.getStartOffset());
@@ -316,32 +261,24 @@
}
public void testCreate02() throws Exception {
- ElementSpec[] specs = {
- new ElementSpec(null, ElementSpec.StartTagType),
- new ElementSpec(null, ElementSpec.StartTagType),
- new ElementSpec(null, ElementSpec.StartTagType),
- new ElementSpec(null, ElementSpec.ContentType,
- "^".toCharArray(), 0, 1),
- new ElementSpec(null, ElementSpec.EndTagType),
- new ElementSpec(null, ElementSpec.EndTagType),
- };
+ ElementSpec[] specs = { new ElementSpec(null, ElementSpec.StartTagType),
+ new ElementSpec(null, ElementSpec.StartTagType),
+ new ElementSpec(null, ElementSpec.StartTagType),
+ new ElementSpec(null, ElementSpec.ContentType, "^".toCharArray(), 0, 1),
+ new ElementSpec(null, ElementSpec.EndTagType),
+ new ElementSpec(null, ElementSpec.EndTagType), };
doc.create(specs);
-
root = doc.getDefaultRootElement();
assertEquals(2, root.getElementCount());
-
Element child = root.getElement(0);
assertFalse(child.isLeaf());
assertEquals(0, child.getStartOffset());
assertEquals(1, child.getEndOffset());
assertEquals(1, child.getElementCount());
-
child = child.getElement(0);
assertFalse(child.isLeaf());
assertEquals(1, child.getElementCount());
assertTrue(child.getElement(0).isLeaf());
-
-
child = root.getElement(1);
assertFalse(child.isLeaf());
assertEquals(1, child.getStartOffset());
@@ -360,8 +297,11 @@
public void testInsertString01() throws BadLocationException {
doc.remove(0, doc.getLength());
doc.buffer = new ElementBufferWithLogging(doc, root) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
public void insert(int offset, int length, ElementSpec[] spec,
- DefaultDocumentEvent event) {
+ DefaultDocumentEvent event) {
specs = spec;
super.insert(offset, length, spec, event);
}
@@ -369,36 +309,24 @@
StyleConstants.setBold(attrs, true);
doc.insertString(0, "b", attrs);
doc.insertString(0, "\n", null);
-
doc.insertString(1, "1", null);
-
- ElementSpec[] ess = {
- new ElementSpec(null, ElementSpec.EndTagType),
- new ElementSpec(null, ElementSpec.StartTagType),
- new ElementSpec(null, ElementSpec.ContentType, 1)
- };
+ ElementSpec[] ess = { new ElementSpec(null, ElementSpec.EndTagType),
+ new ElementSpec(null, ElementSpec.StartTagType),
+ new ElementSpec(null, ElementSpec.ContentType, 1) };
ess[1].setDirection(ElementSpec.JoinNextDirection);
-
assertEquals(ess.length, specs.length);
for (int i = 0; i < ess.length; i++) {
assertEquals("@ " + i, ess[i].getType(), specs[i].getType());
- assertEquals("@ " + i, ess[i].getDirection(),
- specs[i].getDirection());
+ assertEquals("@ " + i, ess[i].getDirection(), specs[i].getDirection());
}
-
- int[][] offsets = {
- {0, 1},
- {1, 2, 2, 3, 3, 4}
- };
-
+ int[][] offsets = { { 0, 1 }, { 1, 2, 2, 3, 3, 4 } };
for (int i = 0; i < root.getElementCount(); i++) {
Element paragraph = root.getElement(i);
for (int j = 0, oi = 0; j < paragraph.getElementCount(); j++) {
Element content = paragraph.getElement(j);
- assertEquals("root[" + i + "].start",
- offsets[i][oi++], content.getStartOffset());
- assertEquals("root[" + i + "].end",
- offsets[i][oi++], content.getEndOffset());
+ assertEquals("root[" + i + "].start", offsets[i][oi++], content
+ .getStartOffset());
+ assertEquals("root[" + i + "].end", offsets[i][oi++], content.getEndOffset());
if (i == 1 && j == 1) {
assertTrue(StyleConstants.isBold(content.getAttributes()));
} else {
@@ -417,8 +345,11 @@
public void testInsertString02() throws BadLocationException {
doc.remove(0, doc.getLength());
doc.buffer = new ElementBufferWithLogging(doc, root) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
public void insert(int offset, int length, ElementSpec[] spec,
- DefaultDocumentEvent event) {
+ DefaultDocumentEvent event) {
specs = spec;
super.insert(offset, length, spec, event);
}
@@ -427,27 +358,18 @@
doc.insertString(0, "b", attrs);
doc.insertString(0, "\n", null);
doc.insertString(1, "1", null);
-
doc.insertString(2, "1", null);
-
assertEquals(1, specs.length);
assertEquals(ElementSpec.ContentType, specs[0].getType());
- assertEquals(ElementSpec.JoinPreviousDirection,
- specs[0].getDirection());
-
- int[][] offsets = {
- {0, 1},
- {1, 3, 3, 4, 4, 5}
- };
-
+ assertEquals(ElementSpec.JoinPreviousDirection, specs[0].getDirection());
+ int[][] offsets = { { 0, 1 }, { 1, 3, 3, 4, 4, 5 } };
for (int i = 0; i < root.getElementCount(); i++) {
Element paragraph = root.getElement(i);
for (int j = 0, oi = 0; j < paragraph.getElementCount(); j++) {
Element content = paragraph.getElement(j);
- assertEquals("root[" + i + "].start",
- offsets[i][oi++], content.getStartOffset());
- assertEquals("root[" + i + "].end",
- offsets[i][oi++], content.getEndOffset());
+ assertEquals("root[" + i + "].start", offsets[i][oi++], content
+ .getStartOffset());
+ assertEquals("root[" + i + "].end", offsets[i][oi++], content.getEndOffset());
if (i == 1 && j == 1) {
assertTrue(StyleConstants.isBold(content.getAttributes()));
} else {
@@ -455,8 +377,9 @@
}
}
}
- }
+ }
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
@@ -470,43 +393,39 @@
doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
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, specs = spec, event);
}
};
doc.buffer = buf;
-
doc.writeLock();
try {
doc.getContent().insertString(0, "\n0000");
-
- final BranchElement html = (BranchElement)root;
+ final BranchElement html = (BranchElement) root;
html.addAttribute(ELEMENT_NAME, "html");
-
final BranchElement head = createBranch(html);
head.addAttribute(ELEMENT_NAME, "head");
-
final BranchElement implied = createBranch(head);
implied.addAttribute(ELEMENT_NAME, "p-implied");
final LeafElement content0 = createLeaf(implied, 0, 1);
content0.addAttribute(ELEMENT_NAME, "head-content");
-
-
final BranchElement body = createBranch(html);
body.addAttribute(ELEMENT_NAME, "body");
-
final BranchElement p1 = createBranch(body);
p1.addAttribute(ELEMENT_NAME, "p1");
final LeafElement content1 = createLeaf(p1, 1, 5);
content1.addAttribute(ELEMENT_NAME, "leaf1");
final LeafElement content2 = createLeaf(p1, 5, 6);
content2.addAttribute(ELEMENT_NAME, "leaf2");
- implied.replace(0, 0, new Element[] {content0});
- p1.replace(0, 0, new Element[] {content1, content2});
- head.replace(0, 0, new Element[] {implied});
- body.replace(0, 0, new Element[] {p1});
- html.replace(0, 1, new Element[] {head, body});
+ implied.replace(0, 0, new Element[] { content0 });
+ p1.replace(0, 0, new Element[] { content1, content2 });
+ head.replace(0, 0, new Element[] { implied });
+ body.replace(0, 0, new Element[] { p1 });
+ html.replace(0, 1, new Element[] { head, body });
} finally {
doc.writeUnlock();
}
@@ -516,51 +435,47 @@
doc = new DefStyledDoc_Helpers.DefStyledDocWithLogging();
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, specs = spec, event);
}
};
doc.buffer = buf;
-
doc.writeLock();
try {
- final BranchElement html = (BranchElement)root;
+ final BranchElement html = (BranchElement) root;
html.addAttribute(ELEMENT_NAME, "html");
-
final BranchElement body = createBranch(html);
body.addAttribute(ELEMENT_NAME, "body");
-
final BranchElement p = createBranch(body);
p.addAttribute(ELEMENT_NAME, "p");
final LeafElement content = createLeaf(p, 0, 1);
content.addAttribute(ELEMENT_NAME, "leaf1");
- p.replace(0, 0, new Element[] {content});
- body.replace(0, 0, new Element[] {p});
- html.replace(0, 1, new Element[] {body});
+ p.replace(0, 0, new Element[] { content });
+ body.replace(0, 0, new Element[] { p });
+ html.replace(0, 1, new Element[] { body });
} finally {
doc.writeUnlock();
}
}
private BranchElement createBranch(final Element parent) {
- return (BranchElement)doc.createBranchElement(parent, null);
+ return (BranchElement) doc.createBranchElement(parent, null);
}
- private LeafElement createLeaf(final Element parent,
- final int start, final int end) {
- return (LeafElement)doc.createLeafElement(parent, null, start, end);
+ private LeafElement createLeaf(final Element parent, final int start, final int end) {
+ return (LeafElement) doc.createLeafElement(parent, null, start, end);
}
-
- private static void assertChildren(final Element element,
- final int[] offsets) {
+ private static void assertChildren(final Element element, final int[] offsets) {
DefStyledDoc_Helpers.assertChildren(element, offsets);
}
private static void assertSpec(final ElementSpec spec, final short type,
- final short direction, final int offset,
- final int length) {
+ final short direction, final int offset, final int length) {
DefStyledDoc_Helpers.assertSpec(spec, type, direction, offset, length);
}
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocumentTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocumentTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocumentTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocumentTest.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$
@@ -33,6 +32,7 @@
public class DefaultStyledDocumentTest extends BasicSwingTestCase {
protected DefaultStyledDocument doc;
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new DefaultStyledDocument(new StyleContext());
@@ -45,7 +45,9 @@
public void testAddRemoveDocumentListener() throws BadLocationException {
final class Listener implements DocumentListener {
private boolean insert;
+
private boolean remove;
+
private boolean change;
public void insertUpdate(DocumentEvent e) {
@@ -60,53 +62,38 @@
change = true;
}
- public void check(final boolean insert, final boolean remove,
- final boolean change) {
+ public void check(final boolean insert, final boolean remove, final boolean change) {
assertEquals("Insert", insert, this.insert);
assertEquals("Remove", remove, this.remove);
assertEquals("Change", change, this.change);
-
this.insert = this.remove = this.change = false;
}
- };
+ }
+ ;
final Listener listener = new Listener();
final AttributeSet attrs = new SimpleAttributeSet();
- StyleConstants.setFontSize((MutableAttributeSet)attrs, 36);
-
+ StyleConstants.setFontSize((MutableAttributeSet) attrs, 36);
// The listener has not been added to the document yet
-
doc.insertString(0, "1", null);
listener.check(false, false, false);
-
doc.remove(0, 1);
listener.check(false, false, false);
-
doc.setCharacterAttributes(0, 1, attrs, false);
listener.check(false, false, false);
-
// The listener has been added to the document
-
doc.addDocumentListener(listener);
-
doc.insertString(0, "1", null);
listener.check(true, false, false);
-
doc.remove(0, 1);
listener.check(false, true, false);
-
doc.setCharacterAttributes(0, 1, attrs, false);
listener.check(false, false, true);
-
// The listener has been removed from the document
-
doc.removeDocumentListener(listener);
-
doc.insertString(0, "1", null);
listener.check(false, false, false);
-
doc.remove(0, 1);
listener.check(false, false, false);
-
doc.setCharacterAttributes(0, 1, attrs, false);
listener.check(false, false, false);
}
@@ -120,8 +107,8 @@
*/
public void testDefaultStyledDocument() {
doc = new DefaultStyledDocument();
- assertEquals(DefaultStyledDocument.BUFFER_SIZE_DEFAULT,
- ((GapContent)doc.getContent()).getArrayLength());
+ assertEquals(DefaultStyledDocument.BUFFER_SIZE_DEFAULT, ((GapContent) doc.getContent())
+ .getArrayLength());
}
/*
@@ -130,7 +117,7 @@
public void testDefaultStyledDocumentContentStyleContext() {
StyleContext styles = new StyleContext();
doc = new DefaultStyledDocument(new GapContent(10), styles);
- assertEquals(10, ((GapContent)doc.getContent()).getArrayLength());
+ assertEquals(10, ((GapContent) doc.getContent()).getArrayLength());
Element root = doc.getDefaultRootElement();
assertTrue(root instanceof SectionElement);
assertEquals(1, root.getElementCount());
@@ -138,10 +125,9 @@
assertTrue(child instanceof BranchElement);
assertEquals(1, child.getElementCount());
assertTrue(child.getElement(0) instanceof LeafElement);
-
assertSame(styles, doc.getAttributeContext());
- assertSame(styles.getStyle(StyleContext.DEFAULT_STYLE),
- child.getAttributes().getResolveParent());
+ assertSame(styles.getStyle(StyleContext.DEFAULT_STYLE), child.getAttributes()
+ .getResolveParent());
}
/*
@@ -151,15 +137,13 @@
StyleContext styles = new StyleContext();
doc = new DefaultStyledDocument(styles);
DefaultStyledDocument anotherDoc = new DefaultStyledDocument(styles);
- assertSame(doc.getAttributeContext(),
- anotherDoc.getAttributeContext());
+ assertSame(doc.getAttributeContext(), anotherDoc.getAttributeContext());
}
public void testCreateDefaultRoot() {
AbstractElement defRoot = doc.createDefaultRoot();
assertTrue(defRoot instanceof SectionElement);
assertEquals(0, defRoot.getAttributeCount());
-
assertEquals(1, defRoot.getElementCount());
assertTrue(defRoot.getElement(0) instanceof BranchElement);
}
@@ -176,13 +160,11 @@
assertNull(getNewLineProperty());
assertEquals(content, getText());
doc.remove(0, doc.getLength());
-
doc.putProperty(filterNewLinesProperty, Boolean.TRUE);
doc.insertString(0, content, null);
assertSame(Boolean.TRUE, getNewLineProperty());
assertEquals(content, getText());
doc.remove(0, doc.getLength());
-
doc.putProperty(filterNewLinesProperty, Boolean.FALSE);
doc.insertString(0, content, null);
assertSame(Boolean.FALSE, getNewLineProperty());
@@ -192,48 +174,34 @@
public void testSerializable() throws Exception {
final String text = "some sample text";
doc.insertString(0, text, DefStyledDoc_Helpers.bold);
-
- doc = (DefaultStyledDocument)BasicSwingTestCase.serializeObject(doc);
-
+ doc = (DefaultStyledDocument) BasicSwingTestCase.serializeObject(doc);
final Element root = doc.getDefaultRootElement();
assertEquals(1, root.getElementCount());
-
final Element paragraph = root.getElement(0);
assertEquals(2, paragraph.getElementCount());
-
final Element character = paragraph.getElement(0);
assertEquals(0, character.getStartOffset());
assertEquals(text.length(), character.getEndOffset());
- assertTrue(character.getAttributes()
- .isEqual(DefStyledDoc_Helpers.bold));
-
+ assertTrue(character.getAttributes().isEqual(DefStyledDoc_Helpers.bold));
assertEquals(text.length() + 1, paragraph.getEndOffset());
-
assertEquals(text, doc.getText(0, doc.getLength()));
-
// Check that ElementBuffer is also functional
doc.writeLock();
try {
- doc.buffer.change(2, 6,
- doc.new DefaultDocumentEvent(2, 6,
- EventType.CHANGE));
+ doc.buffer.change(2, 6, doc.new DefaultDocumentEvent(2, 6, EventType.CHANGE));
assertEquals(4, paragraph.getElementCount());
-
- doc.buffer.remove(2, 6,
- doc.new DefaultDocumentEvent(2, 6,
- EventType.REMOVE));
+ doc.buffer.remove(2, 6, doc.new DefaultDocumentEvent(2, 6, EventType.REMOVE));
assertEquals(3, paragraph.getElementCount());
} finally {
doc.writeUnlock();
}
-
doc.insertString(0, "1\n2\n3\n", null);
for (int i = 0; i < root.getElementCount(); i++) {
Element branch = root.getElement(i);
- assertEquals("root.children[" + i + "].attributes.count",
- 1, branch.getAttributes().getAttributeCount());
- assertNotNull("root.children[" + i + "].attributes.getResolver()",
- branch.getAttributes().getResolveParent());
+ assertEquals("root.children[" + i + "].attributes.count", 1, branch.getAttributes()
+ .getAttributeCount());
+ assertNotNull("root.children[" + i + "].attributes.getResolver()", branch
+ .getAttributes().getResolveParent());
}
}
@@ -244,16 +212,14 @@
private String getText() throws BadLocationException {
return doc.getText(0, doc.getLength());
}
-
/*
- These methods are not tested because they are tests by their side effects:
- insertUpdate prepares ElementSpecs and calls buffer.insert()
- removeUpdate has nothing to do except calling buffer.remove()
- public void testInsertUpdate() {
- }
-
- public void testRemoveUpdate() {
- }
- */
+ These methods are not tested because they are tests by their side effects:
+ insertUpdate prepares ElementSpecs and calls buffer.insert()
+ removeUpdate has nothing to do except calling buffer.remove()
+ public void testInsertUpdate() {
+ }
+ public void testRemoveUpdate() {
+ }
+ */
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_AttributeUndoableEditTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_AttributeUndoableEditTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_AttributeUndoableEditTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultStyledDocument_AttributeUndoableEditTest.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,27 +22,27 @@
import java.util.Iterator;
import java.util.List;
-
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.text.AbstractDocument.DefaultDocumentEvent;
import javax.swing.text.DefaultStyledDocument.AttributeUndoableEdit;
-
import junit.framework.TestCase;
/**
* Tests DefaultStyledDocument.AttributeUndoableEdit class
*
*/
-public class DefaultStyledDocument_AttributeUndoableEditTest extends TestCase
- implements UndoableEditListener {
-
+public class DefaultStyledDocument_AttributeUndoableEditTest extends TestCase implements
+ UndoableEditListener {
private AttributeUndoableEdit undoEdit;
+
private DefaultStyledDocument doc;
private static final AttributeSet italic = DefStyledDoc_Helpers.italic;
+
private static final AttributeSet bold = DefStyledDoc_Helpers.bold;
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new DefaultStyledDocument();
@@ -58,16 +57,13 @@
*/
public void testUndoRedoNoReplace() {
doc.setCharacterAttributes(2, 4, bold, false);
-
doc.writeLock();
try {
undoEdit.undo();
-
AttributeSet attrs = doc.getCharacterElement(4).getAttributes();
assertEquals(1, attrs.getAttributeCount());
assertFalse(attrs.containsAttributes(bold));
assertTrue(attrs.containsAttributes(italic));
-
undoEdit.redo();
attrs = doc.getCharacterElement(4).getAttributes();
assertEquals(2, attrs.getAttributeCount());
@@ -85,17 +81,13 @@
public void testUndoRedoItalicFalse() {
final MutableAttributeSet italicFalse = new SimpleAttributeSet();
StyleConstants.setItalic(italicFalse, false);
-
doc.setCharacterAttributes(2, 4, italicFalse, false);
-
doc.writeLock();
try {
undoEdit.undo();
-
AttributeSet attrs = doc.getCharacterElement(4).getAttributes();
assertEquals(1, attrs.getAttributeCount());
assertTrue(attrs.containsAttributes(italic));
-
undoEdit.redo();
attrs = doc.getCharacterElement(4).getAttributes();
assertEquals(1, attrs.getAttributeCount());
@@ -111,16 +103,13 @@
*/
public void testUndoRedoWithReplace() {
doc.setCharacterAttributes(2, 4, bold, true);
-
doc.writeLock();
try {
undoEdit.undo();
-
AttributeSet attrs = doc.getCharacterElement(4).getAttributes();
assertEquals(1, attrs.getAttributeCount());
assertFalse(attrs.containsAttributes(bold));
assertTrue(attrs.containsAttributes(italic));
-
undoEdit.redo();
attrs = doc.getCharacterElement(4).getAttributes();
assertEquals(1, attrs.getAttributeCount());
@@ -157,8 +146,7 @@
assertSame(attrs, undoEdit.newAttributes);
assertTrue(undoEdit.isReplacing);
assertEquals(1, undoEdit.copy.getAttributeCount());
- assertTrue(undoEdit.copy.containsAttribute(StyleConstants.BidiLevel,
- new Integer(0)));
+ assertTrue(undoEdit.copy.containsAttribute(StyleConstants.BidiLevel, new Integer(0)));
}
/**
@@ -168,13 +156,11 @@
*/
public void testChangeNoReplace() {
doc.setCharacterAttributes(2, 4, bold, false);
-
assertNotNull(undoEdit);
assertSame(doc.getCharacterElement(4), undoEdit.element);
assertTrue(undoEdit.newAttributes.isEqual(bold));
assertFalse(undoEdit.isReplacing);
assertTrue(undoEdit.copy.isEqual(italic));
-
AttributeSet attrs = doc.getCharacterElement(4).getAttributes();
assertEquals(2, attrs.getAttributeCount());
assertTrue(attrs.containsAttributes(bold));
@@ -188,13 +174,11 @@
*/
public void testChangeWithReplace() {
doc.setCharacterAttributes(2, 4, bold, true);
-
assertNotNull(undoEdit);
assertSame(doc.getCharacterElement(4), undoEdit.element);
assertTrue(undoEdit.newAttributes.isEqual(bold));
assertTrue(undoEdit.isReplacing);
assertTrue(undoEdit.copy.isEqual(italic));
-
AttributeSet attrs = doc.getCharacterElement(4).getAttributes();
assertEquals(1, attrs.getAttributeCount());
assertTrue(attrs.containsAttributes(bold));
@@ -202,15 +186,15 @@
}
public void undoableEditHappened(UndoableEditEvent e) {
- searchForAttributeUE((DefaultDocumentEvent)e.getEdit());
+ searchForAttributeUE((DefaultDocumentEvent) e.getEdit());
}
private void searchForAttributeUE(DefaultDocumentEvent e) {
- List edits = DefStyledDoc_Helpers.getEdits(e);
- for (Iterator i = edits.iterator(); i.hasNext();) {
+ List<?> edits = DefStyledDoc_Helpers.getEdits(e);
+ for (Iterator<?> i = edits.iterator(); i.hasNext();) {
Object edit = i.next();
if (edit instanceof AttributeUndoableEdit) {
- undoEdit = (AttributeUndoableEdit)edit;
+ undoEdit = (AttributeUndoableEdit) edit;
break;
}
}