62,634
社区成员




package net.wargreytest.io;
import net.wargrey.application.ExceptionManager;
import net.wargrey.io.DirectoryNotFoundException;
import java.io.File;
import junit.framework.TestCase;
import net.wargrey.io.Directory;
public class DirectoryTest extends TestCase{
private Directory [] testCases=new Directory[4];
private Directory root=null;
private Directory home=null;
private Directory cur=null;
private Directory notexist=null;
@Override
public void setUp(){
try{
this.testCases[0]=this.root=new Directory("/");
this.testCases[1]=this.home=new Directory("/home/Estelle");
this.testCases[2]=this.cur=new Directory(".");
this.testCases[3]=this.notexist=new Directory("/home/Estelle/Yoshua");
}catch(Exception npe){
fail("Initail failure!");
}
}
public void testListRoots(){//测试静态方法
Directory [] roots=Directory.listRoots();
assertEquals("The number of roots is 1 on linux",roots.length,1);
}
public void testConstructorExceptions(){//测试构造异常
Directory vim=null;
try{
vim=new Directory("/home/Estelle/Programs/bin/vim");
}catch(NullPointerException npe){
assertNull("Is there should be null?",vim);
}catch(DirectoryNotFoundException dnfe){
assertNull("Directory not found!",vim);
}
}
public void testGetParentDirectory(){//测试普通方法示例
String [] results={null,"/home","/home/Estelle/Frameworks","/home/Estelle"};
String [] alerts={"Parent of root should be null","","",""};
for (int i=0;i<testCases.length;i++){
Directory parent=testCases[i].getParentDirectory();
if (results[i]==null){
assertNull(alerts[i],parent);
}else{
assertNotNull(alerts[i],parent);
assertEquals(alerts[i],parent.toString(),results[i]);
}
}
}
}