You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2012/02/10 00:10:09 UTC

svn commit: r1242599 - /commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java

Author: ggregory
Date: Thu Feb  9 23:10:09 2012
New Revision: 1242599

URL: http://svn.apache.org/viewvc?rev=1242599&view=rev
Log:
Replace call to JUnit assert method with custom method to compare longs with a delta. The previous code compared floats.

Modified:
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java?rev=1242599&r1=1242598&r2=1242599&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/LastModifiedTests.java Thu Feb  9 23:10:09 2012
@@ -20,24 +20,35 @@ import junit.framework.AssertionFailedEr
 
 import org.apache.commons.vfs2.Capability;
 import org.apache.commons.vfs2.FileObject;
+import org.junit.Assert;
 
 /**
  * Test cases for getting and setting file last modified time.
- *
+ * 
  * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  */
-public class LastModifiedTests
-    extends AbstractProviderTestCase
+public class LastModifiedTests extends AbstractProviderTestCase
 {
+    private void asssertDelta(String message, final long expected, final long actual, final long delta)
+    {
+        if (expected == actual)
+        {
+            return;
+        }
+        if (!(Math.abs(expected - actual) <= delta))
+        {
+            Assert.fail(String.format("%s expected=%d, actual=%d, delta=%d", new Long(expected), new Long(actual)));
+        }
+    }
+
     /**
      * Returns the capabilities required by the tests of this test case.
      */
     @Override
     protected Capability[] getRequiredCaps()
     {
-        return new Capability[]{
-            Capability.GET_LAST_MODIFIED
-        };
+        return new Capability[]
+        { Capability.GET_LAST_MODIFIED };
     }
 
     /**
@@ -51,8 +62,8 @@ public class LastModifiedTests
 
         // TODO - switch this on
         // Try a folder
-        //final FileObject folder = getReadFolder().resolveFile( "dir1" );
-        //folder.getContent().getLastModifiedTime();
+        // final FileObject folder = getReadFolder().resolveFile( "dir1" );
+        // folder.getContent().getLastModifiedTime();
     }
 
     /**
@@ -72,15 +83,13 @@ public class LastModifiedTests
             try
             {
                 assertEquals("Check 1", now, lastModifiedTime, lastModTimeAccuracy);
-            }
-            catch (AssertionFailedError e)
+            } catch (AssertionFailedError e)
             {
                 // on linux ext3 the above check is not necessarily true
                 if (lastModTimeAccuracy < 1000L)
                 {
-                    assertEquals("Check 2", now, lastModifiedTime, 1000L);
-                }
-                else
+                    asssertDelta("Check 2", now, lastModifiedTime, 1000L);
+                } else
                 {
                     throw e;
                 }
@@ -97,15 +106,13 @@ public class LastModifiedTests
             try
             {
                 assertEquals("Check 3", now, lastModifiedTime, lastModTimeAccuracy);
-            }
-            catch (AssertionFailedError e)
+            } catch (AssertionFailedError e)
             {
                 // on linux ext3 the above check is not necessarily true
                 if (lastModTimeAccuracy < 1000L)
                 {
-                    assertEquals("Check 4", now, lastModifiedTime, 1000L);
-                }
-                else
+                    asssertDelta("Check 4", now, lastModifiedTime, 1000L);
+                } else
                 {
                     throw e;
                 }