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

Autowiring of beans generated by EasyMock factory-method?

I have a problem that seems really strange to me. I have the following setup: An interface: package com.example; public interface SomeDependency { } A spring component: package com.example; @Component public class SomeClass { } A spring test…
matsev
  • 32,104
  • 16
  • 121
  • 156
14
votes
2 answers

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
Alan Krueger
  • 4,701
  • 4
  • 35
  • 48
14
votes
1 answer

Testing Exceptions of a method with EasyMock

I am newbie to unit testing. I am using TestNG with MyEclipse to develop unit test cases for my application. While doing it I am facing some problems with EasyMock. Here is my code (Name of the class, method names and return types are changed for…
Sam ツ
  • 583
  • 2
  • 7
  • 17
14
votes
4 answers

Is there a way to partially mock an object using EasyMock?

E.g. let's say I have this class: public class Foo Implements Fooable { public void a() { // does some stuff bar = b(); // moar coadz } public Bar b() { // blah } // ... } And I want to test Foo.a. I want to mock Foo.b,…
allyourcode
  • 21,871
  • 18
  • 78
  • 106
13
votes
3 answers

Testing code which calls native methods

I have a class like this: public final class Foo { public native int getBar(); public String toString() { return "Bar: " + getBar(); } } Please note that getBar() is implemented with JNI and that the class is final. I want…
kayahr
  • 20,913
  • 29
  • 99
  • 147
13
votes
1 answer

creating Java Proxy instance for a class type?

I have the following code that works for creating a Proxy instance for an interface type backed by an InvocationHandler implementation, however when I use a concrete class type it doesn't work and this is well known and documented in…
SkyWalker
  • 13,729
  • 18
  • 91
  • 187
12
votes
4 answers

Unit test private functions in Android

Can we do unit testing of private functions and fields for Android Application using Android Mock ? If yes, please explain how ?
Sachchidanand
  • 1,291
  • 2
  • 18
  • 35
12
votes
1 answer

PowerMock LinkageError: MockClassLoader javax/management/MBeanServer

I'm seeing the following PowerMock/EasyMock error with the following…
javaPlease42
  • 4,699
  • 7
  • 36
  • 65
11
votes
1 answer

What is the analogon of Mockito.spy/doReturn in EasyMock?

Imagine, I have following class: public class TestClass { public class Index { } public class IndexData { private final Index index; private final ReentrantReadWriteLock lock = new…
Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
11
votes
5 answers

Why do we need mocking frameworks like Easymock , JMock or Mockito?

We use hand written stubs in our unit tests and I'm exploring the need for a Mock framework like EasyMock or Mockito in our project. I do not find a compelling reason for switching to Mocking frameworks from hand written stubs. Can anyone please…
Praneeth
  • 439
  • 2
  • 6
  • 11
11
votes
3 answers

How do I write a unit test to verify that a function sorts its result?

I have a data source from which I can request a list of people that live in a (any) country, and a method which retrieves the people from that data source and sorts them by their name alphabetically. How should I write my unit test to make sure that…
f.ardelian
  • 6,716
  • 8
  • 36
  • 53
11
votes
1 answer

EasyMock andReturn() null return value

I have built a mock object using EasyMock, and I'm trying to have the object return another object after a method call. The method call does not cause any exception to be thrown, but it returns null, though I am certain the andReturn() call had a…
Zach
  • 1,263
  • 11
  • 25
11
votes
1 answer

How to ignore unexpected method calls in JUnit/easymock?

I'm just wondering if it is possible using Junit and easymock to ignore unexpected method calls? I.e. instead of the test failing I want to be able to say - "at this point - ignore any unexpected method calls and just continue with the test as…
Rory
  • 1,805
  • 7
  • 31
  • 45
10
votes
2 answers

Difference between EasyMock.expect(...).times(...) versus using EasyMock.expect(...) several times?

What is the difference between this: ResultSet set =…
daveslab
  • 10,000
  • 21
  • 60
  • 86
10
votes
1 answer

EasyMock: Add one more expectation after replay

Is it possible to add expectation after having mock object replayed?
Konstantin Milyutin
  • 11,946
  • 11
  • 59
  • 85