spring-framework / org.springframework.mock.jndi / ExpectedLookupTemplate

ExpectedLookupTemplate

open class ExpectedLookupTemplate : JndiTemplate

Simple extension of the JndiTemplate class that always returns a given object.

Very useful for testing. Effectively a mock object.

Author
Rod Johnson

Author
Juergen Hoeller

Constructors

<init>

ExpectedLookupTemplate()

Construct a new JndiTemplate that will always return given objects for given names. To be populated through addObject calls.

ExpectedLookupTemplate(name: String, object: Any)

Construct a new JndiTemplate that will always return the given object, but honour only requests for the given name.

Functions

addObject

open fun addObject(name: String, object: Any): Unit

Add the given object to the list of JNDI objects that this template will expose.

lookup

open fun lookup(name: String): Any

If the name is the expected name specified in the constructor, return the object provided in the constructor. If the name is unexpected, a respective NamingException gets thrown.