### Question:
ParameterHelper implements JournalConstants { public static long parseParametersForAgeLimit(Map<String, String> parameters) throws JournalException { String ageString = ParameterHelper .getOptionalStringParameter(parameters, PARAMETER_JOURNAL_FILE_AGE_LIMIT, DEFAULT_AGE_LIMIT); Pattern p = Pattern.compile("([0-9]+)([DHM]?)"); Matcher m = p.matcher(ageString); if (!m.matches()) { throw new JournalException("Parameter '" + PARAMETER_JOURNAL_FILE_AGE_LIMIT + "' must be an integer number of seconds, optionally " + "followed by 'D'(days), 'H'(hours), or 'M'(minutes), " + "or a 0 to indicate no age limit"); } long age = Long.parseLong(m.group(1)) * 1000; String factor = m.group(2); if ("D".equals(factor)) { age *= 24 * 60 * 60; } else if ("H".equals(factor)) { age *= 60 * 60; } else if ("M".equals(factor)) { age *= 60; } return age; } private  ParameterHelper(); static String getOptionalStringParameter(Map<String, String> parameters,
                                                    String parameterName,
                                                    String defaultValue); static boolean getOptionalBooleanParameter(Map<String, String> parameters,
                                                      String parameterName,
                                                      boolean defaultValue); static File parseParametersForWritableDirectory(Map<String, String> parameters,
                                                           String parameterName); static String parseParametersForFilenamePrefix(Map<String, String> parameters); static long parseParametersForSizeLimit(Map<String, String> parameters); static long parseParametersForAgeLimit(Map<String, String> parameters);  }### Answer:
@Test public void testParseParametersForAgeLimit_Default() throws JournalException { long actual = ParameterHelper.parseParametersForAgeLimit(parameters); parameters.put(PARAMETER_JOURNAL_FILE_AGE_LIMIT, DEFAULT_AGE_LIMIT); long expected = ParameterHelper.parseParametersForAgeLimit(parameters); assertEquals(expected, actual); }
@Test public void testParseParametersForAgeLimit_NoSuffix() throws JournalException { long expected = 4196L * 1000L; parameters.put(PARAMETER_JOURNAL_FILE_AGE_LIMIT, "4196"); long actual = ParameterHelper.parseParametersForAgeLimit(parameters); assertEquals(expected, actual); }
@Test public void testParseParametersForAgeLimit_M() throws JournalException { long expected = 168L * 1000L * 60L; parameters.put(PARAMETER_JOURNAL_FILE_AGE_LIMIT, "168M"); long actual = ParameterHelper.parseParametersForAgeLimit(parameters); assertEquals(expected, actual); }
@Test public void testParseParametersForAgeLimit_H() throws JournalException { long expected = 5L * 1000L * 60L * 60L; parameters.put(PARAMETER_JOURNAL_FILE_AGE_LIMIT, "5H"); long actual = ParameterHelper.parseParametersForAgeLimit(parameters); assertEquals(expected, actual); }
@Test public void testParseParametersForAgeLimit_D() throws JournalException { long expected = 999L * 1000L * 60L * 60L * 24L; parameters.put(PARAMETER_JOURNAL_FILE_AGE_LIMIT, "999D"); long actual = ParameterHelper.parseParametersForAgeLimit(parameters); assertEquals(expected, actual); }
@Test public void testParseParametersForAgeLimit_InvalidSuffix() { parameters.put(PARAMETER_JOURNAL_FILE_AGE_LIMIT, "5X"); try { ParameterHelper.parseParametersForAgeLimit(parameters); fail("Expected a JournalException"); } catch (JournalException e) { } }