aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org
diff options
context:
space:
mode:
authorJaven O'Neal <onealj@apache.org>2016-10-20 01:54:56 +0000
committerJaven O'Neal <onealj@apache.org>2016-10-20 01:54:56 +0000
commitf14210b101b707b4ce09d87a1d0720ac0c696caf (patch)
tree2d8144fdbf643e9deb5a98279e2e8a8200921c07 /src/testcases/org
parentecef10cb7b381f843e6d94ea97e91bcec385e2c8 (diff)
downloadpoi-f14210b101b707b4ce09d87a1d0720ac0c696caf.tar.gz
poi-f14210b101b707b4ce09d87a1d0720ac0c696caf.zip
Eclipse automated refactor/cleanup: convert for loops to for-each loops
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765736 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestWrite.java13
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/Util.java5
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java15
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java22
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java4
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java5
-rw-r--r--src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java5
-rw-r--r--src/testcases/org/apache/poi/util/TestByteField.java14
-rw-r--r--src/testcases/org/apache/poi/util/TestIntList.java5
-rw-r--r--src/testcases/org/apache/poi/util/TestIntegerField.java14
-rw-r--r--src/testcases/org/apache/poi/util/TestLongField.java14
-rw-r--r--src/testcases/org/apache/poi/util/TestShortField.java14
-rw-r--r--src/testcases/org/apache/poi/util/TestStringUtil.java4
16 files changed, 69 insertions, 81 deletions
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
index 1312cf8aa3..ffcaa3a799 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
@@ -699,11 +699,11 @@ public class TestWrite
return f.getName().startsWith("Test") && TestReadAllFiles.checkExclude(f);
}
});
- for (int i = 0; i < fileList.length; i++) {
+ for (final File file : fileList) {
try {
- testRecreate(fileList[i]);
+ testRecreate(file);
} catch (Exception e) {
- throw new IOException("While handling file " + fileList[i], e);
+ throw new IOException("While handling file " + file, e);
}
}
}
@@ -729,10 +729,9 @@ public class TestWrite
copy.deleteOnExit();
final OutputStream out = new FileOutputStream(copy);
final POIFSFileSystem poiFs = new POIFSFileSystem();
- for (int i = 0; i < psf1.length; i++)
- {
+ for (POIFile file : psf1) {
final InputStream in =
- new ByteArrayInputStream(psf1[i].getBytes());
+ new ByteArrayInputStream(file.getBytes());
final PropertySet psIn = PropertySetFactory.create(in);
final MutablePropertySet psOut = new MutablePropertySet(psIn);
final ByteArrayOutputStream psStream =
@@ -741,7 +740,7 @@ public class TestWrite
psStream.close();
final byte[] streamData = psStream.toByteArray();
poiFs.createDocument(new ByteArrayInputStream(streamData),
- psf1[i].getName());
+ file.getName());
poiFs.writeFilesystem(out);
}
poiFs.close();
diff --git a/src/testcases/org/apache/poi/hpsf/basic/Util.java b/src/testcases/org/apache/poi/hpsf/basic/Util.java
index 299f69797a..668b1858ad 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/Util.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/Util.java
@@ -28,7 +28,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@@ -252,8 +251,8 @@ final class Util {
{
final Properties p = System.getProperties();
final List<String> names = new LinkedList<String>();
- for (Iterator<String> i = p.stringPropertyNames().iterator(); i.hasNext();)
- names.add(i.next());
+ for (String name : p.stringPropertyNames())
+ names.add(name);
Collections.sort(names);
for (String name : names) {
String value = p.getProperty(name);
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
index c57eee387d..eaf4b52c11 100644
--- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
+++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
@@ -211,9 +211,9 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
// Check the numbers of the last seen columns
LastCellOfRowDummyRecord[] lrs = new LastCellOfRowDummyRecord[24];
int lrscount = 0;
- for(int i=0; i<r.length; i++) {
- if(r[i] instanceof LastCellOfRowDummyRecord) {
- lrs[lrscount] = (LastCellOfRowDummyRecord)r[i];
+ for (final Record rec : r) {
+ if(rec instanceof LastCellOfRowDummyRecord) {
+ lrs[lrscount] = (LastCellOfRowDummyRecord)rec;
lrscount++;
}
}
@@ -351,9 +351,9 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
readRecords("MRExtraLines.xls");
int rowCount=0;
- for(int i=0; i<r.length; i++) {
- if(r[i] instanceof LastCellOfRowDummyRecord) {
- LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) r[i];
+ for (Record rec : r) {
+ if(rec instanceof LastCellOfRowDummyRecord) {
+ LastCellOfRowDummyRecord eor = (LastCellOfRowDummyRecord) rec;
assertEquals(rowCount, eor.getRow());
rowCount++;
}
@@ -416,8 +416,7 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
Record[] rr = r;
int eorCount=0;
int sfrCount=0;
- for (int i = 0; i < rr.length; i++) {
- Record record = rr[i];
+ for (Record record : rr) {
if (record instanceof SharedFormulaRecord) {
sfrCount++;
}
diff --git a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
index 1bb3b1924c..953266b4f5 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
@@ -429,8 +429,8 @@ public final class TestHyperlinkRecord {
@Test
public void testClone() {
byte[][] data = {data1, data2, data3, data4};
- for (int i = 0; i < data.length; i++) {
- RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data[i]);
+ for (final byte[] d : data) {
+ RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, d);
HyperlinkRecord link = new HyperlinkRecord(is);
HyperlinkRecord clone = link.clone();
assertArrayEquals(link.serialize(), clone.serialize());
diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
index 29d525098b..330e93df92 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
@@ -107,10 +107,10 @@ public final class TestTextObjectRecord extends TestCase {
* Test that TextObjectRecord serializes logs records properly.
*/
public void testLongRecords() {
- int[] length = {1024, 2048, 4096, 8192, 16384}; //test against strings of different length
- for (int i = 0; i < length.length; i++) {
- StringBuffer buff = new StringBuffer(length[i]);
- for (int j = 0; j < length[i]; j++) {
+ int[] lengths = {1024, 2048, 4096, 8192, 16384}; //test against strings of different length
+ for (int length : lengths) {
+ StringBuffer buff = new StringBuffer(length);
+ for (int j = 0; j < length; j++) {
buff.append("x");
}
HSSFRichTextString str = new HSSFRichTextString(buff.toString());
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
index 86e7f2a8a2..e2a992710b 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
@@ -135,8 +135,8 @@ public final class TestFormulas extends TestCase {
String[] operation = new String[] {
"+", "-", "*", "/", "^", "&"
};
- for (int k = 0; k < operation.length; k++) {
- operationRefTest(operation[k]);
+ for (final String op : operation) {
+ operationRefTest(op);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
index ac65ea2077..96c2d9220d 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java
@@ -65,21 +65,21 @@ public final class TestHSSFClientAnchor extends TestCase {
* (Bug 42999 reported that dx1 and dx2 are swapped if dx1>dx2. It doesn't make sense for client anchors.)
*/
public void testConvertAnchor() {
- HSSFClientAnchor[] anchor = {
+ HSSFClientAnchor[] anchors = {
new HSSFClientAnchor( 0 , 0 , 0 , 0 ,(short)0, 1,(short)1,3),
new HSSFClientAnchor( 100 , 0 , 900 , 255 ,(short)0, 1,(short)1,3),
new HSSFClientAnchor( 900 , 0 , 100 , 255 ,(short)0, 1,(short)1,3)
};
- for (int i = 0; i < anchor.length; i++) {
- EscherClientAnchorRecord record = (EscherClientAnchorRecord)ConvertAnchor.createAnchor(anchor[i]);
- assertEquals(anchor[i].getDx1(), record.getDx1());
- assertEquals(anchor[i].getDx2(), record.getDx2());
- assertEquals(anchor[i].getDy1(), record.getDy1());
- assertEquals(anchor[i].getDy2(), record.getDy2());
- assertEquals(anchor[i].getCol1(), record.getCol1());
- assertEquals(anchor[i].getCol2(), record.getCol2());
- assertEquals(anchor[i].getRow1(), record.getRow1());
- assertEquals(anchor[i].getRow2(), record.getRow2());
+ for (HSSFClientAnchor anchor : anchors) {
+ EscherClientAnchorRecord record = (EscherClientAnchorRecord)ConvertAnchor.createAnchor(anchor);
+ assertEquals(anchor.getDx1(), record.getDx1());
+ assertEquals(anchor.getDx2(), record.getDx2());
+ assertEquals(anchor.getDy1(), record.getDy1());
+ assertEquals(anchor.getDy2(), record.getDy2());
+ assertEquals(anchor.getCol1(), record.getCol1());
+ assertEquals(anchor.getCol2(), record.getCol2());
+ assertEquals(anchor.getRow1(), record.getRow1());
+ assertEquals(anchor.getRow2(), record.getRow2());
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
index b9ff69543a..6c6631a9b1 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java
@@ -20,7 +20,6 @@ package org.apache.poi.hssf.usermodel;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.util.Iterator;
import java.util.List;
import javax.imageio.ImageIO;
@@ -46,8 +45,7 @@ public final class TestHSSFPictureData extends TestCase{
List<HSSFPictureData> lst = (List<HSSFPictureData>)(List<?>)wb.getAllPictures();
//assertEquals(2, lst.size());
- for (Iterator it = lst.iterator(); it.hasNext(); ) {
- HSSFPictureData pict = (HSSFPictureData)it.next();
+ for (final HSSFPictureData pict : lst) {
String ext = pict.suggestFileExtension();
byte[] data = pict.getData();
if (ext.equals("jpeg")){
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
index 6aebd7488d..bbe1e39f6f 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
@@ -340,10 +340,9 @@ public final class TestDocumentInputStream extends TestCase {
while (stream.available() >= buffer.length)
{
assertEquals(_buffer_size, stream.read(buffer));
- for (int j = 0; j < buffer.length; j++)
- {
+ for (byte data : buffer) {
assertEquals("in main loop, byte " + offset,
- _workbook_data[ offset ], buffer[ j ]);
+ _workbook_data[ offset ], data);
offset++;
}
assertEquals("offset " + offset, _workbook_size - offset,
diff --git a/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java b/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java
index a2ff6ceb1f..2d6ef1845c 100644
--- a/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java
+++ b/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java
@@ -213,10 +213,9 @@ public final class TestSmallDocumentBlock extends TestCase {
assertEquals("testing block at offset " + offset, 64,
out_data.length);
- for (int j = 0; j < out_data.length; j++)
- {
+ for (byte b : out_data) {
assertEquals("testing byte at offset " + offset,
- data[ offset ], out_data[ j ]);
+ data[ offset ], b);
offset++;
}
}
diff --git a/src/testcases/org/apache/poi/util/TestByteField.java b/src/testcases/org/apache/poi/util/TestByteField.java
index 2c3c4996d7..ca2a1495f2 100644
--- a/src/testcases/org/apache/poi/util/TestByteField.java
+++ b/src/testcases/org/apache/poi/util/TestByteField.java
@@ -87,11 +87,10 @@ public final class TestByteField extends TestCase {
// as expected
}
- for (int j = 0; j < _test_array.length; j++)
- {
+ for (byte b : _test_array) {
array = new byte[ 1 ];
- new ByteField(0, _test_array[ j ], array);
- assertEquals(_test_array[ j ], new ByteField(0, array).get());
+ new ByteField(0, b, array);
+ assertEquals(b, new ByteField(0, array).get());
}
}
@@ -151,11 +150,10 @@ public final class TestByteField extends TestCase {
ByteField field = new ByteField(0);
byte[] array = new byte[ 1 ];
- for (int j = 0; j < _test_array.length; j++)
- {
- field.set(_test_array[ j ]);
+ for (byte b : _test_array) {
+ field.set(b);
field.writeToBytes(array);
- assertEquals("testing ", _test_array[ j ], array[ 0 ]);
+ assertEquals("testing ", b, array[ 0 ]);
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestIntList.java b/src/testcases/org/apache/poi/util/TestIntList.java
index 1037c2eaf3..abf50158bc 100644
--- a/src/testcases/org/apache/poi/util/TestIntList.java
+++ b/src/testcases/org/apache/poi/util/TestIntList.java
@@ -47,9 +47,8 @@ public final class TestIntList extends TestCase {
0, 1, 2, 3, 5
};
- for (int j = 0; j < testArray.length; j++)
- {
- list.add(testArray[ j ]);
+ for (int element : testArray) {
+ list.add(element);
}
for (int j = 0; j < testArray.length; j++)
{
diff --git a/src/testcases/org/apache/poi/util/TestIntegerField.java b/src/testcases/org/apache/poi/util/TestIntegerField.java
index a26f09cca0..228d398ea2 100644
--- a/src/testcases/org/apache/poi/util/TestIntegerField.java
+++ b/src/testcases/org/apache/poi/util/TestIntegerField.java
@@ -89,11 +89,10 @@ public final class TestIntegerField extends TestCase {
// as expected
}
- for (int j = 0; j < _test_array.length; j++)
- {
+ for (int element : _test_array) {
array = new byte[ 4 ];
- new IntegerField(0, _test_array[ j ], array);
- assertEquals(_test_array[ j ], new IntegerField(0, array).get());
+ new IntegerField(0, element, array);
+ assertEquals(element, new IntegerField(0, array).get());
}
}
@@ -172,9 +171,8 @@ public final class TestIntegerField extends TestCase {
IntegerField field = new IntegerField(0);
byte[] array = new byte[ 4 ];
- for (int j = 0; j < _test_array.length; j++)
- {
- field.set(_test_array[ j ]);
+ for (int b : _test_array) {
+ field.set(b);
field.writeToBytes(array);
int val = array[ 3 ] << 24;
@@ -182,7 +180,7 @@ public final class TestIntegerField extends TestCase {
val += (array[ 2 ] << 16) & 0x00FF0000;
val += (array[ 1 ] << 8) & 0x0000FF00;
val += (array[ 0 ] & 0x000000FF);
- assertEquals("testing ", _test_array[ j ], val);
+ assertEquals("testing ", b, val);
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestLongField.java b/src/testcases/org/apache/poi/util/TestLongField.java
index a37e88ed3b..f613bae1c9 100644
--- a/src/testcases/org/apache/poi/util/TestLongField.java
+++ b/src/testcases/org/apache/poi/util/TestLongField.java
@@ -93,11 +93,10 @@ public final class TestLongField extends TestCase {
// as expected
}
- for (int j = 0; j < _test_array.length; j++)
- {
+ for (long element : _test_array) {
array = new byte[ 8 ];
- new LongField(0, _test_array[ j ], array);
- assertEquals(_test_array[ j ], new LongField(0, array).get());
+ new LongField(0, element, array);
+ assertEquals(element, new LongField(0, array).get());
}
}
@@ -201,9 +200,8 @@ public final class TestLongField extends TestCase {
LongField field = new LongField(0);
byte[] array = new byte[ 8 ];
- for (int j = 0; j < _test_array.length; j++)
- {
- field.set(_test_array[ j ]);
+ for (long element : _test_array) {
+ field.set(element);
field.writeToBytes(array);
long val = (( long ) array[ 7 ]) << 56;
@@ -215,7 +213,7 @@ public final class TestLongField extends TestCase {
val += ((( long ) array[ 2 ]) << 16) & 0x0000000000FF0000L;
val += ((( long ) array[ 1 ]) << 8) & 0x000000000000FF00L;
val += (array[ 0 ] & 0x00000000000000FFL);
- assertEquals("testing ", _test_array[ j ], val);
+ assertEquals("testing ", element, val);
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestShortField.java b/src/testcases/org/apache/poi/util/TestShortField.java
index dd93c1a48d..9e1fec64b5 100644
--- a/src/testcases/org/apache/poi/util/TestShortField.java
+++ b/src/testcases/org/apache/poi/util/TestShortField.java
@@ -87,11 +87,10 @@ public final class TestShortField extends TestCase {
// as expected
}
- for (int j = 0; j < _test_array.length; j++)
- {
+ for (short element : _test_array) {
array = new byte[ 2 ];
- new ShortField(0, _test_array[ j ], array);
- assertEquals(_test_array[ j ], new ShortField(0, array).get());
+ new ShortField(0, element, array);
+ assertEquals(element, new ShortField(0, array).get());
}
}
@@ -160,15 +159,14 @@ public final class TestShortField extends TestCase {
ShortField field = new ShortField(0);
byte[] array = new byte[ 2 ];
- for (int j = 0; j < _test_array.length; j++)
- {
- field.set(_test_array[ j ]);
+ for (short element : _test_array) {
+ field.set(element);
field.writeToBytes(array);
short val = ( short ) (array[ 1 ] << 8);
val &= ( short ) 0xFF00;
val += ( short ) (array[ 0 ] & 0x00FF);
- assertEquals("testing ", _test_array[ j ], val);
+ assertEquals("testing ", element, val);
}
}
}
diff --git a/src/testcases/org/apache/poi/util/TestStringUtil.java b/src/testcases/org/apache/poi/util/TestStringUtil.java
index 122ec408d9..ec9792a259 100644
--- a/src/testcases/org/apache/poi/util/TestStringUtil.java
+++ b/src/testcases/org/apache/poi/util/TestStringUtil.java
@@ -191,6 +191,10 @@ public class TestStringUtil {
assertEquals("abc", StringUtil.join(",", "abc")); // degenerate case: one thing to join, no trailing comma
assertEquals("abc|def|ghi", StringUtil.join("|", "abc", "def", "ghi"));
assertEquals("5|8.5|true|string", StringUtil.join("|", 5, 8.5, true, "string")); //assumes Locale prints number decimal point as a period rather than a comma
+
+ String[] arr = new String[] { "Apache", "POI", "project" };
+ assertEquals("no separator", "ApachePOIproject", StringUtil.join(arr));
+ assertEquals("separator", "Apache POI project", StringUtil.join(arr, " "));
}
@Test