DiscardValuesTooLongFilter extends MetadataFilterImpl { @Override public MetadataCollection filter(MetadataCollection original) { MetadataCollection result = new MetadataCollection(); int maxLen = maxLength(); result.addAll(original.stream().filter(e -> e.getValue().length() <= maxLen) .collect(Collectors.toList())); return result; } DiscardValuesTooLongFilter();  DiscardValuesTooLongFilter(Integer i); @Override MetadataCollection filter(MetadataCollection original); Integer getMaxLengthChars(); void setMaxLengthChars(Integer bytes);  }
@Test public void testFilterMessage() throws Exception { DiscardValuesTooLongFilter filter = new DiscardValuesTooLongFilter(36); MetadataCollection c = filter.filter(createMessage()); assertEquals(4, c.size()); }
@Test public void testFilterSet() throws Exception { DiscardValuesTooLongFilter filter = new DiscardValuesTooLongFilter(36); MetadataCollection c = filter.filter(createMessage().getMetadata()); assertEquals(4, c.size()); }
@Test public void testFilterCollection() throws Exception { DiscardValuesTooLongFilter filter = new DiscardValuesTooLongFilter(36); MetadataCollection c = filter.filter(new MetadataCollection(createMessage().getMetadata())); assertEquals(4, c.size()); }
@Test public void testFilterMessage_EmptyMetadata() throws Exception { DiscardValuesTooLongFilter filter = new DiscardValuesTooLongFilter(36); MetadataCollection c = filter.filter(AdaptrisMessageFactory.getDefaultInstance().newMessage()); assertEquals(0, c.size()); }