android - Unit test RoboSpice request using MockWebServer -


i have springandroidspicerequest subclass wanted unit test using mockwebserver. getting java.lang.noclassdeffounderror during unit test. did wrongly.

springandroidspicerequest subclass test:

public class activemonitorrequest extends springandroidspicerequest<myresponse>{     ...              @override     public myresponse loaddatafromnetwork() throws exception {           httpheaders headers = new httpheaders();         headers.setcontenttype(mediatype.application_json);         headers.set("cache-control", "no-cache");          httpentity<mybody> request = new httpentity<>(body, headers);         resttemplate mresttemplate = getresttemplate();         responseentity<myresponse> response = mresttemplate.exchange(url,         httpmethod.post, request, myresponse.class);          return response.getbody(); } 

unit test method:

@test public void testloaddatafromnetwork() throws exception {     mockwebserver server = new mockwebserver();     server.enqueue(new mockresponse().setbody("{}"));     server.start();     httpurl baseurl = server.url("/helloworld");      jacksonspringandroidspiceservice mservice = new jacksonspringandroidspiceservice();     myspringandroidspicerequest mrequest = new myspringandroidspicerequest(baseurl);     mrequest.setresttemplate(mservice.createresttemplate());      myresponse mresponse = mrequest.loaddatafromnetwork();      assertthat(mresponse.tostring(), is(equalto("{}"))); } 

stack trace:

java.lang.noclassdeffounderror: org/apache/http/conn/params/connperroute     @ org.springframework.http.client.support.httpaccessor.<init>(httpaccessor.java:55)     @ org.springframework.http.client.support.interceptinghttpaccessor.<init>(interceptinghttpaccessor.java:35)     @ org.springframework.web.client.resttemplate.<init>(resttemplate.java:169)     @ org.springframework.web.client.resttemplate.<init>(resttemplate.java:158)     @ com.octo.android.robospice.jacksonspringandroidspiceservice.createresttemplate(jacksonspringandroidspiceservice.java:30)     @ com.nusclimb.live.crimp.common.spicerequest.activemonitorrequesttest.testloaddatafromnetwork(activemonitorrequesttest.java:68)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:50)     @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12)     @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:47)     @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17)     @ org.junit.runners.parentrunner.runleaf(parentrunner.java:325)     @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:78)     @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:57)     @ org.junit.runners.parentrunner$3.run(parentrunner.java:290)     @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71)     @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288)     @ org.junit.runners.parentrunner.access$000(parentrunner.java:58)     @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268)     @ org.junit.runners.parentrunner.run(parentrunner.java:363)     @ org.mockito.internal.runners.junit45andhigherrunnerimpl.run(junit45andhigherrunnerimpl.java:37)     @ org.mockito.runners.mockitojunitrunner.run(mockitojunitrunner.java:62)     @ org.junit.runner.junitcore.run(junitcore.java:137)     @ com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:78)     @ com.intellij.rt.execution.junit.junitstarter.preparestreamsandstart(junitstarter.java:212)     @ com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:68)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ com.intellij.rt.execution.application.appmain.main(appmain.java:140) caused by: java.lang.classnotfoundexception: org.apache.http.conn.params.connperroute     @ java.net.urlclassloader.findclass(urlclassloader.java:381)     @ java.lang.classloader.loadclass(classloader.java:424)     @ sun.misc.launcher$appclassloader.loadclass(launcher.java:331)     @ java.lang.classloader.loadclass(classloader.java:357)     ... 34 more 

have @ @ this , add gradle file:

testcompile 'org.apache.httpcomponents:httpclient:4.5.2' 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -