From: erik Date: Sun, 18 Apr 2010 21:35:53 +0000 (+0000) Subject: more findbugs X-Git-Tag: wamblee-utils-0.2.2^2~61 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=aeb45ea3d98eb31834e3ea9145489bbc29800ae8;p=utils more findbugs --- diff --git a/support/general/src/main/java/org/wamblee/io/SimpleProcess.java b/support/general/src/main/java/org/wamblee/io/SimpleProcess.java index b0e96a90..f0090f53 100644 --- a/support/general/src/main/java/org/wamblee/io/SimpleProcess.java +++ b/support/general/src/main/java/org/wamblee/io/SimpleProcess.java @@ -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 + "')"; diff --git a/support/general/src/test/java/org/wamblee/concurrency/ReadWriteLockTest.java b/support/general/src/test/java/org/wamblee/concurrency/ReadWriteLockTest.java index d17b3d92..3dc5c95a 100644 --- a/support/general/src/test/java/org/wamblee/concurrency/ReadWriteLockTest.java +++ b/support/general/src/test/java/org/wamblee/concurrency/ReadWriteLockTest.java @@ -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()); } diff --git a/support/general/src/test/java/org/wamblee/conditions/AndConditionTest.java b/support/general/src/test/java/org/wamblee/conditions/AndConditionTest.java index 6170b8ea..f9faa729 100644 --- a/support/general/src/test/java/org/wamblee/conditions/AndConditionTest.java +++ b/support/general/src/test/java/org/wamblee/conditions/AndConditionTest.java @@ -41,7 +41,7 @@ public class AndConditionTest extends TestCase { } AndCondition and = new AndCondition(conditions); - assertEquals(aResult, and.matches(new Integer(0))); + assertEquals(aResult, and.matches(Integer.valueOf(0))); } /** diff --git a/support/general/src/test/java/org/wamblee/conditions/OrConditionTest.java b/support/general/src/test/java/org/wamblee/conditions/OrConditionTest.java index ef67728b..9afadfee 100644 --- a/support/general/src/test/java/org/wamblee/conditions/OrConditionTest.java +++ b/support/general/src/test/java/org/wamblee/conditions/OrConditionTest.java @@ -41,7 +41,7 @@ public class OrConditionTest extends TestCase { } OrCondition or = new OrCondition(conditions); - assertEquals(aResult, or.matches(new Integer(0))); + assertEquals(aResult, or.matches(Integer.valueOf(0))); } /** diff --git a/support/general/src/test/java/org/wamblee/general/PairTest.java b/support/general/src/test/java/org/wamblee/general/PairTest.java index d327674c..071a0c8c 100644 --- a/support/general/src/test/java/org/wamblee/general/PairTest.java +++ b/support/general/src/test/java/org/wamblee/general/PairTest.java @@ -27,7 +27,7 @@ public class PairTest extends TestCase { assertEquals("hello", pair.getSecond()); Pair pair2 = new Pair(pair); - assertEquals(new Integer(10), pair2.getFirst()); + assertEquals(Integer.valueOf(10), pair2.getFirst()); assertEquals("hello", pair2.getSecond()); } } diff --git a/support/general/src/test/java/org/wamblee/io/ClassPathResourceTest.java b/support/general/src/test/java/org/wamblee/io/ClassPathResourceTest.java index 4ebcb64c..6baf1f86 100644 --- a/support/general/src/test/java/org/wamblee/io/ClassPathResourceTest.java +++ b/support/general/src/test/java/org/wamblee/io/ClassPathResourceTest.java @@ -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 } diff --git a/support/general/src/test/java/org/wamblee/io/FileResourceTest.java b/support/general/src/test/java/org/wamblee/io/FileResourceTest.java index 0f2b36f1..92b0c644 100644 --- a/support/general/src/test/java/org/wamblee/io/FileResourceTest.java +++ b/support/general/src/test/java/org/wamblee/io/FileResourceTest.java @@ -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 } diff --git a/support/general/src/test/java/org/wamblee/io/FileSystemUtils.java b/support/general/src/test/java/org/wamblee/io/FileSystemUtils.java index 3b2d7e05..4be787e7 100644 --- a/support/general/src/test/java/org/wamblee/io/FileSystemUtils.java +++ b/support/general/src/test/java/org/wamblee/io/FileSystemUtils.java @@ -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(); diff --git a/support/general/src/test/java/org/wamblee/io/TestData.java b/support/general/src/test/java/org/wamblee/io/TestData.java index 8430b098..f34b0a00 100644 --- a/support/general/src/test/java/org/wamblee/io/TestData.java +++ b/support/general/src/test/java/org/wamblee/io/TestData.java @@ -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); } diff --git a/support/general/src/test/java/org/wamblee/observer/ObservableTest.java b/support/general/src/test/java/org/wamblee/observer/ObservableTest.java index f5708dbd..f2fc8d7d 100644 --- a/support/general/src/test/java/org/wamblee/observer/ObservableTest.java +++ b/support/general/src/test/java/org/wamblee/observer/ObservableTest.java @@ -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(observed, new DefaultObserverNotifier()); } diff --git a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java b/support/general/src/test/java/org/wamblee/test/AssertionUtils.java index c0387e0c..8c25fc13 100644 --- a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java +++ b/support/general/src/test/java/org/wamblee/test/AssertionUtils.java @@ -15,16 +15,16 @@ */ 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> expectedEntries = aExpectedMap.entrySet(); - for (Iterator i = keys.iterator(); i.hasNext();) { - String key = (String) i.next(); + for (Entry 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)); } } diff --git a/support/general/src/test/java/org/wamblee/test/EventTracker.java b/support/general/src/test/java/org/wamblee/test/EventTracker.java index 682a6961..e66d0147 100644 --- a/support/general/src/test/java/org/wamblee/test/EventTracker.java +++ b/support/general/src/test/java/org/wamblee/test/EventTracker.java @@ -56,7 +56,7 @@ public class EventTracker { clear(); } - public void clear() { + public synchronized void clear() { events = new HashMap>(); } diff --git a/support/general/src/test/java/org/wamblee/xml/ClasspathUriResolverTest.java b/support/general/src/test/java/org/wamblee/xml/ClasspathUriResolverTest.java index e48b5cc3..97e71758 100644 --- a/support/general/src/test/java/org/wamblee/xml/ClasspathUriResolverTest.java +++ b/support/general/src/test/java/org/wamblee/xml/ClasspathUriResolverTest.java @@ -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 diff --git a/support/general/src/test/java/org/wamblee/xml/XmlUtils.java b/support/general/src/test/java/org/wamblee/xml/XmlUtils.java index ac0f88df..5f9755e4 100644 --- a/support/general/src/test/java/org/wamblee/xml/XmlUtils.java +++ b/support/general/src/test/java/org/wamblee/xml/XmlUtils.java @@ -12,21 +12,22 @@ * 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 { + Comparator, Serializable { + + private static final long serialVersionUID = 7897287273519886301L; + /* * (non-Javadoc) * diff --git a/support/general/src/test/java/org/wamblee/xml/XslTransformerTest.java b/support/general/src/test/java/org/wamblee/xml/XslTransformerTest.java index 79c3fbef..0c5c2697 100644 --- a/support/general/src/test/java/org/wamblee/xml/XslTransformerTest.java +++ b/support/general/src/test/java/org/wamblee/xml/XslTransformerTest.java @@ -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