RenderClassLoader extends ClassLoader { @Nullable protected Class<?> loadClassFile(String fqcn, @NotNull VirtualFile classFile) { try { byte[] data = classFile.contentsToByteArray(); return loadClass(fqcn, data); } catch (IOException e) { LOG.warn(e); } return null; } RenderClassLoader(@Nullable ClassLoader parent);   }
@Test public void testRemovingClassFile() throws IOException { ourLoggerInstance = new DefaultLogger("") { @Override public void error(@NonNls String message, @Nullable Throwable t, @NonNls @NotNull String... details) { fail("Logger shouldn't receive any error calls"); } }; File classSource = new File(AndroidTestBase.getTestDataPath(), "rendering/renderClassLoader/MyJarClass.class"); byte[] classBytes = Files.readAllBytes(classSource.toPath()); RenderClassLoader loader = new RenderClassLoader(this.getClass().getClassLoader()) { @Override protected List<URL> getExternalJars() { return ImmutableList.of(); } @NotNull @Override protected Class<?> defineClassAndPackage(@NotNull String name, @NotNull byte[] b, int offset, int len) { return RenderClassLoaderTest.class; } }; VirtualFile vFile = mock(VirtualFile.class); when(vFile.contentsToByteArray()).thenReturn(classBytes); assertEquals(RenderClassLoaderTest.class, loader.loadClassFile("com.myjar.MyJarClass", vFile)); vFile = mock(VirtualFile.class); when(vFile.contentsToByteArray()).thenThrow(new FileNotFoundException("")); assertNull(loader.loadClassFile("com.myjar.MyJarClass", vFile)); }