@Test public void createsDirectory_basedOnDefinitionPathAndCurrentTime_inInstancesDirectory() throws Exception { String instancesDir = Files.createTempDir().getAbsolutePath(); when(pathProvider.getDirPath(StorageSubdirectory.INSTANCES)).thenReturn(instancesDir); when(clock.getCurrentTime()).thenReturn(simpleDateFormat.parse("1990-04-24_00-00-00").getTime()); FormInstanceFileCreator instanceFileCreator = new FormInstanceFileCreator(pathProvider, clock); instanceFileCreator.createInstanceFile("/blah/blah/Cool form name.xml"); File instanceDir = new File(instancesDir + File.separator + "Cool form name_1990-04-24_00-00-00"); assertThat(instanceDir.exists(), is(true)); assertThat(instanceDir.isDirectory(), is(true)); }
public File createInstanceFile(String formDefinitionPath) { String timestamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH) .format(new Date(clock.getCurrentTime())); String formFileName = formDefinitionPath.substring(formDefinitionPath.lastIndexOf('/') + 1, formDefinitionPath.lastIndexOf('.')); String instancesDir = storagePathProvider.getDirPath(StorageSubdirectory.INSTANCES); String instanceDir = instancesDir + File.separator + formFileName + "_" + timestamp; if (FileUtils.createFolder(instanceDir)) { return new File(instanceDir + File.separator + formFileName + "_" + timestamp + ".xml"); } else { Timber.e("Error creating form instance file"); return null; } }
FormInstanceFileCreator { public File createInstanceFile(String formDefinitionPath) { String timestamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH) .format(new Date(clock.getCurrentTime())); String formFileName = formDefinitionPath.substring(formDefinitionPath.lastIndexOf('/') + 1, formDefinitionPath.lastIndexOf('.')); String instancesDir = storagePathProvider.getDirPath(StorageSubdirectory.INSTANCES); String instanceDir = instancesDir + File.separator + formFileName + "_" + timestamp; if (FileUtils.createFolder(instanceDir)) { return new File(instanceDir + File.separator + formFileName + "_" + timestamp + ".xml"); } else { Timber.e("Error creating form instance file"); return null; } } }
FormInstanceFileCreator { public File createInstanceFile(String formDefinitionPath) { String timestamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH) .format(new Date(clock.getCurrentTime())); String formFileName = formDefinitionPath.substring(formDefinitionPath.lastIndexOf('/') + 1, formDefinitionPath.lastIndexOf('.')); String instancesDir = storagePathProvider.getDirPath(StorageSubdirectory.INSTANCES); String instanceDir = instancesDir + File.separator + formFileName + "_" + timestamp; if (FileUtils.createFolder(instanceDir)) { return new File(instanceDir + File.separator + formFileName + "_" + timestamp + ".xml"); } else { Timber.e("Error creating form instance file"); return null; } } FormInstanceFileCreator(StoragePathProvider storagePathProvider, Clock clock); }
FormInstanceFileCreator { public File createInstanceFile(String formDefinitionPath) { String timestamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH) .format(new Date(clock.getCurrentTime())); String formFileName = formDefinitionPath.substring(formDefinitionPath.lastIndexOf('/') + 1, formDefinitionPath.lastIndexOf('.')); String instancesDir = storagePathProvider.getDirPath(StorageSubdirectory.INSTANCES); String instanceDir = instancesDir + File.separator + formFileName + "_" + timestamp; if (FileUtils.createFolder(instanceDir)) { return new File(instanceDir + File.separator + formFileName + "_" + timestamp + ".xml"); } else { Timber.e("Error creating form instance file"); return null; } } FormInstanceFileCreator(StoragePathProvider storagePathProvider, Clock clock); File createInstanceFile(String formDefinitionPath); }
FormInstanceFileCreator { public File createInstanceFile(String formDefinitionPath) { String timestamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.ENGLISH) .format(new Date(clock.getCurrentTime())); String formFileName = formDefinitionPath.substring(formDefinitionPath.lastIndexOf('/') + 1, formDefinitionPath.lastIndexOf('.')); String instancesDir = storagePathProvider.getDirPath(StorageSubdirectory.INSTANCES); String instanceDir = instancesDir + File.separator + formFileName + "_" + timestamp; if (FileUtils.createFolder(instanceDir)) { return new File(instanceDir + File.separator + formFileName + "_" + timestamp + ".xml"); } else { Timber.e("Error creating form instance file"); return null; } } FormInstanceFileCreator(StoragePathProvider storagePathProvider, Clock clock); File createInstanceFile(String formDefinitionPath);  }