Use Java 5's String#contains(CharSequence)
No need to nest
diff --git a/jelly-tags/junit/src/main/java/org/apache/commons/jelly/tags/junit/AssertFileContainsTag.java b/jelly-tags/junit/src/main/java/org/apache/commons/jelly/tags/junit/AssertFileContainsTag.java
index 97f2a52..3a82b58 100644
--- a/jelly-tags/junit/src/main/java/org/apache/commons/jelly/tags/junit/AssertFileContainsTag.java
+++ b/jelly-tags/junit/src/main/java/org/apache/commons/jelly/tags/junit/AssertFileContainsTag.java
@@ -62,42 +62,39 @@
{
throw new MissingAttributeException("file");
}
+ if (file.exists() && file.canRead())
+ {
+ try
+ {
+ BufferedReader br = new BufferedReader(new FileReader(file));
+ String line;
+ boolean found = false;
+ while ((line = br.readLine()) != null)
+ {
+ if (line.contains(match))
+ {
+ found = true;
+ break;
+ }
+ }
+ br.close();
+ assertTrue(message, found);
+ }
+ catch (IOException fnfe)
+ {
+ throw new JellyTagException(fnfe);
+ }
+ }
else
{
- if (file.exists() && file.canRead())
+ try
{
- try
- {
- BufferedReader br = new BufferedReader(new FileReader(file));
- String line;
- boolean found = false;
- while ((line = br.readLine()) != null)
- {
- if (line.indexOf(match) != -1)
- {
- found = true;
- break;
- }
- }
- br.close();
- assertTrue(message, found);
- }
- catch (IOException fnfe)
- {
- throw new JellyTagException(fnfe);
- }
+ throw new JellyTagException("File '" + file.getCanonicalPath()
+ + "' can't be read.");
}
- else
+ catch (IOException e)
{
- try
- {
- throw new JellyTagException("File '" + file.getCanonicalPath()
- + "' can't be read.");
- }
- catch (IOException e)
- {
- throw new JellyTagException(e);
- }
+ throw new JellyTagException(e);
}
}
}