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

EasyMock calls hashcode when creating constructor and throwing a NullPointerException

I do not understand why EasyMock automatically calls hashcode() before assigning values for properties. When I'm creating the constructor in test class, instead of setting the value for properties, it calls hashcode() that is overridden and throwing…
xuongrong
  • 73
  • 1
  • 7
0
votes
1 answer

EasyMock expectations within loop

Is it possible to set different expectations for a mock which is being invoked in a loop? Considering the use case, while(condition){ List list = Database call //Call to be mocked .... Logic based on above response } how can we set…
ram
  • 747
  • 2
  • 11
  • 34
0
votes
1 answer

EasyMock expected void

Just trying the EasyMock for the first time. I seem to get it going but I am immediately halted with the fact that the mocked class runs a method "returning" void (EntityManager.remove(abc)). I am able to mock the EntityManger partly to begin…
Ville Myrskyneva
  • 1,560
  • 3
  • 20
  • 35
0
votes
1 answer

Easymock: Issue Mocking void DAO method - Unexpected method call

Found a workaround. See solution at the bottom Ok I have been in EasyMock jail all day and I need some help getting out. I have a void save() method I am mocking out. public void save(PurchaseOrder po); PurchaseOrder is an abstract class that has…
Nathan Weddle
  • 187
  • 3
  • 11
0
votes
1 answer

PowerMock / EasyMock for JMX ManagementFactory

I need to mock following code: final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.registerMBean(testMBean, new ObjectName("testObjectName"); I am usign PowerMock to mock ManagementFactory with following code snippet: At class…
arviarya
  • 650
  • 9
  • 9
0
votes
1 answer

EasyMock mocked method call is returning null when called for the second time after resetting mock object

This is my first post in Stackoverflow, so far I have been the active reader of this forum and I am posting my first question here. This is regarding the EasyMock usage, I am a new user of EasyMock and in the following example code I am setting…
Muthu
  • 3
  • 1
  • 2
0
votes
1 answer

Assert method call with EasyMock

I am writing a unit test around void function. Inside that I call another function. I want to test that this function should be called only once. If it is getting called 0 or 2 times, it should fail. I have tried using followings.But even if I…
shantanu
  • 1,748
  • 3
  • 19
  • 34
0
votes
2 answers

EasyMock Void Methods mismatch of object hashcode

I have create an mock object for HttpSession like below. HttpSession mocks.createMock(HttpSession.class); Now i am testing some method the method is public String validateProduct(String productId,Model model,HttpServletRequest request){ …
Krushna
  • 5,059
  • 5
  • 32
  • 49
0
votes
1 answer

Mock object for Hibernate's classes

Is it possible to make Mock object for Hiberate's native classes(I use easymock)? For example for Query? If yes, how should I do it? Here is part of test code: @Mock private SessionFactory sessionFactory; @Mock protected Session session; …
Ana
  • 72
  • 4
0
votes
1 answer

EasyMock servlet reflection

That is a piece of servlet code. I have no idea how to cover it by mock. I created mock objecs like ServletConfig, LoginServiceFactory and LoginService but I don't know how to create mock for Class.forName. That is static method called and other…
RMachnik
  • 3,598
  • 1
  • 34
  • 51
0
votes
1 answer

EasyMock calling two DAO methods- Unexpected method call UserAdminDAO.updateUser

In my unit test for DAO method, I am trying to test the update user method. But, I have to create an user and then update it. So my mock DAO is expecting the addUser call, but then when I am, calling the update method it is…
mi3
  • 581
  • 1
  • 7
  • 13
0
votes
1 answer

ignoring specific parameter of mocked object while comparing expected call and actual call

I have a class as follows: public class MyClass{ Connector con; public MyClass(Connector con){ this.con= con; } public void save(Xyz xyz){ //save 2 instances of xyz one with lastupdatetime as 0 and other with //…
user93796
  • 18,749
  • 31
  • 94
  • 150
0
votes
1 answer

How to mock static method using junit and easymock

The problem is next: I need to test method methodTest() of private class. The methodTest() call static method staticExternal() from external library. How to replace the staticExternal() on a mockLocal(), if I use JMock and EasyMock, but class that…
blackhard
  • 502
  • 7
  • 26
0
votes
1 answer

Powermock no last call on a mock available

Running the code from: http://www.jayway.com/2009/05/17/mocking-static-methods-in-java-system-classes/ I get the following error. Anyone seen this? Thanks! java.lang.IllegalStateException: no last call on a mock available at…
powder366
  • 4,351
  • 7
  • 47
  • 79
0
votes
1 answer

Mock enum instantiation using powermock

I have following code to test: Public MyClass() { public static final boolean myFunc(int param1, String param2, long param3) { SomeInterface var1 = SomeEnumImplementingSomeInterface.INSTANCE; SomeOtherInterface var2 =…
rajneesh2k10
  • 1,550
  • 3
  • 12
  • 24