EasyMock

EasyMock Private Method Mock using PowerMock

Sometimes we want to test a method that is using a private method. We can create the mock object using EasyMock but EasyMock doesn’t allow us to mock private methods. So we can use PowerMock….

EasyMock Final Method – PowerMock, JUnit 4, TestNG

One of the limitations of EasyMock is that it can’t mock final methods and final classes. However, we can use PowerMock EasyMock extension to mock static methods. EasyMock Final Method and Class using PowerMock PowerMock….

EasyMock Static Method – PowerMock, JUnit 4, TestNG

One of the limitations of EasyMock is that it can’t mock static methods. However, we can use PowerMock EasyMock extension to mock static methods. EasyMock Static Method – PowerMock PowerMock is divided into multiple modules….

EasyMock Capture Arguments

Sometimes we want to stub behaviors for any input arguments, so we use argument matchers. If you want to know the arguments when these stub methods are being called, we have to use matcher that….

EasyMock Argument Matchers

EasyMock argument matchers allow us to provide the flexible argument for matching when stubbing the methods. You will find a lot of any*() methods in EasyMock that can be used with expect() to provide arguments….

EasyMock Void Method – expectLastCall()

Sometimes we want to mock void methods. EasyMock expect() method can’t be used to mock void methods. However, we can use expectLastCall() along with andAnswer() to mock void methods. EasyMock void method When we use….

EasyMock Partial Mock

EasyMock supports creating partial mock, where we can specify the methods that will be mocked. If any other method is called, object real method will get invoked. EasyMock Partial Mock Example Let’s say we have….

EasyMock Nice and Strict Mock

EasyMock mock objects can have three types – default, strict and nice. We can specify mock object type using MockType enum while creating the mock object. EasyMock Mock Types Default: Expects only recorded calls but….

EasyMock Verify

EasyMock Verify method is used to verify that all the stubbed methods are called and there are no unexpected calls on the mocked object. EasyMock Verify EasyMock verify() method has the same effect as calling….

EasyMock Mock Exceptions

EasyMock allows us to mock exceptions when a specific method is called. We can do this using andThrow() method along with expect(). EasyMock Mock Exception Example Let’s say we have a following class. package com.journaldev.utils;….

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages