Eclipse automated refactor/cleanup: convert for loops to for-each loops

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-10-19 23:04:39 +00:00
parent f6346b87a4
commit d5d5419d9c
3 changed files with 21 additions and 36 deletions

View File

@ -44,8 +44,8 @@ public final class TestContentType extends TestCase {
String[] contentTypesToTest = new String[] { "text/xml", String[] contentTypesToTest = new String[] { "text/xml",
"application/pgp-key", "application/vnd.hp-PCLXL", "application/pgp-key", "application/vnd.hp-PCLXL",
"application/vnd.lotus-1-2-3" }; "application/vnd.lotus-1-2-3" };
for (int i = 0; i < contentTypesToTest.length; ++i) { for (String contentType : contentTypesToTest) {
new ContentType(contentTypesToTest[i]); new ContentType(contentType);
} }
} }
@ -72,14 +72,13 @@ public final class TestContentType extends TestCase {
"text[/xml", "text]/xml", "text?/xml", "tex=t/xml", "text[/xml", "text]/xml", "text?/xml", "tex=t/xml",
"te{xt/xml", "tex}t/xml", "te xt/xml", "te{xt/xml", "tex}t/xml", "te xt/xml",
"text" + (char) 9 + "/xml", "text xml", " text/xml " }; "text" + (char) 9 + "/xml", "text xml", " text/xml " };
for (int i = 0; i < contentTypesToTest.length; ++i) { for (String contentType : contentTypesToTest) {
try { try {
new ContentType(contentTypesToTest[i]); new ContentType(contentType);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
continue; continue;
} }
fail("Must have fail for content type: '" + contentTypesToTest[i] fail("Must have fail for content type: '" + contentType + "' !");
+ "' !");
} }
} }
@ -110,14 +109,13 @@ public final class TestContentType extends TestCase {
"mail/toto;titi = tata", // spaces not allowed "mail/toto;titi = tata", // spaces not allowed
"text/\u0080" // characters above ASCII are not allowed "text/\u0080" // characters above ASCII are not allowed
}; };
for (int i = 0; i < contentTypesToTest.length; ++i) { for (String contentType : contentTypesToTest) {
try { try {
new ContentType(contentTypesToTest[i]); new ContentType(contentType);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
continue; continue;
} }
fail("Must have fail for content type: '" + contentTypesToTest[i] fail("Must have fail for content type: '" + contentType + "' !");
+ "' !");
} }
} }
@ -128,14 +126,13 @@ public final class TestContentType extends TestCase {
*/ */
public void testContentTypeCommentFailure() { public void testContentTypeCommentFailure() {
String[] contentTypesToTest = new String[] { "text/xml(comment)" }; String[] contentTypesToTest = new String[] { "text/xml(comment)" };
for (int i = 0; i < contentTypesToTest.length; ++i) { for (String contentType : contentTypesToTest) {
try { try {
new ContentType(contentTypesToTest[i]); new ContentType(contentType);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
continue; continue;
} }
fail("Must have fail for content type: '" + contentTypesToTest[i] fail("Must have fail for content type: '" + contentType + "' !");
+ "' !");
} }
} }

View File

@ -133,10 +133,8 @@ public class TestXSSFExcelExtractor extends TestCase {
POITextExtractor[] extractors = POITextExtractor[] extractors =
new POITextExtractor[] { ooxmlExtractor, ole2Extractor }; new POITextExtractor[] { ooxmlExtractor, ole2Extractor };
for (int i = 0; i < extractors.length; i++) {
@SuppressWarnings("resource")
POITextExtractor extractor = extractors[i];
for (POITextExtractor extractor : extractors) {
String text = extractor.getText().replaceAll("[\r\t]", ""); String text = extractor.getText().replaceAll("[\r\t]", "");
assertTrue(text.startsWith("First Sheet\nTest spreadsheet\n2nd row2nd row 2nd column\n")); assertTrue(text.startsWith("First Sheet\nTest spreadsheet\n2nd row2nd row 2nd column\n"));
Pattern pattern = Pattern.compile(".*13(\\.0+)?\\s+Sheet3.*", Pattern.DOTALL); Pattern pattern = Pattern.compile(".*13(\\.0+)?\\s+Sheet3.*", Pattern.DOTALL);

View File

@ -23,6 +23,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
@ -51,15 +53,9 @@ public class TestXWPFWordExtractor extends TestCase {
"Phasellus ultricies mi nec leo. Sed tempus. In sit amet lorem at velit faucibus vestibulum.\n" "Phasellus ultricies mi nec leo. Sed tempus. In sit amet lorem at velit faucibus vestibulum.\n"
)); ));
// Check number of paragraphs // Check number of paragraphs by counting number of newlines
int ps = 0; int numberOfParagraphs = StringUtil.count(text, '\n');
char[] t = text.toCharArray(); assertEquals(3, numberOfParagraphs);
for (int i = 0; i < t.length; i++) {
if (t[i] == '\n') {
ps++;
}
}
assertEquals(3, ps);
extractor.close(); extractor.close();
} }
@ -90,15 +86,9 @@ public class TestXWPFWordExtractor extends TestCase {
"11.4%\t\t90\t\t\t\t\t250\t\t1,310\t\n\n \n\n\n" "11.4%\t\t90\t\t\t\t\t250\t\t1,310\t\n\n \n\n\n"
)); ));
// Check number of paragraphs // Check number of paragraphs by counting number of newlines
int ps = 0; int numberOfParagraphs = StringUtil.count(text, '\n');
char[] t = text.toCharArray(); assertEquals(134, numberOfParagraphs);
for (int i = 0; i < t.length; i++) {
if (t[i] == '\n') {
ps++;
}
}
assertEquals(134, ps);
extractor.close(); extractor.close();
} }