1

I'm trying to mock a generic class, like this:

JobDispatcher<JobBuilding> dispatcher;
(...)

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    dispatcher = createMock(JobDispatcher.class);
}

The Generic class has a specific Type parameter:

public class JobDispatcher<Job_Type extends Job> {

where Job is the superclass of JobBuilding. When I'm running the test, I get an error:

java.lang.NoClassDefFoundError: org/objectweb/asm/Type
at (...)

Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type
at (...)

The end of the first trace points to the line in the setUp() that creates the mock (shown above). Does anyone have an idea what causes the problem?

Thanks for your help.

  • Although no accepted answer, [this post](http://stackoverflow.com/questions/56954/easymock-how-do-i-create-a-mock-of-a-genericized-class-without-a-warning) provides a couple of ways which you might try out. If you need to validate against a generic type [this post](http://stackoverflow.com/questions/9467049/easymock-matcher-for-class-data-type) might be useful as well – Roman Vottner Jul 14 '15 at 21:38
  • The first post is basically where I have my code. But even with a subclass it still doesn't work. – user2283914 Jul 15 '15 at 16:52
  • Have you already tried [adding ASM](http://www.mkyong.com/java/java-lang-classnotfoundexception-org-objectweb-asm-type/) to your dependencies? – Roman Vottner Jul 15 '15 at 17:14
  • Thanks! Adding asm to build path fixed it! So this problem wasn't about mocking generics, but just a missing dependency. – user2283914 Jul 15 '15 at 22:17

0 Answers0