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

JUnit mocking with Mockito, EasyMock, etc

I'm trying to mock a method of an object inside the class I'm testing. For instance class ClassToTest { public doSomething () { SomeObject a = new SomeObject (); a.doSomethingElse (); } } Is there a way to mock the methods of…
Shaun
  • 3,777
  • 4
  • 25
  • 46
4
votes
0 answers

How do I prevent RestAssured from overwriting mocks with real implementations?

I'm trying to test a Jersey REST service endpoint with RestAssured while mocking its dependency. I use Spring to autowire the endpoint, and I set a mock dependency before executing the test. However, when RestAssured calls the service, it gets…
Vytautas
  • 452
  • 3
  • 11
4
votes
3 answers

Mock object creation inside a method

If I have the following method: public void handleUser(String user) { User user = new User("Bob"); Phone phone = userDao.getPhone(user); //something else } When I'm testing this with mocks using EasyMock, is there anyway I could test…
Glide
  • 20,235
  • 26
  • 86
  • 135
4
votes
5 answers

How to turn off recording for an EasyMock object?

I am testing a servlet's doPost() method using EasyMock objects for the HttpServletRequest and HttpServletResponse arguments. Within the doPost() method I'm testing the request and response objects are used as arguments to a static method class for…
James Adams
  • 8,448
  • 21
  • 89
  • 148
4
votes
2 answers

How to override a method in unit tests that is called from which the class being tested

I am testing a class A's function func1. Func1 has a local variable of Class B and calls B's function func2. Code looks something like this: public Class A { public func1() { B object = new B(); int x =…
Khawar Ali
  • 3,462
  • 4
  • 27
  • 55
4
votes
2 answers

Comprehensive Pros/Cons of Mocking Frameworks for GWT

I'm interested in using the right mocking framework for my GWT app. It's my understanding that Mockito, EasyMock, and jMock are some of the most popular for Java. Could someone list pros/cons for the mocking framework that they are most familiar…
JP Richardson
  • 38,609
  • 36
  • 119
  • 151
4
votes
1 answer

ContextConfiguration inheritance in junit

I am trying to mock a service thats fetch data from redis.I have injected the beans in spring context in a new context file test-context.xml But I have other contexts files A.xml,B.xml which referes to methods in the beanS in test-context.xml.I read…
coder25
  • 2,363
  • 12
  • 57
  • 104
4
votes
4 answers

How to mock a file with EasyMock?

I have recently been introduced to EasyMock and have been asked to develop some unit tests for a FileMonitor class using it. The FileMonitor class is based on a timed event that wakes up and checks for file modification(s) in a defined list of…
Todd
  • 1,895
  • 4
  • 15
  • 18
4
votes
1 answer

Easy mock: Setting expectation inside @PostConstruct

I have class which uses @PostConstruct to cache some objects. @Component public class A { @Autowired private B b; private X x; @PostConstruct public void init(){ x = b.doSomething() } } public class C { …
Deepikaa
  • 61
  • 6
4
votes
3 answers

How to call a private constructor of an abstract class for mocking.

I'm running into some issues with how I can test this code correctly. I want to be able to mock out the call to delegateForFoo either using a Mocking framework, or even though reflection. However, when I try to do this through reflection, or through…
Matt Hamrick
  • 759
  • 5
  • 10
4
votes
1 answer

How to mock @PrePersist method?

How do I mock a @PrePersist method, e.g. preInit(), of an entity that I instantiate? I'm using TestNG. EasyMock is prefered. @Test(enabled = true) public void testCreateOrder() { // Instantiating the new mini order will automatically invoke the…
feder
  • 1,849
  • 2
  • 25
  • 43
4
votes
4 answers

EasyMock unclear error: "expected: 1, actual: 1"

I got fail of test with java.lang.AssertionError: Expectation failure on verify: A.logon(null): expected: 1, actual: 1 at org.easymock.internal.MocksControl.verify(MocksControl.java:226) at…
user590444
  • 4,252
  • 8
  • 36
  • 43
4
votes
1 answer

Unable to get mocked instance of Executor in separate class

I am trying to mock ExecutorService and Executors from java.util.concurrent package. I am able to get the mocked object if I try to get the object within the same class (test class) where I am mocking the object. However if I try to get the mocked…
Sanket Meghani
  • 885
  • 2
  • 14
  • 22
4
votes
2 answers

EasyMock - do you have to reset() mocks after test?

I think the answer is yes, but I was unable to find anything definite in the easymock documentation. I'm getting an error when first test is mocking a class, and then another test is using this class in a regular way. The class turns out to be…
Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61
4
votes
2 answers

How to use EasyMock expect

The expect doesn't seem to work for me: package com.jjs.caf.library.client.drafting; import static org.junit.Assert.*; import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; import…
Arturas M
  • 4,120
  • 18
  • 50
  • 80