[jboss-svn-commits] JBoss Common SVN: r3715 - in shrinkwrap/trunk/impl-base/src: test/java/org/jboss/shrinkwrap/impl/base and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Nov 15 12:05:16 EST 2009
Author: ALRubinger
Date: 2009-11-15 12:05:16 -0500 (Sun, 15 Nov 2009)
New Revision: 3715
Added:
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/TestIOUtil.java
Modified:
shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/IOUtil.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java
shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExportTestBase.java
Log:
[SHRINKWRAP-78] Move test code to test sources, address some FindBugs issues
Modified: shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/IOUtil.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/IOUtil.java 2009-11-15 15:29:06 UTC (rev 3714)
+++ shrinkwrap/trunk/impl-base/src/main/java/org/jboss/shrinkwrap/impl/base/io/IOUtil.java 2009-11-15 17:05:16 UTC (rev 3715)
@@ -18,7 +18,6 @@
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -169,44 +168,6 @@
}
/**
- * Recursively deletes a directory and all its contents
- * @param directory
- */
- public static void deleteDirectory(File directory)
- {
- if (directory.isDirectory() && directory.exists())
- {
- // For each file in the directory run cleanup
- for (File file : directory.listFiles())
- {
- if (file.isDirectory())
- {
- // A nested directory, recurse
- deleteDirectory(file);
- }
- else
- {
- // Just a file delete it
- if (!file.delete())
- {
- throw new RuntimeException("Failed to delete file: " + file);
- }
- }
- }
- // Delete the directory
- if (!directory.delete())
- {
- throw new RuntimeException("Failed to delete directory: " + directory);
- }
- }
- else
- {
- throw new RuntimeException("Unable to delete directory: " + directory
- + ". It is either not a directory or does not exist.");
- }
- }
-
- /**
* Helper method to run a specified task and automatically handle the closing of the stream.
*
* @param <S>
Added: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/TestIOUtil.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/TestIOUtil.java (rev 0)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/TestIOUtil.java 2009-11-15 17:05:16 UTC (rev 3715)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.jboss.shrinkwrap.impl.base;
+
+import java.io.File;
+
+/**
+ * IOUtil
+ *
+ * Inport/export utilities for test classes
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class TestIOUtil
+{
+ //-------------------------------------------------------------------------------------||
+ // Constructor ------------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Internal constructor; should not be called
+ */
+ private TestIOUtil()
+ {
+ throw new UnsupportedOperationException("No instances should be created; stateless class");
+ }
+
+ //-------------------------------------------------------------------------------------||
+ // Functional Methods -----------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Recursively deletes a directory and all its contents
+ * @param directory
+ */
+ public static void deleteDirectory(final File directory)
+ {
+ if (directory.isDirectory() && directory.exists())
+ {
+ // For each file in the directory run cleanup
+ for (File file : directory.listFiles())
+ {
+ if (file.isDirectory())
+ {
+ // A nested directory, recurse
+ deleteDirectory(file);
+ }
+ else
+ {
+ // Just a file delete it
+ if (!file.delete())
+ {
+ throw new RuntimeException("Failed to delete file: " + file);
+ }
+ }
+ }
+ // Delete the directory
+ if (!directory.delete())
+ {
+ throw new RuntimeException("Failed to delete directory: " + directory);
+ }
+ }
+ else
+ {
+ throw new RuntimeException("Unable to delete directory: " + directory
+ + ". It is either not a directory or does not exist.");
+ }
+ }
+}
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java 2009-11-15 15:29:06 UTC (rev 3714)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExplodedExporterTestCase.java 2009-11-15 17:05:16 UTC (rev 3715)
@@ -23,12 +23,15 @@
import java.io.InputStream;
import java.util.logging.Logger;
+import junit.framework.TestCase;
+
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.Path;
import org.jboss.shrinkwrap.api.exporter.ArchiveExportException;
import org.jboss.shrinkwrap.api.exporter.ExplodedExporter;
+import org.jboss.shrinkwrap.impl.base.TestIOUtil;
import org.jboss.shrinkwrap.impl.base.io.IOUtil;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.junit.Assert;
@@ -163,7 +166,6 @@
{
log.info("testExportExplodedRequiresValidDirectory");
final File nonDirectory = new File(this.getTarget(), "tempFile.txt");
- nonDirectory.createNewFile();
Archives.create("test.jar", ExplodedExporter.class).exportExploded(nonDirectory);
}
@@ -177,7 +179,8 @@
final File directory = createTempDirectory("testExportExplodedOutpuDirCreationFails");
// Will cause the creation of Archive directory to fail
final File existingFile = new File(directory, NAME_ARCHIVE);
- existingFile.createNewFile();
+ final boolean created = existingFile.createNewFile();
+ TestCase.assertEquals("Could not create test file",true, created);
Archives.create(NAME_ARCHIVE, ExplodedExporter.class).exportExploded(directory);
}
@@ -216,7 +219,7 @@
final File directory = new File(this.getTarget(), "someNonExistentDirectory");
if (directory.exists())
{
- IOUtil.deleteDirectory(directory);
+ TestIOUtil.deleteDirectory(directory);
}
Assert.assertTrue("Precondition Failure: Directory should not exist: " + directory, !directory.exists());
return directory;
Modified: shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExportTestBase.java
===================================================================
--- shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExportTestBase.java 2009-11-15 15:29:06 UTC (rev 3714)
+++ shrinkwrap/trunk/impl-base/src/test/java/org/jboss/shrinkwrap/impl/base/exporter/ExportTestBase.java 2009-11-15 17:05:16 UTC (rev 3715)
@@ -20,13 +20,15 @@
import java.net.URISyntaxException;
import java.util.logging.Logger;
+import junit.framework.TestCase;
+
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.Asset;
import org.jboss.shrinkwrap.api.Path;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.TestIOUtil;
import org.jboss.shrinkwrap.impl.base.asset.ClassLoaderAsset;
-import org.jboss.shrinkwrap.impl.base.io.IOUtil;
import org.jboss.shrinkwrap.impl.base.path.BasicPath;
import org.junit.Assert;
@@ -117,10 +119,12 @@
log.info("Temp Directory: " + tempDirectory.getCanonicalPath());
if (tempDirectory.exists())
{
- IOUtil.deleteDirectory(tempDirectory);
+ TestIOUtil.deleteDirectory(tempDirectory);
}
Assert.assertTrue("Temp directory should be clear before start", !tempDirectory.exists());
- tempDirectory.mkdirs();
+ final boolean created = tempDirectory.mkdirs();
+ TestCase.assertEquals("Could not create temp directory for tests: " + tempDirectory.getAbsolutePath(), true,
+ created);
return tempDirectory;
}
More information about the jboss-svn-commits
mailing list