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

Any argument in Expecting function in easymock scalatest

I have just started to use scalatest for java code and in that we are using easymock to create mocks . I have a situation where I want to do something like this. expecting{ objA.function(x$1, x$2).andReturn(objectB) } For the place…
6
votes
2 answers

EasyMock and modifing a mutable method parameter

How does one use EasyMock to modify a mocked method's mutable method parameter? For example, I have class that uses a BlockingQueue. I want to mock the BlockingQueue member for unit testing. My class calls the method queue.drainTo(Collection c). …
Nathan Reese
  • 311
  • 1
  • 3
  • 6
6
votes
1 answer

JAVA: java.lang.IllegalArgumentException: Cannot subclass final class class [Lcom.package.testEntityDO;

im trying to Mock below class. public class testEntityDO extends BasetestDO { private String entityType; private testCapabilityDO[] capabilities; private testEntityDO[] testDOs; public String getEntityType() { return…
Manjunath
  • 111
  • 1
  • 8
6
votes
1 answer

What is Scala trying to tell me and how do I fix this? [ required: java.util.List[?0] where type ?0]

I am in the process of learning Scala and today I felt confident to introduce it to one of our projects. The application does a lot of JPA / Hibernate stuff and I started implementing one of the Java interfaces in Scala. All went well, until I tried…
msung
  • 3,562
  • 3
  • 19
  • 30
6
votes
2 answers

How to mock each and every instance of a class

I want to mock my java class in such a ways so that each and every new instance of it should return the mocked response.
6
votes
1 answer

PowerMock complains of incorrect arguments even though the private method is mocked

I was trying out PowerMock, and am trying to mock a private method like so: expectPrivate(n, "doLogin", anyString(), anyString()).andReturn(true); That is, I want true to be returned from doLogin irrespective of the parameters passed. The public…
pugmarx
  • 7,323
  • 3
  • 30
  • 40
6
votes
2 answers

EasyMock - changing behavior for equals() and other Object methods

The EasyMock documentation is pretty clear that The behavior for the three object methods equals(), hashCode() and toString() cannot be changed for Mock Objects created with EasyMock, even if they are part of the interface for which the Mock Object…
Ed Wagner
  • 378
  • 3
  • 7
6
votes
1 answer

How to mock both static and non static methods in a same class using powerMock?

I have a simple case to illustrate a much more complicated one (oh Legacy Code, do I love you, shall minstrels sing marvellous songs in thy name). Picture a set of class as the following : The utility class : package org.osef.test; public final…
Ar3s
  • 2,237
  • 2
  • 25
  • 47
6
votes
1 answer

EasyMock - matchers are mixed with raw values?

I have this method signature that i want to mock with EasyMock public BigDecimal getRemainingPremium(BigDecimal baseAmount, Date commencementDate, Date effectiveDate, boolean isComplete) My test code has Premium premium =…
emeraldjava
  • 10,894
  • 26
  • 97
  • 170
6
votes
2 answers

Difference between EasyMock.createStrictMock(class x) and EasyMock.createNiceMock(class x)

In the API doc it is mentioned that in the strictmock order checking is enabled by default while in case of nice mock it is not . I did not get what exactly they meant by "order checking".
Sahil Gupta
  • 2,028
  • 15
  • 22
6
votes
1 answer

EasyMock: supplying arguments you don't know at compile-time

Using the latest version of EasyMock, I have a method that I need to stub out. The method takes an object parameter and returns void. The stubbed method is being called by the method I'm testing. No surprises there. My difficulty is that the…
roufamatic
  • 18,187
  • 7
  • 57
  • 86
6
votes
2 answers

How to mock final class in java by using EasyMock?- Junit test

I have final class and with constructor for that... I have problem to mock this class. I came to know that i cannot use EasyMock for final class. But in my project i should use easymock only. Is there a way to mock this class? Can you please anyone…
shree
  • 2,745
  • 7
  • 28
  • 35
6
votes
4 answers

JUnit Easymock Unexpected method call

I'm trying to setup a test in JUnit w/ EasyMock and I'm running into a small issue that I can't seem to wrap my head around. I was hoping someone here could help. Here is a simplified version of the method I'm trying to test: public void myMethod()…
Lancelot
  • 2,417
  • 12
  • 39
  • 46
6
votes
3 answers

How to avoid mock object's method calls in strings used for logging?

I have written a test method in which there is a mocked object(say mockA). I am able to expect mockA's method calls for the actual program logic. But, part of my program also has logging which require objects' information in the form of string.…
6
votes
3 answers

Using easymock in multithreading

I want to test that some method would be recalled on failing. Calling executed in separate thread. So I write code like this final Foo mock = createStrictMock(Foo.class); mock.bar(); expectLastCall().andThrow(new RuntimeException("TEST…
Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132