DefaultRequestDirector not getting shadowed?

105 views
Skip to first unread message

Neal Sanche

unread,
Feb 11, 2011, 11:10:37 AM2/11/11
to Robolectric
Hi All,

I'm new to Robolectric and have been learning how I might be able to
test a set of classes that I've written that use, through a subclass,
the HttpClient classes. Unfortunately I'm getting the following error
from the class at runtime, and was wondering how to proceed?

[junit] java.lang.NoSuchMethodError:
org.apache.http.impl.client.DefaultRequestDirector.<init>(Lorg/apache/
commons/logging/Log;Lorg/apache/http/protocol/Htt
pRequestExecutor;Lorg/apache/http/conn/ClientConnectionManager;Lorg/
apache/http/ConnectionReuseStrategy;Lorg/apache/http/conn/
ConnectionKeepAliveStrategy;Lorg/a
pache/http/conn/routing/HttpRoutePlanner;Lorg/apache/http/protocol/
HttpProcessor;Lorg/apache/http/client/HttpRequestRetryHandler;Lorg/
apache/http/client/Redirec
tHandler;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/
http/client/AuthenticationHandler;Lorg/apache/http/client/
UserTokenHandler;Lorg/apache/http/p
arams/HttpParams;)V
[junit] at
org.apache.http.impl.client.AbstractHttpClient.createClientRequestDirector(AbstractHttpClient.java:
660)
[junit] at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:
625)
[junit] at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:
576)
[junit] at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:
554)
[junit] at
com.mycompany.AndroidHttpClient.execute(AndroidHttpClient.java:191)
[junit] at
com.mycompany.model.WorklistDataSource.execute(WorklistDataSource.java:
374)
[junit] at
com.mycompany.model.WorklistDataSource.execute(WorklistDataSource.java:
300)
[junit] at
com.mycompany.model.WorklistDataSource.loadVersion(WorklistDataSource.java:
488)
[junit] at com.mycompany.test.MyActivityTest
$1.run(MyActivityTest.java:59)
[junit] at java.lang.Thread.run(Thread.java:619)

How does Robolectric know to shadow a particular class? Does it need
to be told that the AndroidHttpClient class may indirectly create a
DefaultRequestDirector at some point, and that that should be
shadowed? Is there any clue as to what I might be doing wrong? Is it,
perhaps, the classpath I'm using at compile time or at runtime?

Thanks for any help, in advance.

-Neal

Neal Sanche

unread,
Feb 11, 2011, 3:52:51 PM2/11/11
to Robolectric
I figured out what my problem was. In my setup, I need to test a
separate Android library, and Robolectric was producing its cache .jar
file into another directory. At some point I must have had a bad
compile and the cache file wasn't correct, so it was giving me the
error mentioned here. Deleting that cache directory has cured my
problem and so I can now move forward.

Cheers.

-Neal

Neal Sanche

unread,
Mar 21, 2012, 1:00:45 PM3/21/12
to robol...@googlegroups.com
Thanks Neal,

Strangely enough, I had the same problem today and did a Google search for the answer. And I found a message I had sent myself over a year ago that solved the issue again. So, thank you self, that's wonderful.

-Neal

Paul Nicholson

unread,
Oct 12, 2012, 3:52:32 PM10/12/12
to robol...@googlegroups.com
Thanks Neal! I hit this today as well and your solution did the trick.
For others wondering where they might find the cache file, I found it at tmp/cached-robolectric-classes.jar.
It's surprising that the cache file survives the maven clean task.

Paul
Reply all
Reply to author
Forward
0 new messages