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
10
votes
6 answers

java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl cannot be cast to DocumentBuilderFactory

I am using powermock with powermock-easymock-1.5-full.jar. The following exception occurs. These are the all jars i have in my classpath. And are downloaded as powermock package from…
Ramesh
  • 499
  • 4
  • 10
  • 17
9
votes
1 answer

Set negative expectations in EasyMock

I would like to understand EasyMock better, and working with it I came up with this question. What I would like to do is setting up a negative expectation over an object, to check if a certain method is not called during the test (when verifying…
9
votes
4 answers

EasyMock: Mock out a constructor call in java

I have a looked at similar questions on this board, but none of them answer my question. This sound strange, but is it possible to mock out a constructor call on the object you're mocking. Example: class RealGuy { .... public void…
Setzer
  • 739
  • 4
  • 10
  • 18
9
votes
1 answer

EasyMock: Mocked object is calling actual method

I've following code snippet in my unit test, ClassToBeMocked mock = createMock(ClassToBeMocked.class); //I've statically imported EasyMock.* mock.callMethod(); //This is a void method expectLastCall(); replay(mock); But when I run the test, instead…
AndyT
  • 421
  • 6
  • 13
9
votes
5 answers

How do I mock objects that I can't instantiate in my tests?

I'm using EasyMock to mock objects in my tests. But how do I mock objects that are created somewhere else in my code? Look at the following psudo code. I want to mock WebService#getPersonById, how do I do that? public class Person { public Person…
Sven
  • 913
  • 8
  • 16
9
votes
4 answers

EasyMock "Unexpected method call" despite of expect method declaration

My EasyMock's expected method is perceived as unexpected, although I do not use and strict mocks, and the method is already declared before being replied. Test fails in this line of code: Intent batteryIntent =…
apex39
  • 603
  • 1
  • 6
  • 20
9
votes
1 answer

Capture arguments to expected method calls multiple times (EasyMock)

I have the following line in my test: Capture myCapture = Capture.newInstance(); expect(myMockedObject.myMethod(capture(myCapture)).andReturn(...).times(2); This expectation passes when the mocks are verified but…
Max
  • 15,157
  • 17
  • 82
  • 127
9
votes
1 answer

Is it possible to override a native method in a Java class in Android/dalvik?

I am unit testing a class TestMe using EasyMock, and one of its methods (say method(N n)) expects a parameter of type N which has a native method (say nativeMethod()). class TestMe { void method(N n) { // Do stuff …
scorpiodawg
  • 5,612
  • 3
  • 42
  • 62
8
votes
4 answers

Compile error while using EasyMock.expect() in very simple example?

I am trying a very simple example using EasyMock, however I simply cannot make it build. I have the following test case: @Test public void testSomething() { SomeInterface mock = EasyMock.createMock(SomeInterface.class); SomeBase expected =…
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135
8
votes
1 answer

EasyMock returns Null for Expected Method

I have am having a problem with EasyMock returning null for an expected (defined) method call. Creation of the mocked Object mock = EasyMock.createMock(DAO.class); Mock Set up in unit…
Seth M.
  • 598
  • 2
  • 4
  • 14
8
votes
3 answers

Unit-testing a class that calls a static method

I am trying to unit-test a class 'A' which calls a static method of a class 'B'. Class 'B' essentially has a google guava cache which retrieves a value(Object) from the cache given a key, or loads the object into the cache (in case of a cache-miss)…
8
votes
2 answers

How can I EasyMock the cast operation?

How can I mock the cast operation. I have an cast operation on a dependent object , which will cast to another dependent object like SqlMapClient sqlMapClient; SqlMapClientImpl sqlMapClientImpl = (SqlMapClientImpl) sqlMapClient I'm mocking both…
user441756
  • 81
  • 2
8
votes
1 answer

Is there any difference between ".andReturn(...).anyTimes()" and ".andStubReturn(...)" in EasyMock?

This post suggests both- that there is a difference (see comment by user SnoopyMe) and that the two can be used interchangeably. The EasyMock documentation makes no mention of any difference. Is there any difference, either practically or…
Will
  • 390
  • 4
  • 13
8
votes
1 answer

EasyMock - how to reset mock but maintain expectations?

Is it possible to re-define specific expectations on the same instance of mock object? Say I have this test which verifies OK: List foo =…
Ben
  • 81
  • 1
  • 2
8
votes
1 answer

Android: Generate a Mock Intent and return some intent-data from it

I am using ActivityInstrumentationTestCase2 for the unit testing of my application. I have a case where user clicks on a button of Activity 'A' and which in turns open a new Activity 'B' where user will do some work and finally some data is returned…
mudit
  • 25,306
  • 32
  • 90
  • 132