《重构》 — Java示例:影片出租店程序(5、单元测试)

示例:影片出租店程序(单元测试)
代码:
package Movie_Ref;

import junit.framework.TestCase;

public class MovieTest extends TestCase {

    protected void setUp() throws Exception {
        super.setUp();
    }
   
    public void testStatement() {
        String S = "Rental Record for ZhangSan/n"
            + "/taaa/t2.0/n"
            + "/tbbb/t3.0/n"
            + "/tccc/t1.5/n"
            + "Amount owed is 6.5/n"
            + "You earned 3 frequent renter points";
       
        Customer customer = new Customer("ZhangSan");
       
        customer.addRental(new Rental(new Movie("aaa",Movie.REGULAR),1));
        customer.addRental(new Rental(new Movie("bbb",Movie.NEW_RELEASE),1));   
        customer.addRental(new Rental(new Movie("ccc",Movie.CHILDRENS),1));   
       
        String S1 = customer.statement();
               
        assertTrue(S.equals(S1));
       
        //System.out.println(S);       
        //System.out.println(S1);       
    }
    public void testHtmlStatement() {
        String S = "<H1>Rentals for <EM>ZhangSan</EM></H1><P>/n"
            + "aaa: 2.0<BR>/n"
            + "bbb: 3.0<BR>/n"
            + "ccc: 1.5<BR>/n"
            + "<P>You owe <EM>6.5</EM><P>/n"
            + "On this rental you earned <EM>3 </EM> frequent renter points<P>";
       
        Customer customer = new Customer("ZhangSan");
       
        customer.addRental(new Rental(new Movie("aaa",Movie.REGULAR),1));
        customer.addRental(new Rental(new Movie("bbb",Movie.NEW_RELEASE),1));   
        customer.addRental(new Rental(new Movie("ccc",Movie.CHILDRENS),1));   
       
        String S1 = customer.htmlStatement();
               
        assertTrue(S.equals(S1));
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值