@Test(expected = RuntimeException.class) public void testCharsetNotFound() { UrlEncodeFieldProcessor proc = new UrlEncodeFieldProcessor.Builder() .named("foo") .encodingField("toEncode") .withCharacterEncoding("NO_SUCH_ENCODING!") .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); }
@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);  }