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
7
votes
3 answers

How do you use spring's injection for unit testing a controller?

I want to test my spring mvc controller. The controller has a service: @Autowired UserService userService And my user service depends on (autowired) my UserDao and some other services like mongoDb etc. Now I want the business logic to be tested in…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
7
votes
4 answers

Correct way to unit test class with inner class

Class A has inner class B. Class A has a private list of class B objects that it makes available through getBs, addB, and removeB methods. How do I unit test the removeB method? I was hoping to create two equal mocks of class B, add each, and then…
Matt
  • 4,515
  • 5
  • 22
  • 29
7
votes
1 answer

service layer testing in spring mvc using easymock

Service Interface: public List getUserAccounts(); public List getUserAccounts(ResultsetOptions resultsetOptions, List sortOptions); Service Implementation: public List getUserAccounts() { …
kneethan
  • 423
  • 1
  • 8
  • 22
7
votes
4 answers

Junit with new Date()

What would the junit test be when i have the following method: @Override public void saveLastSuccesfullLogin(final User user) { gebruiker.setLastLogin(new Date()); storeUser(user); } submethode storeUser: @Override public void…
A.Khan
  • 73
  • 1
  • 3
7
votes
1 answer

How do I mock a method using EasyMock

User getUser(int id) { User user = service.get( id ); if( user != null ) { user.Stuff = getUserStuff( id ); return User; } throw new NotFoundException(); } Stuff getUserStuff( int id ) { stuffGetter.getStuff( id…
robasta
  • 4,621
  • 5
  • 35
  • 53
7
votes
2 answers

missing behavior definition for the preceding method call:Usage is: expect(a.foo()).andXXX()

I'm New to Junit and am stuck on an issue. Any help would be really appreciated. public void testGuaranteedRates() throws Exception { ParticipantSummary summary = new ParticipantSummary(); EasyMock.expect( iRequest.getPIN() ).andReturn(…
Btla Deva
  • 91
  • 1
  • 3
  • 4
7
votes
6 answers

Easymock using date expectation

I'm mocking a method with easymock that has a date in its body, something like this: public void testedMethod() { ... if (doSomething(new Date())) { ... } And my test looks like this: public void testThatMethod() { ... …
lcuz
  • 113
  • 1
  • 7
7
votes
1 answer

How to expect void method call with any argument using EasyMock

As a part of unit test I need to mock a void function(Which accept any non-primitive paramter. e.g. MAP) call with any argument. mockObj.myMethod() Is it possible to do this with EasyMock?
shantanu
  • 1,748
  • 3
  • 19
  • 34
7
votes
6 answers

Mocking a concrete class using EasyMock

Is it possible to mock a concrete class using EaskMock? If so, how do I do it?
Samuel Carrijo
  • 17,449
  • 12
  • 49
  • 59
6
votes
1 answer

Is there a Mockito equivalent way to expect constructor invocations like PowerMock.expectNew?

If it doesn't, does it exist on EasyMock? Thanks.
kaneda
  • 5,981
  • 8
  • 48
  • 73
6
votes
3 answers

More Matchers recorded than the expected - Easymock fails from Maven and not from Eclipse

I'm having a strange problem with Easymock 3.0 and JUnit 4.8.2. The problem only occurs when executing the tests from Maven and not from Eclipse. This is the unit test (very simple): ... protected ValueExtractorRetriever…
Nico
  • 63
  • 1
  • 3
6
votes
6 answers

Easymock: does the order of captures matter?

This might seem like a pretty detailed question about Easymock, but I'm having a hard time finding a support site/forum/mailing list for this library. I'm encountering a bug when using the captures() method that seems to return the captured…
matt b
  • 138,234
  • 66
  • 282
  • 345
6
votes
1 answer

How to override current system time to a specific date in a Java 8 web application with EasyMock, without Joda Time, and without PowerMock?

I need to mock time (to a specific date, meaning I may not use anyLong()) for testing purposes in Java 8 using solely java.time, thus without Joda Time, in a testing environment under EasyMock. EasyMock doesn't let you mock static methods like…
KiriSakow
  • 957
  • 1
  • 12
  • 22
6
votes
2 answers

EasyMock and JNA - Mock Generic Return Type

I am trying to mock the following JNA call using EasyMock convInterface = (ConvInterface) Native.loadLibrary(libraryLocation,ConvInterface.class); Using this test method @Test public void testLib() { Capture> myClassCapture =…
Damien
  • 4,081
  • 12
  • 75
  • 126
6
votes
2 answers

How to test the order of mocked calls using EasyMock

It's easy enough in EasyMock to do: EasyMock.expect(service.methodCall()); but I noticed that this does not test the order in which I execute the calls, which in a case that I am trying to test is very important. Is there anyway to do this with…
lottolove
  • 61
  • 1
  • 2