@Test public void testEncodeField() { UrlEncodeFieldProcessor proc = new UrlEncodeFieldProcessor.Builder() .named("foo") .encodingField("toEncode") .withCharacterEncoding("UTF-8") .build(); List<String> values = new ArrayList<>(); values.add("semi ;"); values.add("slash /"); values.add("question ?"); values.add("colon :"); values.add("at @"); values.add("and &"); values.add("equal ="); values.add("plus +"); values.add("dollar $"); values.add("comma ,"); expect(docMock.get("toEncode")).andReturn(values); replay(); proc.processDocument(docMock); assertEquals("semi+%3B", values.get(0)); assertEquals("slash+%2F", values.get(1)); assertEquals("question+%3F", values.get(2)); assertEquals("colon+%3A", values.get(3)); assertEquals("at+%40", values.get(4)); assertEquals("and+%26", values.get(5)); assertEquals("equal+%3D", values.get(6)); assertEquals("plus+%2B", values.get(7)); assertEquals("dollar+%24", values.get(8)); assertEquals("comma+%2C", values.get(9)); }
@Override public Document[] processDocument(Document document) { List<String> values = document.get(fieldToEncode); for (int i = 0; i < values.size(); i++) { String value = values.get(i); try { values.set(i, URLEncoder.encode(value, charset)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return new Document[]{document}; }
UrlEncodeFieldProcessor implements DocumentProcessor { @Override public Document[] processDocument(Document document) { List<String> values = document.get(fieldToEncode); for (int i = 0; i < values.size(); i++) { String value = values.get(i); try { values.set(i, URLEncoder.encode(value, charset)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return new Document[]{document}; } }
UrlEncodeFieldProcessor implements DocumentProcessor { @Override public Document[] processDocument(Document document) { List<String> values = document.get(fieldToEncode); for (int i = 0; i < values.size(); i++) { String value = values.get(i); try { values.set(i, URLEncoder.encode(value, charset)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return new Document[]{document}; }  }
UrlEncodeFieldProcessor implements DocumentProcessor { @Override public Document[] processDocument(Document document) { List<String> values = document.get(fieldToEncode); for (int i = 0; i < values.size(); i++) { String value = values.get(i); try { values.set(i, URLEncoder.encode(value, charset)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return new Document[]{document}; }  @Override String getName(); @Override Document[] processDocument(Document document); void setName(String name); void setFieldToEncode(String fieldToEncode); void setCharset(String encoding); }
UrlEncodeFieldProcessor implements DocumentProcessor { @Override public Document[] processDocument(Document document) { List<String> values = document.get(fieldToEncode); for (int i = 0; i < values.size(); i++) { String value = values.get(i); try { values.set(i, URLEncoder.encode(value, charset)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return new Document[]{document}; }  @Override String getName(); @Override Document[] processDocument(Document document); void setName(String name); void setFieldToEncode(String fieldToEncode); void setCharset(String encoding);  }