easymock

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 less brittle tests which are not affected much by change), then Mockito seems a better choi...

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

Hi All, 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 ClassA { public ClassB() { super("title"); } @Override ...

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 is created. The code that I'm trying to test uses equals() to compare my mock object...

EasyMock object for unit testing involving scope="request" bean

I am trying to add some Unit Testing to some of our companies code. Yes, I know it should already be there, but not everyone seems to have the same view of unit testing that I do. However, I have come against a bit of a stopper for me. Admittedly, my Java, Spring and Unit Testing knowledge are not all that they should be. My problem ...

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<String> foo = createMock(List.class); expect(foo.get(1)).andReturn("Wibble").once(); expect(foo.size()).andReturn(1).once(); replay(foo); System.out.println(foo.get(1)); System.out.println(foo.size()); ver...

Mockito preferrable over easymock?

Hi there, recently I made the switch to Mockito framework and am very happy with it (see also blog-post). The switch from easymock to Mockito was very straightforward and I managed to make the tests down compatible (i.e. test cases behave the same). Do you see real reasons or shootout criteria to prefer easymock over Mockito? So far of...

Writing maintainable unit tests with mock objects

This is a simplified version of a class I'm writing a unit test for class SomeClass { void methodA() { methodB(); methodC(); methodD(); } void methodB() { //does something } void methodC() { //does something } void methodD() { //does something } } Whil...

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 using easy mock 3.0 ...

How to get rid of this generics warning?

Hello, I am trying to mock a generic interface and whenever I mock it, I gets this warning The expression of type GenericInterface needs unchecked conversion to conform to GenericInterface My interface is interface GenericInterface<T>{ public T get(); } and My test is @Test public void testGenericMethod(){ Generic...

EasyMock problem, calling method on instance but not interested in how to get this instance

Hi, I'm trying to test an algorithm with Easymock but I'm stumbling into the details of the implementation of this algorithm. Someone who can provide me a way out? The part which gives me a problem is this: interface A { B getB (); } interface B { void setX (int x); void doSomething (); } Now somewhere during the algorithm un...

How to EasyMock a call to a method that returns a wildcarded generic?

We're looking at switching to Spring 3.0 and running into problems with the intersection of Spring 3.0, EasyMock, and Java Generics. In one place, we're mocking a Spring 3.0 AbstractBeanFactory, specifically this method: public Class<?> getType(String name) throws NoSuchBeanDefinitionException { ... } Under earlier versions of Spring...

java.lang.AssertionError: Unexpected method call convertMessagesAsAppropriate(com.Response@1bb35b)

Hi All, Need help is deciding what approach needs to be taken to test below piece of code I have one method called private messageDAOInf messageDAO; public Response verifyUser(Request request) { Response response = null; if (someCondition) { /* -----------Some processing here---------- */ } else { respon...

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 to translate some unittest-code to Scala. I make a lot of use of Easymock, the code is ...

How to test a Request Object in EasyMocks ?

I have a method that uses setAttribute on the Request object. I need to test that method to see if the attribute set has the right value. I am using EasyMocks and am new to it. I created a mock request object. But I need some help on how to test the method. Thanks for any help ...

How to use aryEq in mock behaviour ?

I am using EasyMocks for J2EE. I have a behavior method call that takes in 3 parameters, one of which is an object array and the other are strings. classUnderTest.method(new anotherClass("string1","string2", objectArray)); When I try to use the aryEq method on the object array, classUnderTest.method(new anotherClass("string1","string...

Unit testing Java Classes with EasyMock Framework

HI, I have to unit test a Java class which implements DocumentListener interface. We are using Eclipse and Junit with EasyMock Framework. I'm a newbie to Unit testing and hence would appreciate a sample code using EasyMock. The java class is: public class ClassToBeTested implements DocumentListener { private static final Co...

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 with as it relates to GWT to help fellow GWT testing noobs like myself? Thanks in advance. ...

EasyMock 3.0, mocking class throws java.lang.IllegalStateException: no last call on a mock available

Running the following unit test throws the exception: java.lang.IllegalStateException: no last call on a mock available import org.easymock.*; import org.junit.*; public class MyTest { @Test public void testWithClass() { Thread threadMock = EasyMock.createMock(Thread.class); EasyMock.expect(threadMock.isAlive(...

EasyMock, andReturn a capture

Hi, suppose I want to mock a method with the following signature: public A foo(A a) I want foo to be mocked in a way that it returned what it received (that is the same instance a) I tried unsuccessfully the following: Capture<A> capture = new Capture(); expect(myclass.foo(capture)).andReturn(capture.getValue()); This does not wor...

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). Calling this method removes elements from the queue and adds them to the collection. How...