### Question:
LazyJndiResolver implements InvocationHandler { @SuppressWarnings("unchecked") public static <T> T newInstance(String name, Class<?> objectType) { return (T) Proxy.newProxyInstance( ClassLoaderUtils.getClassLoader(), new Class[]{objectType}, new LazyJndiResolver(name)); } private  LazyJndiResolver(); private  LazyJndiResolver(String name); @Override Object invoke(Object proxy, Method method, Object[] args); @SuppressWarnings("unchecked") static T newInstance(String name, Class<?> objectType);  }### Answer:
@Test public void testLazyLookupFailure() { DataSource dataSource = LazyJndiResolver.newInstance("jdbc/DS", DataSource.class); try { dataSource.getLogWriter(); } catch (Exception e) { assertEquals(NameNotFoundException.class, e.getCause().getClass()); } }
@Test public void testLazyLookup() { jndiTestUtils.namingContext().bind("jdbc/DS", Mockito.mock(DataSource.class)); DataSource dataSource = LazyJndiResolver.newInstance("jdbc/DS", DataSource.class); try { PrintWriter printWriter = new PrintWriter(System.out); when(dataSource.getLogWriter()).thenReturn(printWriter); assertSame(printWriter, dataSource.getLogWriter()); } catch (SQLException e) { fail("There should be no exception thrown!"); } }