0

I'm new to both JUnit and for EasyMock. I need to inject few of the classes into my JUnit test.

private static TheManager theManager;

public static void setUpBeforeClass() throws Exception {
theManager = EasyMock.createMock(TheManagerImpl.class);
theManager.init();
}

will this instantiate an object of "TheManagerImpl"? As I figured it is not calling the code inside implementation. How can I ask EasyMock to do it for me?

Simulant
  • 19,190
  • 8
  • 63
  • 98
dinesh707
  • 12,106
  • 22
  • 84
  • 134

1 Answers1

2

EasyMock will not create an instance of TheMangerImpl, but a mock instance of it. The idea is that if you want to test a class A that uses the TheManagerImpl you should not worry about how TheManager is implemented, but only about the logic in class A. In this case you create a mock for TheManager, inject it into the instance of class A and then you specify in your test how class A is supposed to call TheManager (what method, what parameters and what TheManager is supposed to return).

Bogdan
  • 934
  • 7
  • 13
  • the manager is not in a level where I can mock. It creates multiple connections and message listeners. If I end up mocking the same thing again It will be similar to making a copy of the original code. I think OI will need to find another way. Thankx – dinesh707 Feb 05 '13 at 13:53
  • @dinesh707 You need to explain what you actually want to do. You *are* mocking it, saying it's "not in a level where you can mock" doesn't make any sense. – Dave Newton Feb 05 '13 at 14:08