ErrorReportSender { protected void addHttpPostParams(Map<String, String> values, PostMethod method) { for (String key : values.keySet()) { String parameterValue = values.get(key); parameterValue = parameterValue != null ? parameterValue : NULL; method.setParameter(key, parameterValue); } }  String getProxy(); void setProxy(String proxy); int getProxyPort(); void setProxyPort(int proxyPort); String getUser(); void setUser(String user); String getPassword(); void setPassword(String password); String sendReport(Map<String, String> values); String getSendUrl(); static final String NULL; }
@Test public void addHttpPostParams() { ErrorReportSender sender = new ErrorReportSender(); Map<String, String> values = new HashMap<>(); values.put("key1", "value1"); values.put("key2", "value2"); PostMethod method = new PostMethod(); sender.addHttpPostParams(values, method); assertEquals("value1", method.getParameter("key1").getValue()); assertEquals("value2", method.getParameter("key2").getValue()); }
@Test public void addHttpPostParamsIsNullSafe() { ErrorReportSender sender = new ErrorReportSender(); Map<String, String> values = new HashMap<>(); values.put("key2", null); PostMethod method = new PostMethod(); sender.addHttpPostParams(values, method); assertEquals("null", method.getParameter("key2").getValue()); }