You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/01/03 20:30:56 UTC
svn commit: r1649234 - in /poi/trunk/src/ooxml:
java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
Author: centic
Date: Sat Jan 3 19:30:56 2015
New Revision: 1649234
URL: http://svn.apache.org/r1649234
Log:
Improve information in exceptions thrown by XSSFRichTextString and improve unit tests
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=1649234&r1=1649233&r2=1649234&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Sat Jan 3 19:30:56 2015
@@ -135,9 +135,10 @@ public class XSSFRichTextString implemen
*/
public void applyFont(int startIndex, int endIndex, Font font) {
if (startIndex > endIndex)
- throw new IllegalArgumentException("Start index must be less than end index.");
+ throw new IllegalArgumentException("Start index must be less than end index, but had " + startIndex + " and " + endIndex);
if (startIndex < 0 || endIndex > length())
- throw new IllegalArgumentException("Start and end index not in range.");
+ throw new IllegalArgumentException("Start and end index not in range, but had " + startIndex + " and " + endIndex);
+
if (startIndex == endIndex)
return;
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java?rev=1649234&r1=1649233&r2=1649234&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java Sat Jan 3 19:30:56 2015
@@ -25,6 +25,7 @@ import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.model.StylesTable;
import org.junit.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
@@ -38,7 +39,6 @@ import org.openxmlformats.schemas.spread
public final class TestXSSFRichTextString extends TestCase {
public void testCreate() {
-
XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
assertEquals("Apache POI", rt.getString());
@@ -53,9 +53,14 @@ public final class TestXSSFRichTextStrin
assertEquals("Apache POI is cool stuff", rt.getString());
}
+ public void testEmpty() {
+ XSSFRichTextString rt = new XSSFRichTextString();
+ assertEquals(0, rt.getIndexOfFormattingRun(9999));
+ assertEquals(-1, rt.getLengthOfFormattingRun(9999));
+ assertNull(rt.getFontAtIndex(9999));
+ }
public void testApplyFont() {
-
XSSFRichTextString rt = new XSSFRichTextString();
rt.append("123");
rt.append("4567");
@@ -82,6 +87,65 @@ public final class TestXSSFRichTextStrin
assertEquals(7, rt.getIndexOfFormattingRun(3));
assertEquals(2, rt.getLengthOfFormattingRun(3));
assertEquals("89", rt.getCTRst().getRArray(3).getT());
+
+
+ assertEquals(-1, rt.getIndexOfFormattingRun(9999));
+ assertEquals(-1, rt.getLengthOfFormattingRun(9999));
+ assertNull(rt.getFontAtIndex(9999));
+ }
+
+ public void testApplyFontIndex() {
+ XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
+ rt.applyFont(0, 10, (short)1);
+
+ rt.applyFont((short)1);
+
+ assertNotNull(rt.getFontAtIndex(0));
+ }
+
+ public void testApplyFontWithStyles() {
+ XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
+
+ StylesTable tbl = new StylesTable();
+ rt.setStylesTableReference(tbl);
+
+ try {
+ rt.applyFont(0, 10, (short)1);
+ fail("Fails without styles in the table");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ tbl.putFont(new XSSFFont());
+ rt.applyFont(0, 10, (short)1);
+ rt.applyFont((short)1);
+ }
+
+ public void testApplyFontException() {
+ XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
+
+ rt.applyFont(0, 0, (short)1);
+
+ try {
+ rt.applyFont(11, 10, (short)1);
+ fail("Should catch Exception here");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("11"));
+ }
+
+ try {
+ rt.applyFont(-1, 10, (short)1);
+ fail("Should catch Exception here");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("-1"));
+ }
+
+ try {
+ rt.applyFont(0, 555, (short)1);
+ fail("Should catch Exception here");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("555"));
+ }
}
public void testClearFormatting() {
@@ -431,4 +495,13 @@ public final class TestXSSFRichTextStrin
assertNotNull(rt.getFontOfFormattingRun(2));
assertEquals(9, rt.getLengthOfFormattingRun(2));
}
+
+ public void testToString() {
+ XSSFRichTextString rt = new XSSFRichTextString("Apache POI");
+ assertNotNull(rt.toString());
+
+ // TODO: normally toString() should never return null, should we adjust this?
+ rt = new XSSFRichTextString();
+ assertNull(rt.toString());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org