more findbugs
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 18 Apr 2010 21:35:53 +0000 (21:35 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sun, 18 Apr 2010 21:35:53 +0000 (21:35 +0000)
15 files changed:
support/general/src/main/java/org/wamblee/io/SimpleProcess.java
support/general/src/test/java/org/wamblee/concurrency/ReadWriteLockTest.java
support/general/src/test/java/org/wamblee/conditions/AndConditionTest.java
support/general/src/test/java/org/wamblee/conditions/OrConditionTest.java
support/general/src/test/java/org/wamblee/general/PairTest.java
support/general/src/test/java/org/wamblee/io/ClassPathResourceTest.java
support/general/src/test/java/org/wamblee/io/FileResourceTest.java
support/general/src/test/java/org/wamblee/io/FileSystemUtils.java
support/general/src/test/java/org/wamblee/io/TestData.java
support/general/src/test/java/org/wamblee/observer/ObservableTest.java
support/general/src/test/java/org/wamblee/test/AssertionUtils.java
support/general/src/test/java/org/wamblee/test/EventTracker.java
support/general/src/test/java/org/wamblee/xml/ClasspathUriResolverTest.java
support/general/src/test/java/org/wamblee/xml/XmlUtils.java
support/general/src/test/java/org/wamblee/xml/XslTransformerTest.java

index b0e96a90397326a9e8ec8f4c04fce9e34d4c36ad..f0090f53215c0d6af3a80228329eddaed930b97e 100644 (file)
@@ -183,10 +183,10 @@ public class SimpleProcess {
 
     @Override
     public String toString() {
-        String fullcmd = "";
+        StringBuffer fullcmd = new StringBuffer();
 
         for (String part : cmd) {
-            fullcmd += (part + " ");
+            fullcmd.append(part + " ");
         }
 
         return "process(dir = '" + directory + "', cmd = '" + fullcmd + "')";
index d17b3d92fa66bc1bbfb9bce90437f54a4f48171c..3dc5c95abee49ca7bcb08fa5964ed7e53edc2055 100644 (file)
@@ -466,7 +466,7 @@ class ReadLocker implements Runnable {
         try {
             Thread.sleep(sleepTime);
         } catch (InterruptedException e) {
-            Assert.fail("ReadLocker thread was interrupted." +
+            ReadWriteLockTest.fail("ReadLocker thread was interrupted." +
                 Thread.currentThread());
         }
 
@@ -499,7 +499,7 @@ class WriteLocker implements Runnable {
         try {
             Thread.sleep(sleepTime);
         } catch (InterruptedException e) {
-            Assert.fail("WriteLocker thread was interrupted: " +
+            ReadWriteLockTest.fail("WriteLocker thread was interrupted: " +
                 Thread.currentThread());
         }
 
index 6170b8ea06ad3f4bb51edb97b1749f8f7f7d5c5f..f9faa729d3e5bc9bc762d3911994cb80e0fa6d21 100644 (file)
@@ -41,7 +41,7 @@ public class AndConditionTest extends TestCase {
         }
 
         AndCondition<Integer> and = new AndCondition<Integer>(conditions);
-        assertEquals(aResult, and.matches(new Integer(0)));
+        assertEquals(aResult, and.matches(Integer.valueOf(0)));
     }
 
     /**
index ef67728b45f4ff6a00ccd6cb18907d9787281f33..9afadfeeb2062fd2213d6dc0905b6b9c4b439d0a 100644 (file)
@@ -41,7 +41,7 @@ public class OrConditionTest extends TestCase {
         }
 
         OrCondition<Integer> or = new OrCondition<Integer>(conditions);
-        assertEquals(aResult, or.matches(new Integer(0)));
+        assertEquals(aResult, or.matches(Integer.valueOf(0)));
     }
 
     /**
index d327674c69f8730770e77a8a1ce0c6ec31e56f8b..071a0c8ce9a8124c3d2d49b369fb819b892084b0 100644 (file)
@@ -27,7 +27,7 @@ public class PairTest extends TestCase {
         assertEquals("hello", pair.getSecond());
 
         Pair<Integer, String> pair2 = new Pair<Integer, String>(pair);
-        assertEquals(new Integer(10), pair2.getFirst());
+        assertEquals(Integer.valueOf(10), pair2.getFirst());
         assertEquals("hello", pair2.getSecond());
     }
 }
index 4ebcb64c85d95dc372fb5cda2ff0bffa08a24ff7..6baf1f86791540a9c7ac34afb272550b597fcbd5 100644 (file)
@@ -45,7 +45,7 @@ public class ClassPathResourceTest extends TestCase {
         try {
             ClassPathResource resource = new ClassPathResource(
                 "org/wamblee/io/myresource-nonexistent.txt");
-            InputStream is = resource.getInputStream();
+            resource.getInputStream();
         } catch (IOException e) {
             return; // ok
         }
index 0f2b36f1c0b0778e2fa082389708d8bbbcf2d20f..92b0c6449e1136a00d0d00ebab1cdf7a06c8c6a0 100644 (file)
@@ -48,7 +48,7 @@ public class FileResourceTest extends TestCase {
             FileResource resource = new FileResource(new File(FileSystemUtils
                 .getTestInputDir(FileResourceTest.class),
                 "myresource-nonexistent.txt"));
-            InputStream is = resource.getInputStream();
+            resource.getInputStream();
         } catch (IOException e) {
             return; // ok
         }
index 3b2d7e05c6dd961197b0025541d253e1af91987c..4be787e791899be20eed098e532e1eab24fb341a 100644 (file)
@@ -303,7 +303,9 @@ public final class FileSystemUtils {
         Assert.assertTrue(aSrc.isDirectory());
         Assert.assertTrue(!aTarget.exists());
 
-        aTarget.mkdirs();
+        if (!aTarget.mkdirs()) { 
+            Assert.fail("Could not create target directory '" + aTarget + "'");
+        }
 
         File[] files = aSrc.listFiles();
 
index 8430b0988407fa76f833d0a9782685d08044d6bf..f34b0a00ebd3d6815e822ab99760a7384bd53b6c 100644 (file)
@@ -34,7 +34,6 @@ import java.nio.channels.FileChannel;
  * @author Erik Brakkee
  */
 public final class TestData {
-    private Object testcase;
     private File root;
 
     /**
@@ -43,7 +42,6 @@ public final class TestData {
      * test.
      */
     public TestData(Object aTestcase) {
-        testcase = aTestcase;
         root = getTestRootDir(aTestcase);
         FileSystemUtils.createDir(root);
     }
index f5708dbd16c3cb0dc608a01cf51d41fb93b2ea11..f2fc8d7d5609bfaab493d98753b56411fd96cf6c 100644 (file)
@@ -42,7 +42,7 @@ public class ObservableTest extends TestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        observed = new Integer(1);
+        observed = Integer.valueOf(1);
         observable = new Observable<Integer, String>(observed,
             new DefaultObserverNotifier());
     }
index c0387e0cf8b4e92d43b8a593c0e7a5eae304e3a0..8c25fc13f6963646653ee3cab510c6d622899b2e 100644 (file)
  */ 
 package org.wamblee.test;
 
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
 import junit.framework.TestCase;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * Useful assertions for use in test cases.
  * 
@@ -112,14 +112,14 @@ public final class AssertionUtils {
         TestCase.assertEquals("Map sizes differ", aExpectedMap.size(), aActual
             .size());
 
-        Set keys = aExpectedMap.keySet();
+        Set<Entry<Key,Value>> expectedEntries = aExpectedMap.entrySet();
 
-        for (Iterator i = keys.iterator(); i.hasNext();) {
-            String key = (String) i.next();
+        for (Entry<Key,Value> entry: expectedEntries) {
+            Key key = entry.getKey();
             TestCase.assertTrue("Map does not containg entry for key:" + key,
                 aActual.containsKey(key));
             AssertionUtils.assertEquals("Value of key " + key + " of map",
-                aExpectedMap.get(key), aActual.get(key));
+                entry.getValue(), aActual.get(key));
         }
     }
 
index 682a6961b1c6261e6b49cb2234e4ee7b03057fe6..e66d01475e08a50ee3f18c15ad451506f2ecbe0b 100644 (file)
@@ -56,7 +56,7 @@ public class EventTracker<Event> {
         clear();
     }
 
-    public void clear() {
+    public synchronized void clear() {
         events = new HashMap<Thread, List<Event>>();
     }
 
index e48b5cc3662b97bd549399a67b852411c43aff27..97e71758d67e9fe427d072e206e318784b36e220 100644 (file)
@@ -73,7 +73,7 @@ public class ClasspathUriResolverTest extends TestCase {
      */
     public void testResolveNonExistingFile() {
         try {
-            Source source = resolver.resolve(
+            resolver.resolve(
                 "org/wamblee/xml/reportToHtml-nonexisting.xsl", "");
         } catch (TransformerException e) {
             return; // ok
index ac0f88df096660ae7f0a2b7b616f062ec3ad4edb..5f9755e474407b1a94afb73c0c814abbe58c419b 100644 (file)
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 package org.wamblee.xml;
 
-import junit.framework.TestCase;
-
-import org.dom4j.Attribute;
-import org.dom4j.Document;
-import org.dom4j.Element;
-
+import java.io.Serializable;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
+import junit.framework.TestCase;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.Element;
+
 /**
  * XML test support utilities.
  * 
@@ -154,7 +155,10 @@ public final class XmlUtils {
      * Comparator which compares attributes by name.
      */
     private static final class AttributeComparator implements
-        Comparator<Attribute> {
+        Comparator<Attribute>, Serializable {
+        
+        private static final long serialVersionUID = 7897287273519886301L;
+
         /*
          * (non-Javadoc)
          * 
index 79c3fbef12d1dae23c1b0bf164344c7dc3d25138..0c5c269732e8cf572c21c45967b42abadfad2e59 100644 (file)
@@ -123,7 +123,7 @@ public class XslTransformerTest extends TestCase {
             .read(xmlResource.getInputStream()).getBytes();
 
         try {
-            Document output1 = transformer.transform(documentData, xslt);
+            transformer.transform(documentData, xslt);
         } catch (TransformerException e) {
             return; // ok
         }
@@ -148,7 +148,7 @@ public class XslTransformerTest extends TestCase {
             .read(xmlResource.getInputStream()).getBytes();
 
         try {
-            Document output1 = transformer.transform(documentData, xslt);
+            transformer.transform(documentData, xslt);
         } catch (TransformerException e) {
             return; // ok
         }
@@ -174,7 +174,7 @@ public class XslTransformerTest extends TestCase {
             .read(xmlResource.getInputStream()).getBytes();
 
         try {
-            Document output1 = transformer.transform(documentData, xslt);
+            transformer.transform(documentData, xslt);
         } catch (TransformerException e) {
             return; // ok
         }
@@ -237,7 +237,7 @@ public class XslTransformerTest extends TestCase {
         XslTransformer transformer = new XslTransformer();
 
         try {
-            Source source = transformer
+            transformer
                 .resolve("org/wamblee/xml/utilities-nonexistent.xsl");
         } catch (TransformerException e) {
             return; // ok