JUnit testing returns an error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatos
    New Member
    • Aug 2007
    • 105

    JUnit testing returns an error

    I have the class TableCollection which creates tables for data store in the given direcoty, the method which reads this goes like this.
    Code:
    public void read(String dirname,String regex) throws IOException{
    where dirname is the directory name and regex is a regular expression which allows the read method to only take files in that directory which matches that expression.
    On my JUnit testing I have the following test:
    The test tests whether the path or directory is valid or not
    Code:
      @Test  //2 
      
      public void testPathInvalid() throws IOException {
        TableCollection all = new TableCollection();
        try {
          all.read("junk/file","");
        } 
        catch
          (FileNotFoundException e) {
          return;
        }
        fail("FileNotFoundException expected");
        
      }
    
    //This returns the following error
     java.lang.NullPointerException from line:61 i.e all.read("junk/file","");
    On my read method must I include statements which firsts check whether the path in valid or not and throws an exception?
  • thatos
    New Member
    • Aug 2007
    • 105

    #2
    I found the solution to this, I placed the following statements on the read method
    Code:
        File directory = new File(dirname);
        boolean exists = directory.exists();
        if(!exists){
          throw new FileNotFoundException();
        }

    Comment

    Working...