Saturday, 15 March 2014

java - Easymock expect exception? -



java - Easymock expect exception? -

i have below dao method.

public string getmsg(string name){ //get info database if db returned value null throw exception. if(returnvalue == null){ throw new customexception("no results"); } homecoming returnvalue; }

i need write test expected exception scenario below. how can write?

if string getmsg(string name) interface method, then:

public interface imsgdao { // ... string getmsg(string name); // ... }

in ut

imsgdao dao = easymock.createmock(imsgdao.class); easymock.expect(dao.getmsg((string) easymock.anyobject()) .andthrow(new customexception()) // <--- .anytimes();

now phone call of dao.getmsg("anystring") throw exception

java junit easymock

No comments:

Post a Comment