### Question:
FileNameService { String generateReportFileName(final String scenarioName, final String extension) { final String truncatedScenarioName = StringUtils.left(scenarioName, MAX_SCENARIO_NAME_LENGTH); final String safeScenarioName = truncatedScenarioName.replace(' ', '-').replaceAll("[^a-zA-Z0-9\\-]", ""); final String formattedDate = new SimpleDateFormat(HUMAN_AND_MACHINE_READABLE_TIMESTAMP_PATTERN).format(dateService.now()); return formattedDate + "-" + safeScenarioName + (StringUtils.isEmpty(extension) ? "" : ("." + extension)); }    }### Answer:
@Test public void generateReportFileName_ShouldGenerateADatedFileName_WhenCalledWithAnExtension() { when(dateService.now()).thenReturn(timestamp(2018, 1, 1, 1, 1, 1)); final String fileName = cut.generateReportFileName("Name", "ext"); assertThat(fileName).isEqualTo("2018.02.01-01h01m01.000-Name.ext"); }
@Test public void generateReportFileName_ShouldGenerateADatedDirectoryName_WhenCalledWithoutExtension() { when(dateService.now()).thenReturn(timestamp(2018, 1, 1, 1, 1, 1)); final String fileName = cut.generateReportFileName("Name", null); assertThat(fileName).isEqualTo("2018.02.01-01h01m01.000-Name"); }
@Test public void generateReportFileName_ShouldTruncateName_WhenCalledWithALargeScenarioName() { when(dateService.now()).thenReturn(timestamp(2018, 1, 1, 1, 1, 1)); final String fileName = cut.generateReportFileName("" + "Veeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" + "Loooooooooooooooooooooooooooooooonnnnnnnnnnnnnnnng" + "Name", null); assertThat(fileName).isEqualTo("2018.02.01-01h01m01.000-VeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyLoooooooooooooooooooooooooooooooonnnnnnnnnnnnnnnngN"); }
@Test public void generateReportFileName_ShouldReplaceSpacesWithDashes_WhenScenarioNameHasSpaces() { when(dateService.now()).thenReturn(timestamp(2018, 1, 1, 1, 1, 1)); final String fileName = cut.generateReportFileName("Scenario Name", null); assertThat(fileName).isEqualTo("2018.02.01-01h01m01.000-Scenario-Name"); }
@Test public void generateReportFileName_ShouldRemoveNonAlphaNumericCharacters_WhenScenarioNameHasSpecialCharacters() { when(dateService.now()).thenReturn(timestamp(2018, 1, 1, 1, 1, 1)); final String fileName = cut.generateReportFileName("Scenario+Name!042", null); assertThat(fileName).isEqualTo("2018.02.01-01h01m01.000-ScenarioName042"); }