Skip to content
Convenient extensions to Mockito
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Convenient extensions to the [Mockito] ( unit-testing mock object library.

Requires Java 8 (or higher)

Adds a mixin interface (built by [interface-it] ( called ExtendedMockito (and there is also ExtendedBDDMockito) and extra matchers, including lambda-capable matchers.

##Latest release Maven Central

[Release notes on github] (


[Binary downloads] ( "binaries")

In Maven:


##Example usage

	public class EmployeeTest implements ExtendedMockito { 
	when(mock.acceptExtractedInformation(toStringContainsAllOf("Shire", "Baggins", "Precious"))).thenReturn(Boolean.TRUE);
when(mock.checkCVBuzzwords(toStringContainsOneOrMoreOf("SCRUM", "Kanban", "TDD", "DDD", "ROTFL")))
		when(mock.doAThingWithAList(oneOrMoreItemsMatch((str) -> str.startsWith("item")))).thenReturn(Boolean.TRUE);
		when(mock.doAThingWithADouble(doubleMatches((val) -> val < Math.PI, "< PI"))).thenReturn(Boolean.TRUE);
		verify(mock).doAThingWithABean(hasToString("[Employee] name=John Smith, group=R&D"));	
when(mock.doAThingWithAList(listContainsExactlyInAnyOrder("Parsley", "Rosemary", "Sage", "Thyme"))).thenReturn(Boolean.TRUE);

See [the unit tests] ( for more examples.

##List of added matchers:

String matchers

  • containsAllOf
  • containsOneOrMoreOf
  • hasToString
  • toStringContainsAllOf
  • toStringContainsOneOrMoreOf

Lambda Predicate matchers for collections

  • allListItemsMatch
  • oneOrMoreListItemsMatch
  • allSetItemsMatch
  • oneOrMoreSetItemsMatch
  • mapThat

Other matchers for collections

  • listContainsExactlyInAnyOrder

Lambda Predicate matchers for objects and primitives

Mockito already accepts lambdas for argThat(), intThat(), etc. but does not accept Predicate instances, and the lambdas accepted by argThat(), intThat() etc. require type casts (Note - this seems to be an area which is rapidly changing in the 2.0.XX betas of Mockito). The following methods accept a Predicate instance or a lambda without the need for a type cast.

  • objectMatches (use only for objects, not for auto-boxed primitive types)
  • intMatches
  • longMatches
  • shortMatches
  • doubleMatches
  • floatMatches
  • byteMatches
  • charMatches

New : Injection methods

  • injectByName - Simple dependency injection which works for a private field with no setter
  • injectByType - Injection of multiple objects based on their type and the alphabetical order of field names

##Blog The Green Bar

You can’t perform that action at this time.