easymock

EasyMock: How do I create a mock of a genericized class without a warning?

The code private SomeClass<Integer> someClass; someClass = EasyMock.createMock(SomeClass.class); gives me a warning "Type safety: The expression of type SomeClass needs unchecked conversion to conform to SomeClass<Integer>". ...

How to unit test a DAO that is extending SqlMapClientDaoSupport

Spring DA helps in writing DAOs. When using iBATIS as the persistence framework, and extending SqlMapClientDaoSupport, a SqlMapClient mock should be set for the DAO, but I can't do it. SqlMapClientTemplate is not an interface and EasyMock cannot creates a mock for it. ...

Two IDEs have different results.

My co-worker and I are working on the same project, but we use different IDEs. He uses Eclipse 3.4 and I use IntelliJ 8.0. Recently I advocated using EasyMock, which uses CGLIB, for some unit tests on our project. I have not seen any problem setting breakpoints in IntelliJ on the partial mock objects generated by EasyMock, but my co-wor...

EasyMock and Hibernate Criteria Queries

Hi, I am trying to test a dao method which uses the hibernate criteria API, using JUnit4 and EasyMock 2.4. When I run the test fixture 'testGetAsset' I receive the following exception: java.lang.AssertionError: Unexpected method call add(name=Test): add(name=Test): expected: 1, actual: 0 add(source=GSFP): expected: 1, actual...

JUnit: Making sure failures in the test method are shown before failures in @After methods

I have designed a small test case class that is designed to make mocking easier (in this case, with JUnit 4 and EasyMock). Part of this is verifying the mocks after the test has finished, so the mocks are verified in a method annotated with @After. However, if there is a failure in the test method itself, which causes the test not to be...

Easymock: does the order of captures matter?

This might seem like a pretty detailed question about Easymock, but I'm having a hard time finding a support site/forum/mailing list for this library. I'm encountering a bug when using the captures() method that seems to return the captured parameters out of order. Here's a simplified version of what I am testing: public class Capture...

How do I verify a method call and ignore the return value in EasyMock?

I'm getting frustrated trying to do a simple thing - I want to invoke a method on a mock object and NOT check its return value. I just want to check that it was invoked with the correct parameters. Example: MyInterface mockObject = createMock(MyInterface.class); SomeObject param = new SomeObject(); /* the write object is not void and ...

Can I mock a super class method call?

Sometimes, you want to test a class method and you want to do an expectation on a call of a super class method. I did not found a way to do this expectation in java using easymock or jmock (and I think it is not possible). There is a (relative) clean solution, to create a delegate with the super class method logic and then set expectati...

How does "static reflection" work in java? (ex. in mockito or easymock)

I'm a .NET guy - and I mainly code in C#. Since C# 3.0, we can leverage lambda expressions and expression trees to use static reflection. For example, it is possible to implement GetMethodName in the following snippet to return the name of the method passed in parameter: string methodName = GetMethodName( o => o.DoSomething()); Console...

Equivalent of LastCall.IgnoreArguments in EasyMock

I have used Rhino.Mocks extensively currently writing some tests in Java using EasyMocks. However I was unable to pull out a LastCall.IgnoreArguments() Rhino.Mocks equivalent in EasyMocks. How do I use Easy Mocks to return a value irrespective of the arguments in the method. For example: public interface ISoothSayer { String SayS...

EasyMock: Void Methods

I have a method that returns void in a class that is a dependency of the class I want to test. This class is huge and I'm only using this single method from it. I need to replace the implementation of this method for the test as I want it to do something different and I need to be able to access the parameters this method receives. I c...

Using Spring to inject EasyMock mocks causes ClassCastException

I am trying to get Spring to inject EasyMock mocks in my unit tests. In my applicationContext.xml, I have this: <bean id="mockService" class="org.easymock.EasyMock" factory-method="createMock" name="MockService"> <constructor-arg index="0" value="my.project.Service"/> </bean> In my unit test I have this: @Autowired @Qualifier(...

Unit testing DAO, am I doing it right?

I'm starting out unit testing and reviewing Java web programming. The thing is I don't know if I'm doing things right. I'm building a mini blog. I'm using EasyMock for the mock objects. Here's my code: The test case The PostDAO The Post Bean I'd really appreciate your comments and suggestions on how I could improve my code and bec...

Is it possible to create a mock object that implements multiple interfaces with EasyMock?

Is it possible to create a mock object that implements several interfaces with EasyMock? For example, interface Foo and interface Closeable? In Rhino Mocks you can provide multiple interfaces when creating a mock object, but EasyMock's createMock() method only takes one type. Is it possbile to achieve this with EasyMock, without resor...

Using easymock, repeated void method call

I am new to easymock. I am trying to mock a service where one of the methods is a void method that will gets called an unknown and large amount of times. How to specify that any number of calls is allowed. I know how to do it for other then void methods. Thanks, Hendrik ...

Mocking a concrete class using easymock

Is it possible? How do I do it? ...

verify object type with easymock

hello guys.i've just come into the world of easymock.i'll like to ask if easymock only does mock object for interfaces? So in my effort to understand i wrote a class to generate unique voucher in java.i obviously can't know which value it will generate to use in the assert stuff.So how to make sure the generated voucher is of the type l...

easymock - matcher and multiple calls

Below is a test I have knocked up that uses its own matcher. I know in this case I could use a standard matcher but in my real code I need a more complicated one. The test passes - tick VG. The issue is that there appears to be an extra call to IArgumentMatcher.matches() method that returns false, and yet the test passes. The output I ...

Are mock frameworks and high test coverage important?

Mock frameworks, e.g. EasyMock, make it easier to plugin dummy dependencies. Having said that, using them for ensuring how different methods on particular components are called (and in what order) seems bad to me. It exposes the behaviour to test class, which makes it harder to maintain production code. And I really don't see the benefit...

Unit Test - Check a method call with an object that doesn't override equals

Hi All, This is a general question on how to unit-test a Java Class using mock objects. I can summarize my problem with this example. Let's say I've an Interface called MyInterface.java and a "TwoString" Object that doesn't override equals() "TwoString.java" private String string1; private String string2; public TwoString(...