java - Simple Junit Test method for this Class using mocks/stubs -


im new junit, , wondering if give me example of of how write unit test method? of if point me in right direction, unsure use of mocks , stubs, if need them in particular situation, when use them ect...

public static string[] getdirectorylist(string parentpath, string directorynames) {     final list<string> directorylist= new arraylist<string>();     string[] directoryarray = directorynames.split(", ");      for(string directories : directoryarray){         directories.trim();         directories = parentpath + directories;         directorylist.add(directories);     }      if (directorylist.size()==0)         return null;     else         return directorylist.toarray(new string[directorylist.size()]);  } 

in case don't need mock.

    @test     public void testwithonedirectory() {        string[] directorylist = getdirectorylist("/", "home");        assert.assertarrayequals(" sould equal on dir",one_dir, directorylist);     }      @test     public void testshouldthrowexception{        try{           string[] directorylist = getdirectorylist("/", null);           fail("should throw exception when arg null");        }        catch(exception e) {}     } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -