### Question:
VFSRegistryHelper { public Path ensureDirectory(final String directory) { Path directoryPath = provisioningRootPath.resolve(directory); if (!ioService.exists(directoryPath)) { directoryPath = ioService.createDirectory(directoryPath); } return directoryPath; } VFSRegistryHelper(); @Inject  VFSRegistryHelper(final VFSMarshallerRegistry marshallerRegistry,
                             final @Named("ioStrategy") IOService ioService,
                             final @Named("systemFS") FileSystem fileSystem); Path ensureDirectory(final String directory); String md5Hex(String content); void storeEntry(final Path path,
                           final Object value); Object readEntry(final Path path); List<Object> readEntries(final Path rootPath,
                                    final DirectoryStream.Filter<Path> filter); void writeBatch(final Path path,
                           final String content); void deleteBatch(final Path path);  }### Answer:
@Test public void testEnsureDirectoryWhenDirectoryExists() { Path path = mock(Path.class); when(provisioningPath.resolve(DIRECTORY_NAME)).thenReturn(path); when(ioService.exists(path)).thenReturn(true); Path result = registryHelper.ensureDirectory(DIRECTORY_NAME); verify(provisioningPath, times(1)).resolve(DIRECTORY_NAME); verify(ioService, never()).createDirectory(path); assertEquals(path, result); }
@Test public void testEnsureDirectoryWhenDirectoryNotExists() { Path path = mock(Path.class); Path createdPath = mock(Path.class); when(provisioningPath.resolve(DIRECTORY_NAME)).thenReturn(path); when(ioService.exists(path)).thenReturn(false); when(ioService.createDirectory(path)).thenReturn(createdPath); Path result = registryHelper.ensureDirectory(DIRECTORY_NAME); verify(provisioningPath, times(1)).resolve(DIRECTORY_NAME); verify(ioService, times(1)).createDirectory(path); assertEquals(createdPath, result); }