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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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="http://www.springframework.org/schema/beans"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org...