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
119
votes
1 answer

PowerMockito mock single static method and return object

I want to mock a static method m1 from a class which contains 2 static methods, m1 and m2. And I want the method m1 to return an object. I tried the following 1) PowerMockito.mockStatic(Static.class, new Answer() { @Override …
user1393653
  • 1,191
  • 2
  • 8
  • 3
68
votes
5 answers

EasyMock: Void Methods

I have a method that returns void in a class that is a dependency of the class I want to test. This class is huge and I'm only using this single method from it. I need to replace the implementation of this method for the test as I want it to do…
Iker Jimenez
  • 7,105
  • 9
  • 49
  • 46
64
votes
4 answers

What is EasyMock.replay() used for?

I'm a newbie to unit testing and Junit. I know the basics of Junit. I just started learning about the EasyMock framework. I couldn't understand the use of replay() method. Could anyone please provide some info? I understand the use of…
Surez
  • 854
  • 1
  • 8
  • 10
58
votes
5 answers

EasyMock vs Mockito: design vs maintainability?

One way of thinking about this is: if we care about the design of the code then EasyMock is the better choice as it gives feedback to you by its concept of expectations. If we care about the maintainability of tests (easier to read, write and having…
RAbraham
  • 5,956
  • 8
  • 45
  • 80
56
votes
2 answers

EasyMock andReturn() vs andStubReturn()

What is the difference between using andReturn(T value) vs andStubReturn(T value) for EasyMock? In what situation would you use andStubReturn() where andReturn() can't achieve the same result?
Glide
  • 20,235
  • 26
  • 86
  • 135
53
votes
6 answers

Is it possible to create a mock object that implements multiple interfaces with EasyMock?

Is it possible to create a mock object that implements several interfaces with EasyMock? For example, interface Foo and interface Closeable? In Rhino Mocks you can provide multiple interfaces when creating a mock object, but EasyMock's createMock()…
Daniel Fortunov
  • 43,309
  • 26
  • 81
  • 106
45
votes
5 answers

EasyMock: How do I create a mock of a genericized class without a warning?

The code private SomeClass someClass; someClass = EasyMock.createMock(SomeClass.class); gives me a warning "Type safety: The expression of type SomeClass needs unchecked conversion to conform to SomeClass".
Kevin Wong
  • 14,656
  • 11
  • 42
  • 52
41
votes
5 answers

NoClassDefFoundError when using Powermock

I'm running a junit test case using the PowerMock test runner. I'm using the following command line to execute it: java -cp .:junit-4.9b2.jar:easymock-3.0.jar:powermock-easymock-1.4.8-full.jar org.junit.runner.JUnitCore SampleTest When doing so I…
lukas
  • 421
  • 1
  • 4
  • 4
39
votes
5 answers

How to mock the HttpServletRequest?

I have a function that looks for a query parameter and returns a boolean: public static Boolean getBooleanFromRequest(HttpServletRequest request, String key) { Boolean keyValue = false; if(request.getParameter(key) != null) { …
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
36
votes
5 answers

java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage("title")

I'm using EasyMock(version 2.4) and TestNG for writing UnitTest. I have a following scenario and I cannot change the way class hierarchy is defined. I'm testing ClassB which is extending ClassA. ClassB look like this public class ClassB extends…
user362199
  • 361
  • 1
  • 3
  • 3
35
votes
3 answers

How do I remove the warning from a EasyMock.anyObject(List.class) call

Compiler can't stop complaining with this call : EasyMock.anyObject(List.class) I tried to specify list's type EasyMock.anyObject(List.class) but it doesn't seems to be an option (anyway, it is stupid since java will erase the type…
Drahakar
  • 5,986
  • 6
  • 43
  • 58
34
votes
5 answers

How do I mock static methods in a class with easymock?

Suppose I have a class like so: public class StaticDude{ public static Object getGroove() { // ... some complex logic which returns an object }; } How do I mock the static method call using easy mock? StaticDude.getGroove(). I am…
JavaRocky
  • 19,203
  • 31
  • 89
  • 110
33
votes
2 answers

EasyMock void method

I'm trying to use EasyMock to mock out some database interface so I can test the business logic off a wrapping method. I've been going ok with methods that return by using the following in my setup of my test. DBMapper dbmapper =…
FireEnigmaX
  • 567
  • 2
  • 7
  • 17
32
votes
2 answers

Expecting anything as parameter to mock using EasyMock

Using EasyMock I want to be able to say that I expect a specific method called on my mock, but I do not care about the parameter which are used to call the mock. SomeInterface mock =…
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135
32
votes
5 answers

How can I mock a method in easymock that shall return one of its parameters?

public Object doSomething(Object o); which I want to mock. It should just return its parameter. I tried: Capture copyCaptcher = new Capture(); expect(mock.doSomething(capture(copyCaptcher))) …
Jan
  • 2,803
  • 6
  • 36
  • 57
1
2 3
66 67