### Question:
DataSourceResourceLoader extends HadoopClassLoader { public void addFile(@Nullable final String path) { if (path == null) { log.debug("Ignoring null file"); return; } final String name = FilenameUtils.getName(path); if (files.contains(name)) { log.debug("Ignoring existing file: {}", path); return; } URI uri; try { uri = URI.create(path); if (uri.getScheme() == null) { uri = URI.create("file: } } catch (final IllegalArgumentException e) { log.debug("Ignoring invalid path: {}", path, e); return; } try { if (!FileSystemUtil.fileExists(uri, sparkContext.hadoopConfiguration())) { log.debug("Ignoring missing file: {}", path); return; } } catch (final IOException e) { log.debug("Failed to determine if file [{}] exists: {}", path, e, e); } log.debug("Updating Spark files with: {}", path); sparkContext.addFile(path); files.add(name); } DataSourceResourceLoader(@Nonnull final SparkContext sparkContext, @Nonnull final ClassLoader parent); void addFile(@Nullable final String path); @Nonnull Optional<DataSourceRegister> getDataSource(@Nonnull final String shortName); T runWithThreadContext(@Nonnull final Callable<T> callable); void runWithThreadContext(@Nonnull final Runnable runnable);  }### Answer:
@Test public void addFile() { final SparkContext sparkContext = Mockito.mock(SparkContext.class); Mockito.when(sparkContext.hadoopConfiguration()).thenReturn(new Configuration(false)); final DataSourceResourceLoader loader = DataSourceResourceLoader.create(sparkContext); loader.addFile(null); Mockito.verify(sparkContext, Mockito.never()).addFile(Mockito.anyString()); loader.addFile("file:/tmp/" + UUID.randomUUID().toString()); Mockito.verify(sparkContext, Mockito.never()).addFile(Mockito.anyString()); final String filePath = getClass().getResource("DataSourceResourceLoaderTest.class").toString(); loader.addFile(filePath); loader.addFile(filePath); Mockito.verify(sparkContext, Mockito.times(1)).addFile(filePath); }