FileResourceFactory implements IResourceFactory { protected Constructor<?> getNIOFileResourceConstructor(Class<?>... args) { final String method = "getNIOFileResourceConstructor"; if (tryNIO && nioFileResourceConstructor == null) { try { Class<?> clazz = getNIOFileResourceClass(); if (clazz != null) nioFileResourceConstructor = clazz.getConstructor(args); } catch (NoSuchMethodException e) { tryNIO = false; if (log.isLoggable(Level.SEVERE)) { log.log(Level.SEVERE, e.getMessage(), e); } if (log.isLoggable(Level.WARNING)) log.logp(Level.WARNING, CLAZZ, method, WARN_MESSAGE); } catch (SecurityException e) { tryNIO = false; if (log.isLoggable(Level.SEVERE)) { log.log(Level.SEVERE, e.getMessage(), e); } if (log.isLoggable(Level.WARNING)) log.logp(Level.WARNING, CLAZZ, method, WARN_MESSAGE); } } return nioFileResourceConstructor; } FileResourceFactory(); protected  FileResourceFactory(ClassLoader classLoader); @Override IResource newResource(URI uri); @Override boolean handles(URI uri);  }
@Test public void testErrorLoadingClass() throws ClassNotFoundException { List<Throwable> throwables = ImmutableList.<Throwable>builder() .add(new ClassNotFoundException()) .add(new UnsupportedClassVersionError()) .build(); for (Throwable throwable : throwables) { factory = new FileResourceFactory(classLoader); control.reset(); EasyMock.expect(classLoader.loadClass(EasyMock.isA(String.class))) .andThrow(throwable).once(); control.replay(); Constructor<?> cons = factory.getNIOFileResourceConstructor(); Assert.assertNull(cons); cons = factory.getNIOFileResourceConstructor(); control.verify(); Assert.assertNull(cons); } }
@Test public void testgetNIOResource() { factory = new FileResourceFactory(); Assert.assertNotNull(factory.getNIOFileResourceConstructor(URI.class)); }