Book Image

Mockito for Spring

By : Sujoy Acharya
Book Image

Mockito for Spring

By: Sujoy Acharya

Overview of this book

Table of Contents (12 chapters)
Mockito for Spring
About the Author
About the Reviewers

Mocking the JNDI lookup

Sometimes, we need to mock the <jee:jndi-lookup>/JNDI lookup with a mock value in the out-of-container tests. The org.springframework.mock.jndi package contains an implementation of the JNDI SPI, which you can use to set up a simple JNDI environment for test suites or standalone applications. In the following example, we'll define <jee:jndi-lookup> for the DataSource resource in applicationContext and mock out the lookup from the test. The following are the steps to mock up a JNDI call:

  1. Create an applicationContext.xml file in the com.packt.jndi package, with the following details:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""