Questions tagged [easymock]

Easymock is a mocking framework for Java.

Easymock is an open source mocking framework for Java. It is used for creating mock objects and stubs for unit tests.

999 questions
5
votes
2 answers

Easy way to mock chained method calls in Easymock

Is there a simple way to mock this call: objectA.getB().getC(); right now the way I do this is: A mockA = EasyMock.createMock(A.class); B mockB = EasyMock.createMock(B.class); C mockC =…
Quantum_Entanglement
  • 1,583
  • 7
  • 21
  • 32
5
votes
4 answers

How to unit test a DAO that is extending SqlMapClientDaoSupport

Spring DA helps in writing DAOs. When using iBATIS as the persistence framework, and extending SqlMapClientDaoSupport, a SqlMapClient mock should be set for the DAO, but I can't do it. SqlMapClientTemplate is not an interface and EasyMock cannot…
Behrang
  • 9,789
  • 6
  • 24
  • 19
5
votes
1 answer

How to inject EasyMock mock into tested class private field

I'm using EasyMock to create mock that is one of private parameters (without setter) in tested class. I tried using reflection - but it does not work correctly. public class TestedClassTest{ @Test public void test(){ TestedClass…
Marcin
  • 185
  • 1
  • 2
  • 16
4
votes
1 answer

Junit Testing Mocking a File Operation

I have a piece of code similar to the below that I have been asked to Junit test. We are using Junit, EasyMock and Spring Framework. I've not done much Junit testing, and am a bit lost as to how I can mock the below. Basically the path to the file…
brim4brim
  • 163
  • 1
  • 7
4
votes
1 answer

EasyMock giving unexpected results, says expected 1, actual 0

With my mocks in place, I get the error: redisDao.someMethod(notNull(), notNull()): expected 1, actual 0 If I remove the mock setup, then when tracing in debug mode, it goes to the method redisDao.someMethod and then fails with a null pointer…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
4
votes
3 answers

Easymock - nested void method testing (spying)

How to spy parameter 'param' in nested method during getData() mock testing ? Is it possible with Easymock 3 ? Source code public class ServiceLogic { public void getData(){ // some business logic serviceDAO.executeStatement(param); …
Martin V.
  • 3,560
  • 6
  • 31
  • 47
4
votes
2 answers

Mock/Test Super class call in subclass..is it possible?

I am looking for a solution to mock the super call in subclass ButtonClicker. Class Click { public void buttonClick() throws java.lang.Exception { /* compiled code */ } } Class ButtonClicker extends Click { @Override public void…
Himalay Majumdar
  • 3,883
  • 14
  • 65
  • 94
4
votes
2 answers

Does EasyMock.anyObject() match a null parameter?

My SUT may call a method on my mock with any object as paramter, including null. So, does EasyMock.anyObject() match a null parameter? or can I use something else instead of anyObject() which will also match null ?
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135
4
votes
3 answers

Getting exception from EasyMock's "nice mock" with a debugger attached

(Disclaimer - EasyMock newb) According to the documentation (and this post), if I wanted to use EasyMock to generate stub objects, I should use EasyMock.createNiceMock(). A "nice mock" is actually a stub - i.e an object that doesn't participate in…
ripper234
  • 222,824
  • 274
  • 634
  • 905
4
votes
4 answers

Mocking void method with EasyMock and Mockito

Hello I would like to know what is the best approach to mock void methods for example: I have a PersonManager under the test and then I have dao that is mocked. class PersonManager { PersonDao dao... PersonManager(PersonDao dao)... …
Jarek
  • 7,425
  • 15
  • 62
  • 89
4
votes
1 answer

How to unit test a method with enum parameters?

I'm using junit and EasyMock to do unit testing on a project I'm working on. However, I've run into a problem. I have a good handful of methods that have a parameter that is an enumeration. I ran into the java.lang.NullPointerException when…
Jay
  • 53
  • 1
  • 4
4
votes
1 answer

Unit Testing Composite Service Methods

I am writing (junit) unit tests for a class which implements an exposed interface with methods like: public Set getUserSettings(); public Set getOrganizationSettings(); public Set getDefaults(); public Set
BuffaloBuffalo
  • 7,703
  • 4
  • 28
  • 29
4
votes
1 answer

How to get an EasyMock mock to return an empty list multiple times

I would like an EasyMock mock to be able to expect an empty list multiple times, even when the list that is returned the first time has elements added to it. Is this possible? As the empty list created in the expectation persists for the whole…
insano10
  • 113
  • 2
  • 6
4
votes
2 answers

no injection of a mock with easymock

I want to code a little example using easymock 3.5 and JUnit5, but I get an error (nullPointerException) when trying to inject the mock... here is the test code: package model; import controler.BookEditor; import org.easymock.EasyMockRule; import…
lolveley
  • 1,659
  • 2
  • 18
  • 34
4
votes
1 answer

3 matchers expected, 4 recorded

I get this exception during the mock recording time. I tried searching for a solution in this forum and made sure that I did not mess up any another parameter. The below mock expectation is giving the…
user564159
  • 51
  • 1
  • 1
  • 4