PatternListConverter implements Converter<List<Pattern>> { @Override public String convertTo(List<Pattern> value) { if (value == null) { throw new ParameterException("Couldn't convert \"null\" to string."); } return Joiner.on(SEPARATOR) .skipNulls() .join(value); }  @Override List<Pattern> convertFrom(String value); @Override String convertTo(List<Pattern> value);  }
@Test public void convertToWithNull() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("Couldn't convert \"null\" to string."); new PatternListConverter().convertTo(null); }
@Test public void convertToWithEmptyList() throws Exception { final String s = new PatternListConverter().convertTo(Collections.emptyList()); assertEquals("", s); }
@Test public void convertToWithRegularList() throws Exception { final String s = new PatternListConverter().convertTo( ImmutableList.of(Pattern.compile("foobar.*"), Pattern.compile("foo(bar|baz)"))); assertEquals("foobar.*,foo(bar|baz)", s); }
@Test public void convertToWithListContainingNull() throws Exception { final List<Pattern> patterns = new ArrayList<>(); patterns.add(Pattern.compile("foobar.*")); patterns.add(null); patterns.add(Pattern.compile("foo(bar|baz)")); final String s = new PatternListConverter().convertTo(patterns); assertEquals("foobar.*,foo(bar|baz)", s); }