以下是TestList类的完整代码, 现在想为class TestList中的print方法写JUnit Test Case, 请问Test Case的代码应如何写?
package com.testlist;import java.util.* ;interface Book
{
// 书的价格、书的名字、书的信息
public float getPrice() ;
public String getName() ;
public String getInfo() ;
}
class ComputerBook implements Book
{
private String name ;
private float price ;
private String info ; public ComputerBook(String name,float price,String info)
{
this.setName(name) ;
this.setPrice(price) ;
this.setInfo(info) ;
} public String getName()
{
return this.name ;
}
public float getPrice()
{
return this.price ;
}
public String getInfo()
{
return this.info ;
}
public void setName(String name)
{
this.name = name ;
}
public void setPrice(float price)
{
this.price = price ;
}
public void setInfo(String info)
{
this.info = info ;
}
public String toString()
{
return "电脑书:书名:"+this.getName()+",价格:"+this.price+",简介:"+this.getInfo() ;
}
};class BookShop
{
private String name ;
// 一个书店包含多种书
private List allBooks ; public BookShop()
{
this.allBooks = new ArrayList() ;
}
public BookShop(String name)
{
this() ;
this.setName(name) ;
} // 得到全部的书
public List getAllBooks()
{
return this.allBooks ;
} public void append(Book book)
{
this.allBooks.add(book) ;
} public void setName(String name)
{
this.name = name ;
}
public String getName()
{
return this.name ;
}
};public class TestList
{
public static void main(String args[])
{
Book b1 = new ComputerBook("JAVA",65.0f,"JAVA 语言的核心技术") ;
Book b2 = new ComputerBook("C++",50.0f,"C++ 语言的核心技术") ;
Book b3 = new ComputerBook("Linux",50.0f,"服务器搭建") ; BookShop bs = new BookShop("网上书店") ;
bs.append(b1) ;
bs.append(b2) ;
bs.append(b3) ; print(bs.getAllBooks()) ;
}
        //怎样为下面的这个print方法写JUnit Test Case
public static void print(List all)
{
Iterator iter = all.iterator() ;
while(iter.hasNext())
{
Book b = (Book)iter.next() ;
System.out.println(b) ;
}
}
};