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
21
votes
2 answers

How to test void methods using EasyMock

I've seen a few questions out there regarding this but I can't seem to make sense of any of the answers for my particular problem. I have a mock object, lets call "object1", which I send to some method for testing, lets call testMethod(). So I end…
KWJ2104
  • 1,959
  • 6
  • 38
  • 53
20
votes
4 answers

Mock Runtime.getRuntime()?

Can anyone make any suggestions about how best to use EasyMock to expect a call to Runtime.getRuntime().exec(xxx)? I could move the call into a method in another class that implements an interface, but would rather not in an ideal world. interface…
Rich
  • 15,602
  • 15
  • 79
  • 126
19
votes
5 answers

java.lang.IllegalStateException: incompatible return value type

I am using EasyMock to create mock classes in test cases. expect(entity.getType()).andReturn("string"); Type belongs to the String datatype. In my development environment it is working fine. But If I transfer to my server and take build, it is…
Dinesh
  • 1,088
  • 4
  • 16
  • 28
19
votes
3 answers

How can I mock a void method to throw an exception?

I have a structure like this: public class CacheWrapper { private Map innerMap; public CacheWrapper() { //initialize the innerMap with an instance for an in-memory cache //that works on external server …
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
19
votes
2 answers

Powermock (With Easymock) no last call on a mock available

I am trying to just run a simple test case. I have the following method. public static void run(String[] args) throws Throwable { CommandLineArguments opts = CommandLineOptionProcessor.getOpts(args); } I will continue to build this method /…
dev
  • 1,477
  • 5
  • 18
  • 43
18
votes
6 answers

Can I mock a super class method call?

Sometimes, you want to test a class method and you want to do an expectation on a call of a super class method. I did not found a way to do this expectation in java using easymock or jmock (and I think it is not possible). There is a (relative)…
arielsan
  • 418
  • 2
  • 4
  • 11
17
votes
6 answers

During suite tests EasyMock says 0 matchers expected 1 recorded

So I've been using EasyMock's class extension for a while now. All of a sudden I'm getting this exception, but only when I run the entire test suite: java.lang.IllegalStateException: 0 matchers expected, 1 recorded. at…
holmes
  • 578
  • 1
  • 7
  • 16
16
votes
3 answers

How to create HttpServletResponse for unit tests in Spring?

How to create HttpServletResponse for unit tests, where I can write output stream and headers(not MockHttpServletResponse)? In assert block I expect to compare OutputStream and headers with etalon httpServletResponse. I used Spring4, java8 and…
Roberto
  • 1,288
  • 5
  • 23
  • 47
16
votes
1 answer

Powermock keeps throwing errors for ScriptEngineManager

Due to the fact that I wanted to use Categories from JUnit on my tests I had to rewrite some mocked tests with PowerMock (powermock on top of EasyMock to mock statics). From RunWith(PowermockRunner.class) to the below; …
Jurn
  • 796
  • 1
  • 8
  • 19
16
votes
2 answers

Easymock isA vs anyObject

What is the difference between EasyMock.isA(String.class) and EasyMock.anyObject(String.class) (Or any other class supplied) In what situations would would you use one over the other?
emilyk
  • 713
  • 5
  • 14
  • 26
16
votes
1 answer

What is the Mockito equivalent of expect().andReturn().times()

I've been experimenting the Mockito equivalent of the EasyMock.expect(someMethod()).andReturn(someMockObject).times(n); but I can't figure it out. A little help on this, please? Thanks in advance.
leinra
  • 163
  • 1
  • 1
  • 4
15
votes
1 answer

EasyMock: Get real parameter value for EasyMock.anyObject()?

In my unit tests I'm using EasyMock for creating mock objects. In my test code I have something like this EasyMock.expect(mockObject.someMethod(anyObject())).andReturn(1.5); So, now EasyMock will accept any call to someMethod(). Is there any way to…
Armen
  • 255
  • 1
  • 2
  • 12
15
votes
2 answers

PowerMock's expectNew() isn't mocking a constructor as expected

I'm trying to learn the ins and outs of various mocking libraries and PowerMock(specifically the EasyMock extension) is next on the list. I'm attempting to mock a constructor and the examples provided don't have the same response when I try to…
AdamSpurgin
  • 951
  • 2
  • 8
  • 28
14
votes
3 answers

EasyMock expect method to return multiple, different objects in same test

I am using EasyMock to unit test my Java code. The class I'm trying to test is a RESTful webservice API layer. The API has an underlying service layer which is being mocked in the API test. My problem is figuring out how to correctly unit test my…
Amanda_A
  • 323
  • 1
  • 3
  • 10
14
votes
2 answers

Difference between 'same' and 'eq' in EasyMock

Is there a significant(or even any) difference between 'same' and 'eq' in EasyMock?
kolistivra
  • 4,229
  • 9
  • 45
  • 58
1 2
3
66 67