* An Iterator over an array of Strings.
*/
public static class StringsIterator implements Iterator<String> {
- private String[] strings;
+ private String[] strings = {};
private int position = 0;
public StringsIterator(String[] strings) {
- if(strings != null) {
- this.strings = strings;
- } else {
- this.strings = new String[0];
+ if (strings != null) {
+ this.strings = strings.clone();
}
}
}
public String next() {
int ourPos = position++;
- if(ourPos >= strings.length)
+ if(ourPos >= strings.length) {
throw new ArrayIndexOutOfBoundsException(ourPos);
+ }
return strings[ourPos];
}
public void remove() {}
package org.apache.poi.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.nio.charset.Charset;
import org.apache.poi.util.StringUtil.StringsIterator;
-
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit test for StringUtil
- *
- * @author Marc Johnson (mjohnson at apache dot org
- * @author Glen Stampoultzis (glens at apache.org)
- * @author Sergei Kozello (sergeikozello at mail.ru)
*/
-public final class TestStringUtil extends TestCase {
+public class TestStringUtil {
/**
* test getFromUnicodeHigh for symbols with code below and more 127
*/
+ @Test
public void testGetFromUnicodeHighSymbolsWithCodesMoreThan127() {
byte[] test_data = new byte[]{0x22, 0x04,
0x35, 0x04,
StringUtil.getFromUnicodeLE( test_data ) );
}
+ @Test
public void testPutCompressedUnicode() {
byte[] output = new byte[100];
byte[] expected_output =
}
}
+ @Test
public void testPutUncompressedUnicode() {
byte[] output = new byte[100];
String input = "Hello World";
}
}
+ @Test
public void testStringsIterator() {
StringsIterator i;