commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject svn commit: r278632 - /jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java
Date Sun, 04 Sep 2005 21:51:05 GMT
Author: jkeyes
Date: Sun Sep  4 14:50:59 2005
New Revision: 278632

URL: http://svn.apache.org/viewcvs?rev=278632&view=rev
Log:
- added tests (100% clover coverage)

Modified:
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java?rev=278632&r1=278631&r2=278632&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java
(original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/validation/FileValidatorTest.java
Sun Sep  4 14:50:59 2005
@@ -1,5 +1,5 @@
-/**
- * Copyright 2004 The Apache Software Foundation
+/*
+ * Copyright 2004-2005 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,8 +22,14 @@
 
 import junit.framework.TestCase;
 
+/**
+ * JUnit test case for the FileValidator.
+ *
+ * @author Rob Oxspring
+ * @author John Keyes
+ */
 public class FileValidatorTest extends TestCase {
-    
+
     public void testValidate() throws InvalidArgumentException {
         final Object[] array = new Object[] { "src", "project.xml", "veryunlikelyfilename"};
         final List list = Arrays.asList(array);
@@ -37,11 +43,16 @@
         assertEquals(new File("veryunlikelyfilename"), i.next());
         assertFalse(i.hasNext());
     }
-    
+
     public void testValidate_Directory() {
         final Object[] array = new Object[] { "src", "project.xml"};
         final List list = Arrays.asList(array);
-        final Validator validator = FileValidator.getExistingDirectoryInstance();
+        final FileValidator validator = FileValidator.getExistingDirectoryInstance();
+
+        assertTrue("is a directory validator", validator.isDirectory());
+        assertFalse("is not a file validator", validator.isFile());
+        assertTrue("is an existing file validator", validator.isExisting());
+        assertFalse("is not a hidden file validator", validator.isHidden());
 
         try{
             validator.validate(list);
@@ -51,11 +62,61 @@
             assertEquals("project.xml",e.getMessage());
         }
     }
-    
-    public void testValidate_File() {
-        final Object[] array = new Object[] { "project.xml", "src"};
+
+    public void testValidate_ReadableFile() {
+        final Object[] array = new Object[] { "src/test/data/readable.txt", "src/test/data/notreadable.txt"};
         final List list = Arrays.asList(array);
-        final Validator validator = FileValidator.getExistingFileInstance();
+        final FileValidator validator = FileValidator.getExistingFileInstance();
+        validator.setReadable(true);
+
+        assertFalse("is not a directory validator", validator.isDirectory());
+        assertTrue("is a file validator", validator.isFile());
+        assertTrue("is an existing file validator", validator.isExisting());
+        assertFalse("is not a hidden file validator", validator.isHidden());
+        assertTrue("is a readable file validator", validator.isReadable());
+        assertFalse("is not a writable file validator", validator.isWritable());
+
+        try{
+            validator.validate(list);
+            fail("InvalidArgumentException");
+        }
+        catch(InvalidArgumentException e){
+            assertEquals("src/test/data/notreadable.txt",e.getMessage());
+        }
+    }
+
+    public void testValidate_WritableFile() {
+        final Object[] array = new Object[] { "src/test/data/writable.txt", "src/test/data/readable.txt"};
+        final List list = Arrays.asList(array);
+        final FileValidator validator = FileValidator.getExistingFileInstance();
+        validator.setWritable(true);
+
+        assertFalse("is not a directory validator", validator.isDirectory());
+        assertTrue("is a file validator", validator.isFile());
+        assertTrue("is an existing file validator", validator.isExisting());
+        assertFalse("is not a hidden file validator", validator.isHidden());
+        assertTrue("is not a readable file validator", validator.isReadable());
+        assertFalse("is a writable file validator", validator.isWritable());
+
+        try{
+            validator.validate(list);
+            fail("InvalidArgumentException");
+        }
+        catch(InvalidArgumentException e){
+            assertEquals("src/test/data/readable.txt",e.getMessage());
+        }
+    }
+
+    public void testValidate_HiddenFile() throws InvalidArgumentException {
+        final Object[] array = new Object[] { "src/test/data/hidden.txt", "src"};
+        final List list = Arrays.asList(array);
+        final FileValidator validator = FileValidator.getExistingFileInstance();
+        validator.setHidden(true);
+
+        assertFalse("is not a directory validator", validator.isDirectory());
+        assertTrue("is a file validator", validator.isFile());
+        assertTrue("is an existing file validator", validator.isExisting());
+        assertTrue("is a hidden file validator", validator.isHidden());
 
         try{
             validator.validate(list);
@@ -65,11 +126,16 @@
             assertEquals("src",e.getMessage());
         }
     }
-    
+
     public void testValidate_Existing() {
         final Object[] array = new Object[] { "project.xml", "veryunlikelyfilename"};
         final List list = Arrays.asList(array);
-        final Validator validator = FileValidator.getExistingInstance();
+        final FileValidator validator = FileValidator.getExistingInstance();
+
+        assertFalse("is not a directory validator", validator.isDirectory());
+        assertFalse("is not a file validator", validator.isFile());
+        assertTrue("is an existing file validator", validator.isExisting());
+        assertFalse("is not a hidden file validator", validator.isHidden());
 
         try{
             validator.validate(list);
@@ -77,6 +143,20 @@
         }
         catch(InvalidArgumentException e){
             assertEquals("veryunlikelyfilename",e.getMessage());
+        }
+    }
+
+    public void testValidate_File() {
+        final Object[] array = new Object[] { "project.xml", "src"};
+        final List list = Arrays.asList(array);
+        final Validator validator = FileValidator.getExistingFileInstance();
+
+        try{
+            validator.validate(list);
+            fail("InvalidArgumentException");
+        }
+        catch(InvalidArgumentException e){
+            assertEquals("src",e.getMessage());
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message