Clover coverage report - Maven Clover report
Coverage timestamp: Sun Mar 18 2007 17:42:32 CET
file stats: LOC: 56   Methods: 1
NCLOC: 32   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClassBaseDirExtractor.java 100% 100% 100% 100%
coverage
 1    package com.agical.rmock.core.find.iterator;
 2   
 3    import java.io.File;
 4    import java.net.URISyntaxException;
 5    import java.net.URL;
 6    import java.util.StringTokenizer;
 7   
 8    import com.agical.rmock.core.find.UnsupportedClassLocationException;
 9    import com.agical.rmock.core.util.StringUtils;
 10   
 11    /**
 12    * @author brolund
 13    *
 14    * (c) 2005 Agical AB
 15    */
 16    public class ClassBaseDirExtractor {
 17   
 18    /**
 19    * Finds the base directory of the given class
 20    * @param clazz The class to search from
 21    * @return The base directory of the class (with all packages removed from the path).
 22    * @throws URISyntaxException
 23    */
 24  11 public File getDir(Class clazz) {
 25   
 26  11 String className = clazz.getName();
 27  11 int dotIndex = className.lastIndexOf('.');
 28  11 if (dotIndex > -1) {
 29  10 className = className.substring(dotIndex+1)+".class";
 30    } else {
 31  1 className = className + ".class";
 32    }
 33   
 34    // get a URL to the actual file for this class
 35  11 URL resource = clazz.getResource(className);
 36  11 if(!resource.getProtocol().equals("file")) {
 37  1 throw new UnsupportedClassLocationException("The class location ("+resource+") is not supported. Currently tests can only be discovered on the filesystem!");
 38    }
 39  10 String file = resource.getFile();
 40   
 41    // Remove %20 if the URL class doesn't
 42  10 String fileNameWithNormalSpaces = StringUtils.replace( file, "%20", " " );
 43  10 File classDirectory = new File(fileNameWithNormalSpaces);
 44  10 String name = clazz.getPackage()==null?"":clazz.getPackage().getName();
 45   
 46  10 StringTokenizer stringTokenizer = new StringTokenizer(name, ".");
 47  10 int tokens = stringTokenizer.countTokens();
 48   
 49    // iterate to the root of all classes
 50  10 for (int i = 0; i <= tokens; i++){
 51  60 classDirectory = classDirectory.getParentFile();
 52    }
 53  10 return classDirectory;
 54    }
 55   
 56    }