DefaultBindingNamingEnumeration implements NamingEnumeration<Binding> { private void checkClosed() throws NamingException { if (list == null) { throw new NamingException("Cannot call any method on a closed NamingEnumeration"); } } DefaultBindingNamingEnumeration(List<Binding> list); @Override Binding next(); @Override boolean hasMore(); @Override void close(); @Override boolean hasMoreElements(); @Override Binding nextElement();  }
@Test void testCheckClosed() throws Exception { DefaultBindingNamingEnumeration enumeration = new DefaultBindingNamingEnumeration(new ArrayList<>()); enumeration.close(); assertThrows(NamingException.class, enumeration::close); }