Author: kono
Date: 2012-04-17 16:21:28 -0700 (Tue, 17 Apr 2012)
New Revision: 28872

Added:
   core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/
   
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/AbstractInputStreamTaskFactoryTest.java
   
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/InputStreamTaskFactoryTest.java
Modified:
   core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
   
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/read/AbstractInputStreamTaskFactory.java
Log:
refs #865 New test cases had been added to io-api.

Modified: 
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
===================================================================
--- 
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java    
    2012-04-17 23:00:34 UTC (rev 28871)
+++ 
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java    
    2012-04-17 23:21:28 UTC (rev 28872)
@@ -5,7 +5,6 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URI;
-import java.net.URLConnection;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -14,10 +13,11 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * This is meant to be an basic implementation of {@link CyFileFilter} that 
can either be
- * used directly or extended to provide different acceptance criteria. Only 
the 
- * accepts() methods may be overridden.
- * @CyAPI.Abstract.Class 
+ * This is meant to be an basic implementation of {@link CyFileFilter} that can
+ * either be used directly or extended to provide different acceptance 
criteria.
+ * Only the accepts() methods may be overridden.
+ * 
+ * @CyAPI.Abstract.Class
  */
 public class BasicCyFileFilter implements CyFileFilter {
 
@@ -30,13 +30,20 @@
        private static final Logger logger = 
LoggerFactory.getLogger(BasicCyFileFilter.class);
 
        /**
-        * Creates a file filter from the specified arguments. 
-        * Note that a "." before the extension is not needed and will be 
ignored.
-        * @param extensions The set of valid extensions for this filter.
-        * @param contentTypes The set of valid MIME content types that this 
filter should recognize. 
-        * @param description A human readable description of the filter.
-        * @param category The type of data this filter is meant to support.
-        * @param streamUtil An instance of the StreamUtil service.
+        * Creates a file filter from the specified arguments. Note that a "."
+        * before the extension is not needed and will be ignored.
+        * 
+        * @param extensions
+        *            The set of valid extensions for this filter.
+        * @param contentTypes
+        *            The set of valid MIME content types that this filter 
should
+        *            recognize.
+        * @param description
+        *            A human readable description of the filter.
+        * @param category
+        *            The type of data this filter is meant to support.
+        * @param streamUtil
+        *            An instance of the StreamUtil service.
         */
        public BasicCyFileFilter(final Set<String> extensions, final 
Set<String> contentTypes, final String description,
                        final DataCategory category, StreamUtil streamUtil) {
@@ -49,6 +56,7 @@
 
                for (String ex : extensions)
                        d += "*." + ex + ", ";
+
                d = d.substring(0, d.length() - 2);
                d += ")";
 
@@ -58,23 +66,29 @@
        }
 
        /**
-        * Creates a file filter from the specified arguments. 
-        * Note that a "." before the extension is not needed and will be 
ignored.
-        * @param extensions The set of valid extensions for this filter.
-        * @param contentTypes The set of valid MIME content types that this 
filter should recognize. 
-        * @param description A human readable description of the filter.
-        * @param category The type of data this filter is meant to support.
-        * @param streamUtil An instance of the StreamUtil service.
+        * Creates a file filter from the specified arguments. Note that a "."
+        * before the extension is not needed and will be ignored.
+        * 
+        * @param extensions
+        *            The set of valid extensions for this filter.
+        * @param contentTypes
+        *            The set of valid MIME content types that this filter 
should
+        *            recognize.
+        * @param description
+        *            A human readable description of the filter.
+        * @param category
+        *            The type of data this filter is meant to support.
+        * @param streamUtil
+        *            An instance of the StreamUtil service.
         */
-       public BasicCyFileFilter(final String[] extensions,
-                       final String[] contentTypes, final String description,
+       public BasicCyFileFilter(final String[] extensions, final String[] 
contentTypes, final String description,
                        final DataCategory category, StreamUtil streamUtil) {
                this(createSet(extensions), createSet(contentTypes), 
description, category, streamUtil);
        }
 
        private static Set<String> createSet(String[] values) {
                Set<String> set = new HashSet<String>();
-               for ( String v : values )
+               for (String v : values)
                        set.add(v);
                return set;
        }
@@ -85,17 +99,17 @@
        public boolean accepts(URI uri, DataCategory category) {
 
                // Check data category
-               if (category != this.category) 
+               if (category != this.category)
                        return false;
 
                if (extensionsMatch(uri))
                        return true;
                else
                        return false;
-               
+
        }
 
-       private boolean extensionsMatch(URI uri){
+       private boolean extensionsMatch(URI uri) {
                final String extension = getExtension(uri.toString());
                if (extension != null && extensions.contains(extension))
                        return true;
@@ -104,12 +118,16 @@
        }
 
        /**
-        * This method always returns false in this particular implementation.  
You must extend
-        * this class and override this method to get alternative behavior. 
Ideally this method
-        * would return true if this class is capable of processing the 
specified InputStream.
-        * @param stream The stream that references the file we'd like to read.
-        * @param category The type of input that we're considering. 
-        * @return Always returns false in this particular implementation. 
+        * This method always returns false in this particular implementation. 
You
+        * must extend this class and override this method to get alternative
+        * behavior. Ideally this method would return true if this class is 
capable
+        * of processing the specified InputStream.
+        * 
+        * @param stream
+        *            The stream that references the file we'd like to read.
+        * @param category
+        *            The type of input that we're considering.
+        * @return Always returns false in this particular implementation.
         */
        public boolean accepts(InputStream stream, DataCategory category) {
                return false;
@@ -145,15 +163,16 @@
 
        /**
         * Returns a human readable description of this class.
+        * 
         * @return a human readable description of this class.
         */
        @Override
        public String toString() {
                String s = description + " [category: " + category + "]  
[extensions: ";
-               for ( String ext : extensions )
+               for (String ext : extensions)
                        s += ext + ",";
                s += "]   [contentTypes: ";
-               for ( String c : contentTypes )
+               for (String c : contentTypes)
                        s += c + ",";
                s += "]";
 
@@ -161,10 +180,12 @@
        }
 
        /**
-        * Returns a string of the characters following the last '.' in the
-        * input string, which is to say the file extension assuming that the
-        * input string represents a file name. Will return null if no '.' is 
found.
-        * @param filename the file name as a string.
+        * Returns a string of the characters following the last '.' in the 
input
+        * string, which is to say the file extension assuming that the input 
string
+        * represents a file name. Will return null if no '.' is found.
+        * 
+        * @param filename
+        *            the file name as a string.
         * @return a string representing the file extension of the input string.
         */
        protected final String getExtension(String filename) {
@@ -181,15 +202,18 @@
 
        /**
         * Returns a string containing the specified number of lines from the
-        * beginning of the file.  This is useful for testing input streams. 
-        * @param stream the input stream from which to read the header.
-        * @param numLines the number of lines from the beginning of the file.
+        * beginning of the file. This is useful for testing input streams.
+        * 
+        * @param stream
+        *            the input stream from which to read the header.
+        * @param numLines
+        *            the number of lines from the beginning of the file.
         * @return a string containing the specified number of lines from the
-        * beginning of the file.
+        *         beginning of the file.
         */
        protected final String getHeader(InputStream stream, int numLines) {
-               
-               String header; 
+
+               String header;
                BufferedReader br = new BufferedReader(new 
InputStreamReader(stream));
 
                try {
@@ -199,7 +223,10 @@
                        header = "";
                } finally {
                        if (br != null)
-                               try { br.close(); } catch (IOException e) {}
+                               try {
+                                       br.close();
+                               } catch (IOException e) {
+                               }
 
                        br = null;
                }
@@ -207,8 +234,7 @@
                return header;
        }
 
-       private final String parseHeader(BufferedReader bufferedReader, int 
numLines)
-                       throws IOException {
+       private final String parseHeader(BufferedReader bufferedReader, int 
numLines) throws IOException {
                StringBuilder header = new StringBuilder();
 
                try {

Modified: 
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/read/AbstractInputStreamTaskFactory.java
===================================================================
--- 
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/read/AbstractInputStreamTaskFactory.java
      2012-04-17 23:00:34 UTC (rev 28871)
+++ 
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/read/AbstractInputStreamTaskFactory.java
      2012-04-17 23:21:28 UTC (rev 28872)
@@ -5,17 +5,24 @@
 import org.cytoscape.io.CyFileFilter;
 
 public abstract class AbstractInputStreamTaskFactory implements 
InputStreamTaskFactory {
+       
        private CyFileFilter fileFilter;
 
-       public AbstractInputStreamTaskFactory(CyFileFilter fileFilter) {
+       public AbstractInputStreamTaskFactory(final CyFileFilter fileFilter) {
                this.fileFilter = fileFilter;
        }
        
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public boolean isReady(InputStream is, String inputName) {
                return true;
        }
 
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public CyFileFilter getFileFilter() {
                return fileFilter;

Added: 
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/AbstractInputStreamTaskFactoryTest.java
===================================================================
--- 
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/AbstractInputStreamTaskFactoryTest.java
                          (rev 0)
+++ 
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/AbstractInputStreamTaskFactoryTest.java
  2012-04-17 23:21:28 UTC (rev 28872)
@@ -0,0 +1,28 @@
+package org.cytoscape.io.read;
+
+import static org.junit.Assert.*;
+
+import org.cytoscape.io.CyFileFilter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class AbstractInputStreamTaskFactoryTest {
+
+       protected InputStreamTaskFactory taskFactory;
+       protected CyFileFilter fileFilter;
+
+       @Test
+       public void testAbstractInputStreamTaskFactory() {
+               assertNotNull(taskFactory);
+               assertNotNull(fileFilter);
+       }
+
+       @Test
+       public abstract void testIsReady();
+
+       @Test
+       public void testGetFileFilter() {
+               assertEquals(fileFilter, taskFactory.getFileFilter());
+       }
+}

Added: 
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/InputStreamTaskFactoryTest.java
===================================================================
--- 
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/InputStreamTaskFactoryTest.java
                          (rev 0)
+++ 
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/read/InputStreamTaskFactoryTest.java
  2012-04-17 23:21:28 UTC (rev 28872)
@@ -0,0 +1,53 @@
+package org.cytoscape.io.read;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.cytoscape.io.BasicCyFileFilter;
+import org.cytoscape.io.CyFileFilter;
+import org.cytoscape.io.DataCategory;
+import org.cytoscape.io.util.StreamUtil;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskIterator;
+import org.junit.Before;
+
+public class InputStreamTaskFactoryTest extends 
AbstractInputStreamTaskFactoryTest {
+
+       private StreamUtil streamUtil = mock(StreamUtil.class);
+
+       @Before
+       public void setUp() throws Exception {
+               Set<String> extensions = new HashSet<String>();
+               extensions.add("xml");
+               Set<String> contentTypes = new HashSet<String>();
+               String description = "test filter";
+               DataCategory category = DataCategory.NETWORK;
+               this.fileFilter = new BasicCyFileFilter(extensions, 
contentTypes, description, category, streamUtil);
+               this.taskFactory = new DummyInputStreamTaskFactory(fileFilter);
+       }
+
+
+       @Override
+       public void testIsReady() {
+               assertTrue(taskFactory.isReady(null, null));
+       }
+       
+       private static final class DummyInputStreamTaskFactory extends 
AbstractInputStreamTaskFactory {
+
+               public DummyInputStreamTaskFactory(final CyFileFilter 
fileFilter) {
+                       super(fileFilter);
+               }
+
+               private Task initialTasks = mock(Task.class);
+
+               @Override
+               public TaskIterator createTaskIterator(InputStream is, String 
inputName) {
+                       return new TaskIterator(initialTasks );
+               }
+               
+       }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to