论坛首页 Java企业应用论坛

jmockit 的使用系列

浏览 1380 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2010-12-13   最后修改:2010-12-19

目标测试代码

WinportUrlService

package jmockit.target;

public interface WinportUrlService {
	boolean hasWinport(String memberId);

	String getWinportUrlThrowException(String memberId);
}

 

WinportBaseService

package jmockit.target;

public class WinportBaseService {
	public long getPostedOfferCounts(String memberId) {
		return 1000;
	}
}

 

WinportUrlServiceImpl

package jmockit.target;

public class WinportUrlServiceImpl extends WinportBaseService implements
		WinportUrlService {
	public boolean hasWinport(String memberId) {
		return true;
	}

	public String getWinportUrlThrowException(String memberId) {
		throw new RuntimeException();
	}
}

 

OfferPostAction

package jmockit.target;

public class OfferPostAction {

	private WinportUrlServiceImpl winportUrlService = new WinportUrlServiceImpl();

	public boolean hasWinport(String memberId) {
		return winportUrlService.hasWinport(memberId);
	}
	
	public String getWinportUrlThrowException(String memberId){
		return winportUrlService.getWinportUrlThrowException(memberId);
	}
	
	public long getPostedOfferCounts(String memberId){
		return winportUrlService.getPostedOfferCounts(memberId);
	}
}

 

 

附件为源代码。

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics