### Question:
ChannelConfigImpl implements ChannelConfig, LogChannel { static Integer timeStringToMillis(String timeString) throws ParseException { if (timeString == null || timeString.isEmpty()) { return null; } Matcher timeMatcher = timePattern.matcher(timeString); if (!timeMatcher.matches()) { throw new ParseException(MessageFormat.format("Unknown time string: ''{0}''.", timeString)); } String timeNumStr = timeMatcher.group(1); Long timeNum = parseTimeNumFrom(timeNumStr); String timeUnit = timeMatcher.group(2); final TimeUnit milliseconds = TimeUnit.MILLISECONDS; if (timeUnit == null) { return timeNum.intValue(); } switch (timeUnit) { case "s": return (int) milliseconds.convert(timeNum, TimeUnit.SECONDS); case "m": return (int) milliseconds.convert(timeNum, TimeUnit.MINUTES); case "h": return (int) milliseconds.convert(timeNum, TimeUnit.HOURS); case "ms": return timeNum.intValue(); default: throw new ParseException("Unknown time unit: " + timeUnit); } } ChannelConfigImpl(String id, DeviceConfigImpl deviceParent); @Override String getId(); @Override void setId(String id); @Override String getDescription(); @Override void setDescription(String description); @Override String getChannelAddress(); @Override void setChannelAddress(String address); @Override String getUnit(); @Override void setUnit(String unit); @Override ValueType getValueType(); @Override void setValueType(ValueType valueType); @Override Integer getValueTypeLength(); @Override void setValueTypeLength(Integer length); @Override Double getScalingFactor(); @Override void setScalingFactor(Double factor); @Override Double getValueOffset(); @Override void setValueOffset(Double offset); @Override Boolean isListening(); @Override void setListening(Boolean listening); @Override Integer getSamplingInterval(); @Override void setSamplingInterval(Integer samplingInterval); @Override Integer getSamplingTimeOffset(); @Override void setSamplingTimeOffset(Integer samplingTimeOffset); @Override String getSamplingGroup(); @Override void setSamplingGroup(String group); @Override Integer getLoggingInterval(); @Override void setLoggingInterval(Integer loggingInterval); @Override Integer getLoggingTimeOffset(); @Override void setLoggingTimeOffset(Integer loggingTimeOffset); @Override Boolean isDisabled(); @Override void setDisabled(Boolean disabled); @Override void delete(); @Override List<ServerMapping> getServerMappings(); @Override DeviceConfig getDevice(); boolean isSampling(); @Override void addServerMapping(ServerMapping serverMapping); @Override void deleteServerMappings(String id);  }### Answer:
@Test @Parameters({ "99ms, 99", "100, 100", "1s, 1000", "1m, 60000", "0h, 0", "5h, 18000000", "24h, 86400000" }) public void testTimeStringToMillis(String timeStr, Integer expTimeInMillis) throws Exception { Integer millis = timeStringToMillis(timeStr); assertEquals(expTimeInMillis, millis); }
@Test public void testEmptyTimeStringToMillis() throws Exception { Integer millis = timeStringToMillis(""); assertNull(millis); }
@Test(expected = ParseException.class) @Parameters({ "99w", "1y", "a77" }) public void testTimeStringToMillisFail(String timeStr) throws Exception { timeStringToMillis(timeStr); }