TmTextUnitMappingConverter implements IStringConverter<Map<Long, Long>> { @Override public Map<Long, Long> convert(String value) { Map<Long, Long> map = null; if (value != null) { try { return Splitter.on(";").withKeyValueSeparator(":").split(value).entrySet().stream(). collect(Collectors.toMap( e -> Long.valueOf(e.getKey()), e -> Long.valueOf(e.getValue()))); } catch (IllegalArgumentException iae) { throw new ParameterException("Invalid source to target textunit id mapping [" + value + "]"); } } return map; }  @Override Map<Long, Long> convert(String value);  }
@Test public void testConvertNull() { TmTextUnitMappingConverter tmTextUnitMappingConverter = new TmTextUnitMappingConverter(); Map<Long, Long> convert = tmTextUnitMappingConverter.convert(null); assertNull(convert); }
@Test public void testConvertValid() { TmTextUnitMappingConverter tmTextUnitMappingConverter = new TmTextUnitMappingConverter(); Map<Long, Long> convert = tmTextUnitMappingConverter.convert("1001:2001;1002:2002"); assertEquals(2001L, convert.get(1001L).longValue()); assertEquals(2002L, convert.get(1002L).longValue()); assertEquals(2, convert.size()); }
@Test(expected = ParameterException.class) public void testConvertInvalid() { TmTextUnitMappingConverter tmTextUnitMappingConverter = new TmTextUnitMappingConverter(); Map<Long, Long> convert = tmTextUnitMappingConverter.convert("dsafdsf"); assertEquals(0, convert.size()); }