ContextHelper { public static void close(@Nullable Context context, boolean swallowIOException) throws NamingException { if (context == null) { return; } try { context.close(); } catch (NamingException e) { if (swallowIOException) { LOG.warn("NamingException thrown while closing context.", e); } else { throw e; } } } private  ContextHelper(); static void close(@Nullable Context context, boolean swallowIOException); static void closeQuietly(@Nullable Context context);  }
@Test(expected = NamingException.class) public void shouldNotSwallow() throws Exception { Context context = mock(Context.class); doThrow(new NamingException()).when(context).close(); ContextHelper.close(context, false); }