[jboss-svn-commits] JBoss Common SVN: r3494 - declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 26 20:51:14 EDT 2009


Author: ALRubinger
Date: 2009-08-26 20:51:13 -0400 (Wed, 26 Aug 2009)
New Revision: 3494

Removed:
   declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestUtil.java
Modified:
   declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestBase.java
Log:
[TMPARCH-22] Some more test consolidation

Modified: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestBase.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestBase.java	2009-08-27 00:49:03 UTC (rev 3493)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestBase.java	2009-08-27 00:51:13 UTC (rev 3494)
@@ -25,6 +25,7 @@
 import org.jboss.declarchive.api.Asset;
 import org.jboss.declarchive.api.Path;
 import org.jboss.declarchive.impl.base.MemoryMapArchiveImpl;
+import org.jboss.declarchive.impl.base.Validate;
 import org.jboss.declarchive.impl.base.asset.ClassLoaderAsset;
 import org.jboss.declarchive.impl.base.io.IOUtil;
 import org.jboss.declarchive.impl.base.path.BasicPath;
@@ -57,7 +58,7 @@
     * @return A new Archive<T> instance.
     */
    protected abstract Archive<T> createNewArchive();
-   
+
    /**
     * Simple printout of the tested archive. 
     */
@@ -266,10 +267,8 @@
 
       byte[] addedData = IOUtil.asByteArray(asset.getStream());
       byte[] fetchedData = IOUtil.asByteArray(archive.get(location).getStream());
-      
-      Assert.assertTrue(
-            "Asset should be returned from path: " + location.get(), 
-            Arrays.equals(addedData, fetchedData));
+
+      Assert.assertTrue("Asset should be returned from path: " + location.get(), Arrays.equals(addedData, fetchedData));
    }
 
    /**
@@ -306,16 +305,17 @@
       archive.add(location, asset).add(locationTwo, assetTwo);
 
       Map<Path, Asset> content = archive.getContent();
-      
-      Assert.assertTrue(
-            "Asset should existing in content with key: " + location.get(), 
-            ArchiveTestUtil.compareAssets(asset, content.get(location)));
-      
-      Assert.assertTrue(
-            "Asset should existing in content with key: " + locationTwo.get(), 
-            ArchiveTestUtil.compareAssets(assetTwo, content.get(locationTwo)));
+
+      final Asset asset1 = content.get(location);
+      final Asset asset2 = content.get(locationTwo);
+
+      Assert.assertTrue("Asset should existing in content with key: " + location.get(), this.compareAssets(asset,
+            asset1));
+
+      Assert.assertTrue("Asset should existing in content with key: " + locationTwo.get(), this.compareAssets(assetTwo,
+            asset2));
    }
-   
+
    /**
     * Ensure adding an archive to a path requires a path
     * @throws Exception
@@ -387,13 +387,11 @@
       sourceArchive.add(location, asset).add(locationTwo, assetTwo);
 
       archive.addContents(sourceArchive);
-      Assert.assertTrue(
-            "Asset should have been added to path: " + location.get(), 
-            ArchiveTestUtil.compareAssets(archive.get(location), asset));
-      
-      Assert.assertTrue(
-            "Asset should have been added to path: " + location.get(), 
-            ArchiveTestUtil.compareAssets(archive.get(locationTwo), assetTwo));
+      Assert.assertTrue("Asset should have been added to path: " + location.get(), this.compareAssets(archive
+            .get(location), asset));
+
+      Assert.assertTrue("Asset should have been added to path: " + location.get(), this.compareAssets(archive
+            .get(locationTwo), assetTwo));
    }
 
    /**
@@ -419,13 +417,11 @@
       Path expectedPath = new BasicPath(baseLocation, location);
       Path expectedPathTwo = new BasicPath(baseLocation, locationTwo);
 
-      Assert.assertTrue(
-            "Asset should have been added to path: " + expectedPath.get(), 
-            ArchiveTestUtil.compareAssets(archive.get(expectedPath), asset));
-      
-      Assert.assertTrue(
-            "Asset should have been added to path: " + expectedPathTwo.getClass(), 
-            ArchiveTestUtil.compareAssets(archive.get(expectedPathTwo), assetTwo));
+      Assert.assertTrue("Asset should have been added to path: " + expectedPath.get(), this.compareAssets(archive
+            .get(expectedPath), asset));
+
+      Assert.assertTrue("Asset should have been added to path: " + expectedPathTwo.getClass(), this.compareAssets(
+            archive.get(expectedPathTwo), assetTwo));
    }
 
    /**
@@ -468,13 +464,37 @@
       Path expectedPath = new BasicPath(new BasicPath(baseLocation, sourceArchive.getName()), location);
       Path expectedPathTwo = new BasicPath(new BasicPath(baseLocation, sourceArchive.getName()), locationTwo);
 
-      Assert.assertTrue(
-            "Asset should have been added to path: " + expectedPath.get(), 
-            ArchiveTestUtil.compareAssets(archive.get(expectedPath), asset));
-      
-      Assert.assertTrue(
-            "Asset should have been added to path: " + expectedPathTwo.get(), 
-            ArchiveTestUtil.compareAssets(archive.get(expectedPathTwo), assetTwo));
+      Assert.assertTrue("Asset should have been added to path: " + expectedPath.get(), this.compareAssets(archive
+            .get(expectedPath), asset));
+
+      Assert.assertTrue("Asset should have been added to path: " + expectedPathTwo.get(), this.compareAssets(archive
+            .get(expectedPathTwo), assetTwo));
    }
 
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Compare two Asset with each other.
+    * <br/>
+    * Does not check instances but content.
+    * 
+    * @param one Asset to compare
+    * @param two Asset to compare
+    * @return true if they are equal
+    * @throws IllegalArgumentException If either asset is not specified
+    */
+   private boolean compareAssets(final Asset one, final Asset two) throws IllegalArgumentException
+   {
+      // Precondition check
+      Validate.notNull(one, "Asset one must be specified");
+      Validate.notNull(two, "Asset two must be specified");
+
+      byte[] oneData = IOUtil.asByteArray(one.getStream());
+      byte[] twoData = IOUtil.asByteArray(two.getStream());
+
+      return Arrays.equals(oneData, twoData);
+   }
+
 }

Deleted: declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestUtil.java
===================================================================
--- declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestUtil.java	2009-08-27 00:49:03 UTC (rev 3493)
+++ declarchive/trunk/impl-base/src/test/java/org/jboss/declarchive/impl/base/test/ArchiveTestUtil.java	2009-08-27 00:51:13 UTC (rev 3494)
@@ -1,70 +0,0 @@
-/*
- * 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.declarchive.impl.base.test;
-
-import java.util.Arrays;
-
-import org.jboss.declarchive.api.Asset;
-import org.jboss.declarchive.impl.base.io.IOUtil;
-
-/**
- * ArchiveTestUtil
- * 
- * Helper to compare Assets.
- *
- * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
- * @version $Revision: $
- */
-class ArchiveTestUtil
-{
-   //-------------------------------------------------------------------------------------||
-   // Class Members ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   //-------------------------------------------------------------------------------------||
-   // Instance Members -------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   //-------------------------------------------------------------------------------------||
-   // Constructor ------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Internal constructor; should not be called
-    */
-   private ArchiveTestUtil()
-   {
-      throw new UnsupportedOperationException("No instances should be created; stateless class");
-   }
-   
-   /**
-    * Compare two Asset with each other.
-    * <br/>
-    * Does not check instances but content.
-    * 
-    * @param one Asset to compare
-    * @param two Asset to compare
-    * @return true if they are equal
-    */
-   static boolean compareAssets(Asset one, Asset two) 
-   {
-      byte[] oneData = IOUtil.asByteArray(one.getStream());
-      byte[] twoData = IOUtil.asByteArray(two.getStream());
-      
-      return Arrays.equals(oneData, twoData);
-   }
-}



More information about the jboss-svn-commits mailing list