easymock « Tools « Java Testing Q&A

Home
Java Testing Q&A
1.Development
2.FindBugs
3.HTMLUnit
4.hudson
5.junit
6.performance
7.plugin
8.profile
9.selenium
10.Tools
11.unit test
Java Testing Q&A » Tools » easymock 

1. Easymock: does the order of captures matter?    stackoverflow.com

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() ...

2. Can I mock a super class method call?    stackoverflow.com

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 ...

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

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 ...

4. Equivalent of LastCall.IgnoreArguments in EasyMock    stackoverflow.com

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 ...

5. EasyMock: Void Methods    stackoverflow.com

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 ...

6. Is it possible to create a mock object that implements multiple interfaces with EasyMock?    stackoverflow.com

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 ...

7. Mocking a concrete class using easymock    stackoverflow.com

Is it possible? How do I do it?

8. Easymock partially mocking (EasyMock ClassExtension), good or bad?    stackoverflow.com

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 ...

9. How to test with easymock Capture    stackoverflow.com

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 ...

10. EasyMock: What I'm doing wrong?    stackoverflow.com

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() {

  ...

11. EasyMock: test that method in mock isn't called    stackoverflow.com

As per title, just wondering if there is a mechanism with easymock to test if a method wasn't called during it's lifetime.

12. EasyMock: supplying arguments you don't know at compile-time    stackoverflow.com

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 ...

13. Easymock using date expectation    stackoverflow.com

I'm mocking a method with easymock that has a date in its body, something like this:

public void testedMethod() {
    ...
    if (doSomething(new Date())) {
  ...

14. During suite tests EasyMock says 0 matchers expected 1 recorded    stackoverflow.com

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, ...

15. How can I mock a method in easymock that shall return one of its parameters?    stackoverflow.com

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 ...

16. Why do we need mocking frameworks like Easymock , JMock or Mockito?    stackoverflow.com

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 ...

17. When is it appropriate to do interaction based testing as opposed to state based testing?    stackoverflow.com

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. ...

18. Test param value using EasyMock    stackoverflow.com

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()
  ...

19. Mock Object and Interface    stackoverflow.com

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 ...

20. Easymock vs Mockito: Design vs Maintainability?    stackoverflow.com

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 ...

21. EasyMock - changing behavior for equals() and other Object methods    stackoverflow.com

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 ...

22. Which is the best isolation framework for Java? JMock, Easymock, Mockito, or other?    stackoverflow.com

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 ...

23. EasyMock - how to reset mock but maintain expectations?    stackoverflow.com

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 ...

24. Mockito preferrable over easymock?    stackoverflow.com

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 ...

25. How do I mock static methods in a class with easymock?    stackoverflow.com

Suppose I have a class like so:

public class StaticDude{
    public static Object getGroove() {
        // ... some complex logic which returns ...

26. EasyMock problem, calling method on instance but not interested in how to get this instance    stackoverflow.com

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 ...

27. How to test a Request Object in EasyMocks?    stackoverflow.com

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 ...

28. How to use aryEq in mock behaviour?    stackoverflow.com

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", ...

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

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() ...

30. EasyMock, andReturn a capture    stackoverflow.com

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 ...

31. Can mockito or easymock replace rmock    stackoverflow.com

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 ...

32. EasyMock - How to mock the cast operation    stackoverflow.com

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 ...

33. Test that void method didn't get called with EasyMock    stackoverflow.com

Is this possible? I tried with EasyMock.expectLastCall().times(0); but EasyMock complains that times must be >=1

34. How to turn off recording for an EasyMock object?    stackoverflow.com

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 ...

35. EasyMock andReturn() vs andStubReturn()    stackoverflow.com

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 ...

36. How to test the order of mocked calls using EasyMock    stackoverflow.com

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 ...

37. Mock object creation inside a method    stackoverflow.com

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 ...

38. EasyMock methods with parameters returning void    stackoverflow.com

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 ...

39. Using normal mock and NiceMock within the same mockControl    stackoverflow.com

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 ...

40. EasyMock: Expect Number of Elements in a Set    stackoverflow.com

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 ...

41. What's the usage of Easymock.and(int, int)?    stackoverflow.com

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 ...

42. does easymock depend on net/sf/cglib/proxy/Enhancer?    stackoverflow.com

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 - ...

43. Mocking an object that uses jni using EasyMock    stackoverflow.com

So my class under test has code that looks braodly like this

public void doSomething(int param)
{
    Report report = new Report()
    ...do some calculations
   ...

44. easymock replacement for setReturnValue    stackoverflow.com

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(...) ...

45. EasyMock expect method is always return null despite setting a new Object in .andReturn    stackoverflow.com

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 ...

46. 3 matchers expected, 4 recorded    stackoverflow.com

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 ...

47. Easy mock behaviour while requested    stackoverflow.com

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 ...

48. Mock a new object creation    stackoverflow.com

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= ...

49. How do I mock objects that I can't instantiate in my tests?    stackoverflow.com

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 ...

50. Mocking both static and dynamic methods with PowerMock    stackoverflow.com

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 ...

51. Classpath issue using Ivy    stackoverflow.com

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 ...

52. Getting EasyMock mock objects to throw Exceptions    stackoverflow.com

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 ...

53. Refactoring to test    stackoverflow.com

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 ...

54. java EasyMock ignore calls to an object from TestedClass' methods    stackoverflow.com

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 ...

55. Why does this EasyMock test fails ? I can't fix it !    stackoverflow.com

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 ...

56. How to mock a list that will have certain values    stackoverflow.com

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, ...

57. Mocking Clojure protocols    stackoverflow.com

Can one of the popular Java mocking frameworks like EasyMock or Mockito be used to mock Clojure protocols defined with defprotocol? If so, how?

58. Mocking void method with EasyMock and Mockito    stackoverflow.com

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 ...

59. EasyMock, return any object, or skip that function call?    stackoverflow.com

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, ...

60. Getting exception from EasyMock's "nice mock" with a debugger attached    stackoverflow.com

(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 ...

61. Why does EasyMock's IArgumentMatcher interface use a StringBuffer?    stackoverflow.com

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 ...

62. How to mock a method call on the constructor using easymock?    stackoverflow.com

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 ...

63. EasyMock returning strange values    stackoverflow.com

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 ...

64. easymock unexpected behaviour    stackoverflow.com

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 ...

65. How do I mock a method inherited from an abstract class with EasyMock?    stackoverflow.com

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 ...

66. easymock set expectations on parameters of a method of a mocked object    stackoverflow.com

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, ...

67. EasyMock - expectation of mocked object    stackoverflow.com

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, ...

68. createPartialMock with MocksControl    stackoverflow.com

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 ...

69. EasyMock : java.lang.IllegalStateException: 1 matchers expected, 2 recorded    stackoverflow.com

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 ...

70. EasyMock : mocking the new operation possible?    stackoverflow.com

Is it possible to do something like that with EasyMock:

class ClassName{
   void method(){
      TypeToMock a = new TypeToMock();
   }
}
and I want to ...

71. Difference between 'same' and 'eq' in EasyMock    stackoverflow.com

Is there a significant(or even any) difference between 'same' and 'eq' in EasyMock?

72. EasyMock expect method to return multiple, different objects in same test    stackoverflow.com

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 ...

73. Testing private method using power mock which return list of Integers    stackoverflow.com

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 ...

74. EasyMock gentle introduction?    stackoverflow.com

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 ...

75. Compile error while using EasyMock.expect() in very simple example?    stackoverflow.com

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 ...

76. EasyMock: Mocked object is calling actual method    stackoverflow.com

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, ...

77. EasyMock: isA() fails on the right class    stackoverflow.com

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 ...

78. EasyMock: Add one more expectation after replay    stackoverflow.com

Is it possible to add expectation after having mock object replayed?

79. Expecting anything as parameter to mock using EasyMock    stackoverflow.com

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 ...

80. Mock not saving state    stackoverflow.com

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 ...

81. Does it exists a Mockito equivalent way to expect constructor invocations like PowerMock.expectNew?    stackoverflow.com

If it doesn't, does it exist on EasyMock? Thanks.

82. mocking class with annotated methods    stackoverflow.com

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. ...

83. EasyMock Not making a distinction between subclasses    stackoverflow.com

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)
  ...

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

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 ...

85. How to test the inner classes by using EasyMock    stackoverflow.com

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 ...

86. EasyMock to test SecurityException    stackoverflow.com

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 ...

87. EasyMock: Mock out a constructor call in java    stackoverflow.com

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 ...

88. How do I mock a class with easymock 3.x?    stackoverflow.com

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 ...

89. Does EasyMock.anyObject() match a null parameter?    stackoverflow.com

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() ...

90. How Configure EasyMock Class Extension 3.1?    stackoverflow.com

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 ...

91. EasyMock for testing Dependency Injection    forums.oracle.com

92. EasyMock mockSession.setAttribute() object mismatch in code and test.    forums.oracle.com

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. ...

93. easymock replay behavior..    forums.oracle.com

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). ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.