O'Reilly logo

Mockito Cookbook by Marcin Grzejszczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Injecting test doubles instead of beans with Guice using Jukito

In the following recipe, we will replace an existing bean with a test double using Jukito annotations (since this library has a specially defined JUnit runner, it integrates perfectly with JUnit—there is no official support for TestNG).

Getting ready

In order to profit from Jukito, you have to add it to your build. The following is the configuration for Gradle:

testCompile 'org.jukito:jukito:1.4'

A sample Maven dependency configuration is given as follows:

<dependency>
	<groupId>org.jukito</groupId>
	<artifactId>jukito</artifactId>
	<version>1.4</version>
</dependency>            

We will reuse the previous example of the tax transferring system for a given person, as shown in the following code:

public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required