java - Fixing error : The type com.mockobjects.MockObject cannot be resolved. It is indirectly referenced from required .class files -
i trying learn unit testing of servlet mock objects, simple example. copied example code , included think necessary jars eclipse build path project. but, still error: 'the type com.mockobjects.mockobject cannot resolved. indirectly referenced required .class files'
the jars are:
mockito-all-1.9.5-sources.jar mockito-all-1.9.5.jar mockobjects-jdk1.3-j2ee1.3-0.09.jar servlet-api-2.5.jar
temperature servlet:
import java.io.ioexception; import java.io.printwriter; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; //converts farenheit celcius public class temperatureservlet extends httpservlet { public void doget(httpservletrequest req, httpservletresponse res) throws servletexception, ioexception { string str_f = req.getparameter("fahrenheit"); res.setcontenttype("text/html"); printwriter out = res.getwriter(); try { int temp_f = integer.parseint(str_f); double temp_c = (temp_f - 32) * 5.0 / 9.0; out.println("fahrenheit: " + temp_f + ", celsius: " + temp_c); } catch (numberformatexception e) { out.println("invalid temperature: " + str_f); } } }
tester class:
import junit.framework.testcase; import com.mockobjects.servlet.mockhttpservletrequest; import com.mockobjects.servlet.mockhttpservletresponse; public class testtempservlet extends testcase { public void test_bad_parameter() throws exception { temperatureservlet s = new temperatureservlet(); mockhttpservletrequest request = new mockhttpservletrequest(); mockhttpservletresponse response = new mockhttpservletresponse(); request.setupaddparameter("fahrenheit", "boo!"); response.setexpectedcontenttype("text/html"); s.doget(request, response); response.verify(); assertequals("invalid temperature: boo!\n", response.getoutputstreamcontents()); } public void test_boil() throws exception { temperatureservlet s = new temperatureservlet(); mockhttpservletrequest request = new mockhttpservletrequest(); mockhttpservletresponse response = new mockhttpservletresponse(); request.setupaddparameter("fahrenheit", "212"); response.setexpectedcontenttype("text/html"); s.doget(request, response); response.verify(); assertequals("fahrenheit: 212, celsius: 100.0\n", response.getoutputstreamcontents()); } }
you miss mockobjects-core
jar. have mockito-all.jar
not mockobjects ver 1.9.5
add mockobjects-jdk1.4-j2ee1.3.jar
, remove mockobjects-jdk1.3-j2ee1.3-0.09.jar`
Comments
Post a Comment