### Question:
JndiUtils { public static <T> T lookup(String name) { InitialContext initialContext = initialContext(); try { @SuppressWarnings("unchecked") T object = (T) initialContext.lookup(name); if (object == null) { throw new NameNotFoundException(name + " was found but is null"); } return object; } catch (NameNotFoundException e) { throw new IllegalArgumentException(name + " was not found in JNDI", e); } catch (NamingException e) { throw new IllegalArgumentException("JNDI lookup failed", e); } finally { closeContext(initialContext); } } private  JndiUtils(); static T lookup(String name);  }### Answer:
@Test public void testLookupUnboundObject() { try { JndiUtils.lookup("abc"); fail("There shouldn't be any object bound with this name"); } catch (IllegalArgumentException e) { assertEquals(NameNotFoundException.class, e.getCause().getClass()); assertEquals("abc was not found in JNDI", e.getMessage()); } }
@Test public void testLookupSuccess() { namingContext.bind("abc", "def"); assertEquals("def", JndiUtils.lookup("abc")); }