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() ... |
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 ... |
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 ... |
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 ... |
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 ... |
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 ... |
Is it possible? How do I do it?
|
|
I have written quite a few Mock objects using EasyMock. However, often i find writing partial mocks time consuming, and it does not feel 'right'.
I'd say its a design fault as ... |
I have the following code
Record rd = registerNewRecord();
<do some processing>
rd.setFinished(true);
updateRecord(rd);
The registerNewRecord method calls the RecordDao insert method, and updateRecord calls the update method on the same DAO.
I have the following easymock ... |
So, I need to test the Service Layer for an application (I need to test some methods - this is my first contact with the testing section)
public void testGetAllOrderedDescByRating() {
...
|
As per title, just wondering if there is a mechanism with easymock to test if a method wasn't called during it's lifetime.
|
Using the latest version of EasyMock, I have a method that I need to stub out. The method takes an object parameter and returns void.
The stubbed method is being called ... |
I'm mocking a method with easymock that has a date in its body, something like this:
public void testedMethod() {
...
if (doSomething(new Date())) {
...
|
So I've been using EasyMock's class extension for a while now. All of a sudden I'm getting this exception, but only when I run the entire test suite:
java.lang.IllegalStateException: 0 matchers expected, ...
|
I have a method
public Object doSomething(Object o); which I want to mock. It shall just return its parameter. I tried:
Capture<Object> copyCaptcher = new Capture<Object>();
expect(mock.doSomething(capture(copyCaptcher))).andReturn(copyCatcher.getValue()); wihtout success, I get just an ... |
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 ... |
When I use Easymock(or a similar mocking framework) to implement my unit tests, I'm forced to do interaction-based testing (as I don't get to assert on the state of my dependencies. ... |
I'm attempting to write some unit tests using EasyMock and TestNG and have run into a question. Given the following:
void execute(Foo f) {
Bar b = new Bar()
...
|
I'm a newbie in Unit Test with Mock Object. I use EasyMock. I try to understand this example:
import java.io.IOException;
public interface ExchangeRate {
double getRate(String inputCurrency, String outputCurrency) throws ...
|
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 ... |
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 ... |
I realize this has been asked before, but the last time was in mid 2008.
If you were starting a new project right now, which one would you use and ... |
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());
verify(foo);
What I would then like to do is ... |
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 ... |
Suppose I have a class like so:
public class StaticDude{
public static Object getGroove() {
// ... some complex logic which returns ...
|
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 ... |
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 ... |
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", ... |
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() ...
|
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 ... |
I'm sitting with a legacy project, and we're starting to replace some old legacycode. As Rmock don't have support for junit4, we would like to replace it. One thing i was ... |
How can I mock the cast operation.
I have an cast operation on a dependent object , which will cast to another dependent object like
SqlMapClient sqlMapClient;
SqlMapClientImpl sqlMapClientImpl = (SqlMapClientImpl) sqlMapClient
I' mocking ... |
Is this possible?
I tried with EasyMock.expectLastCall().times(0); but EasyMock complains that times must be >=1
|
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 ... |
I'm still a rather new developer,so I might not have a grasp on all the concepts and terms which could be the reason why I don't understand this. But what exactly ... |
It's easy enough in EasyMock to do:
EasyMock.expect(service.methodCall());
but I noticed that this does not test the order in which I execute the calls, which in a case that I am ... |
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 ... |
My unit test framework replaces business service components with Mock objects using EasyMock.createMock(Interace).
These components are accessed several layers down in the class under test so I don't wish to modify ... |
Is it possible to use a niceMock and a "normal" mock within the same mockControl object?
Currently if I try to set one of the mock to nice
someMock = mockControl.createMock(someClass.class);
EasyMock.resetToNice(someMock);
It seems ... |
How do you verify the number of elements in a set in Easymock? The class I'm testing should call a method, passing in a set with n elements. Right ... |
EasyMock has predefined argument matcher and(X first, X second)
Document says:
Matches if the matchers used in first and second both match. Available for all primitive types and for objects.
But ... |
I am trying to complete a tutorial about easymock to use it for the first time.
http://www.vogella.de/articles/EasyMock/article.html
I am using
- ... |
So my class under test has code that looks braodly like this
public void doSomething(int param)
{
Report report = new Report()
...do some calculations
...
|
Hy,
The new version of easymock has deprecated the setReturnValue method from org.easymock.MockControl
is there a way to set a default return value for a call, or do I have to use expect(...) ... |
I have my source code as:
response = getRequestService().retrieveResponse(baseRequest);
data = response.getStoredData(); ---> (1)
And I have written my Test Case as :
RequestService requestService = EasyMock.createNiceMock(RequestService .class);
BaseRequest baseRequest = new ...
|
I get this exception during the mock recording time.
Searched for a solution in this forum. Made sure that i did not mess up any another parameter.
The below mock expection is giving ... |
I was thinking, is it possible to mock whole object behavior with EasyMock, but in a way that once declared mock with all expected values and results is used several times ... |
I am using EasyMocks.
Inside a method there is a new object created. And upon that object a method is called which returns a map. As show below
test(){
Fun f= ...
|
I'm using EasyMock to mock objects in my tests. But how do I mock objects that are created somewhere else in my code? Look at the following psudo code. I want ... |
Let's say we have
public class Foo {
public static Foo getInstance() {...}
public Bar bar(Baz baz) {...}
}
What I want to do is to mock it in my ... |
I'm using Ivy to manage my dependencies, and It's causing me issues with easymock
my ivy.xml file has the following:
<dependency org="easymock" name="easymock" rev="2.5.+" conf="compile,test -> default" />
and then I follow ... |
I'm in process of using EasyMock to write Unit tests for a number of collaborating classes. One of these classes (lets call it Foo) opens a network connection to a remote ... |
I have a piece of code roughly equivalent to the following.
public class ConcreteThread extends OtherThread {
private DAOfirst firstDAO;
private DAOsecond secondDAO;
private TransformService transformService;
private NetworkService ... |
I have a class where I have an object. I am testing a method that calls this object, but it the object has nothing to do with my test, so I'd ... |
Hi I have this test below failing and giving me this error, the fail is on the Verify... but I can't get why !
java.lang.AssertionError:
Expectation failure on ... |
I have a method:
expect(processor.process(arg1, list));
expectLastCall().anyTImes();
Now, I need the list to contain certain values. And the problem is that the values have to be added to the list in a right order, ... |
Can one of the popular Java mocking frameworks like EasyMock or Mockito be used to mock Clojure protocols defined with defprotocol? If so, how?
|
Hello I would like to know what is the best approach to mock void methods for example: I have a PersonManager under the test and then I have dao that is ... |
Using EasyMock, how do I specify returning "anyObject"? I get an exception if I try to use ".addReturns(anyObject())".
Or is there a way to just relax EasyMock's requirements and just say, ... |
(Disclaimer - EasyMock newb)
According to the documentation (and this post), if I wanted to use EasyMock to generate stub objects, I should use EasyMock.createNiceMock(). A "nice mock" is actually ... |
EasyMock allows you to create your own matchers so that you can specify what a mock should return for certain inputs. To do this, you create a custom implementation of their ... |
I have a class that receives a factory as an argument that is called inside the constructor. It must be called there because the object should be fully initalized before it ... |
I am currently trying to learn how to use easymock. I have the following code:
List list = EasyMock.createMock(List.class);
EasyMock.expect(list.size()).andReturn(0);
EasyMock.replay(list);
EasyMock.verify(list);
This, to me at least, should work -- a list is initialized with nothing ... |
I'm not sure what I'm doing wrong here. I had this error in my code, so I wrote a simple example to try to identify where the error lies.
I have ... |
I'm struggling with EasyMock. I've written two small classes to illustrate my problem:
public abstract class A {
private AtomicReference<Integer> id = new AtomicReference<Integer>(null);
public final ...
|
I'm not sure how to set up this sort of behaviour with easymock. To illustrate I created a simplified example.
Basically, I have a method that returns void, and take one map, ... |
I am fairly new to EasyMock. I am trying to write a EasyMock test for my Spring WS Endpoint and keep running to a issue. Details are listed below:
Endpoint:
@PayloadRoot(namespace = NAMESPACE_URI, ... |
I have a StrictPartialMock (created with createStrictPartialMock(class, "method1")). and a normal mockedObject.
I want to test if method1() calls StrictPartialMock.method2(), mockedObject.method1(), StrictPartialMock.method3() in that order.
Now i read i can use private IMocksControl ... |
I am having a problem with EasyMock 2.5.2 and JUnit 4.8.2 (running through Eclipse). I have read all the similar posts here but have not found an answer. I have a ... |
Is it possible to do something like that with EasyMock:
class ClassName{
void method(){
TypeToMock a = new TypeToMock();
}
}
and I want to ... |
Is there a significant(or even any) difference between 'same' and 'eq' in EasyMock?
|
I am using EasyMock to unit test my Java code. The class I'm trying to test is a RESTful webservice API layer. The API has an underlying service layer which is ... |
I have a private method which take a list of integer value returns me a list of integer value. How can i use power mock to test it. I am new ... |
I am completely baffled while trying to use EasyMock. Does anybody know of a (very) gentle introduction to EasyMock?
I already heavily use TDD, and I use mocking (which I guess is ... |
I am trying a very simple example using EasyMock, however I simply cannot make it build. I have the following test case:
@Test
public void testSomething()
{
SomeInterface mock ...
|
I've following code snippet in my unit test,
ClassToBeMocked mock = createMock(ClassToBeMocked.class); //I've statically imported EasyMock.*
mock.callMethod(); //This is a void method
expectLastCall();
replay(mock);
But when I run the test, instead of seeting up the expectaion, ... |
I'm telling mock object to wait for method with command:
mockObject.registerSQLDriver(isA(SomeName.class));
At runtime method is called exactly with instance of SomeName class, but the test fails telling that "Unexpected method call registerSQLDriver()"
What can ... |
Is it possible to add expectation after having mock object replayed?
|
Using EasyMock I want to be able to say that I expect a specific method called on my mock, but I do not care about the parameter which are used to ... |
I'm unit testing with easymock and having a result not set in the answer object. The mock object is passed to the testing subject and after processing the same reference of ... |
If it doesn't, does it exist on EasyMock?
Thanks.
|
I have concrete class that I want to mock. There are several annotated methods with annotations. I want to create class mock but I need to preserve that annotations.
I tried easymock. ... |
Given the following
class Event{
}
class SpecialEvent extends Event{
}
class OtherEvent extends Event{
}
class EventPublisher{
public publish(Event e){
}
}
@test
testBlah{
myService = new MyService();
mockEvent = createMock(EventPublisher)
...
|
What is the difference between this:
ResultSet set = EasyMock.createNiceMock(ResultSet.class);
EasyMock.expect(set.getInt("col1")).andReturn(1);
EasyMock.expect(set.wasNull()).andReturn(false);
EasyMock.expect(set.getInt("col2")).andReturn(2);
EasyMock.expect(set.wasNull()).andReturn(false);
EasyMock.replay(set);
assertEquals(1, set.getInt("col1"));
assertEquals(false, set.wasNull());
assertEquals(2, set.getInt("col2"));
assertEquals(false, set.wasNull());
And this:
ResultSet set = EasyMock.createNiceMock(ResultSet.class);
EasyMock.expect(set.getInt("col1")).andReturn(1);
EasyMock.expect(set.getInt("col2")).andReturn(2);
EasyMock.expect(set.wasNull()).andReturn(false).times(2);
EasyMock.replay(set);
assertEquals(1, set.getInt("col1"));
assertEquals(false, set.wasNull());
assertEquals(2, set.getInt("col2"));
assertEquals(false, set.wasNull());
?
Note: both sets of code compile and run successfully as jUnit ... |
I am new to the EasyMock. I need to test my class using the EasyMock, but here the problem is my class has inner class and this inner class is instatiated ... |
I am trying to use easyMock to write a test, that tests SecurityException in the following code.
eg. for NumberFormatException I use the below.
EasyMock.expect(mockEntityManager.find(UserProfile.class,"abc")).andThrow(new
NumberFormatException());
Any ideas on what ... |
I have a looked at similar questions on this board, but none of them answer my question. This sound strange, but is it possible to mock out a constructor call on ... |
So I've got the following import in my class:
import static org.easymock.classextension.EasyMock.*;
So I create a real object
SomeJobDataMap map = SomeJobDataMap();
map.put(Constant.SOMETHING,"somevalue");
map.put(Constant.SOMETHING_ELSE,"anothervalue")
Then I create a mock:
SomeJobContext context = createMock(SomeJobContext.class);
expect(context.getJobDataMap()).andReturn(map);
replay(context);
testTargetClass.methodUnderTest(context);
... no errors except the NPE ... |
My SUT may call a method on my mock with any object as paramter, including null.
So, does EasyMock.anyObject() match a null parameter? or can I use something else instead of anyObject() ... |
I want to add EasyMock Class Extension 3.1 to my project and I have a problem with dependencies of EasyMock 3.1 CE. I add dependencies : cglib-2.2.2.jar and asm-4.0.jar and ... |
|
You set up the expectation with a particular instance of Context, and of course, during replay, the mock gets passed a different instance of Context. Try the following mockSession.setAttribute("test", EasyMock.isA(Context.class)) replay(mockSession); Note that here, you've kind-of circumvented some of EasyMock's more strict testing, but it's sometimes unavoidable, especially where the code under test is explicitly creating new objects as yours is. ... |
Thanks Loko. I appreciate it. Yes, you are right, I'm calling replay() on the MockControl and not the MockObject. It was a typo. However, when I call MockControl.verify(), I get a AssertionFailedError. It says "Expectation failed on verify: : Expected: 1, Actual: 0". I don't see a call to verify() in any of the code I'm looking at (inherited code). ... |