类 ExpectedLookupTemplate


  • public class ExpectedLookupTemplate
    extends JndiTemplate
    Simple extension of the JndiTemplate class that always returns a given object.

    Very useful for testing. Effectively a mock object.

    作者:
    Rod Johnson, Juergen Hoeller
    • 构造器详细资料

      • ExpectedLookupTemplate

        public ExpectedLookupTemplate​(String name,
                                      Object object)
        Construct a new JndiTemplate that will always return the given object, but honour only requests for the given name.
        参数:
        name - the name the client is expected to look up
        object - the object that will be returned
    • 方法详细资料

      • addObject

        public void addObject​(String name,
                              Object object)
        Add the given object to the list of JNDI objects that this template will expose.
        参数:
        name - the name the client is expected to look up
        object - the object that will be returned
      • lookup

        public Object lookup​(String name)
                      throws NamingException
        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.
        覆盖:
        lookup 在类中 JndiTemplate
        参数:
        name - the JNDI name of the object
        返回:
        object found (cannot be null; if a not so well-behaved JNDI implementations returns null, a NamingException gets thrown)
        抛出:
        NamingException - if there is no object with the given name bound to JNDI