ApiUtil { public String cleanArgument(String arg) { if (arg == null) { return null; } Matcher graphable_matcher = non_graphable_pattern.matcher(arg); String filtered_of_non_graphing = graphable_matcher.replaceAll(""); Matcher prohibited_matcher = prohibited_pattern.matcher(filtered_of_non_graphing); return prohibited_matcher.replaceAll(""); }  String cleanArgument(String arg); static Pattern non_graphable_pattern; static Pattern prohibited_pattern; }
@Test public void testCleanArgument() throws Exception { Map<String, String> queryToExpectedMap = new HashMap<>(); queryToExpectedMap.put(null, null); queryToExpectedMap.put("", ""); queryToExpectedMap.put("arg", "arg"); queryToExpectedMap.put(" ", ""); queryToExpectedMap.put(" arg", "arg"); queryToExpectedMap.put("a rg", "arg"); queryToExpectedMap.put("arg ", "arg"); queryToExpectedMap.put(" arg ", "arg"); queryToExpectedMap.put(" a r g ", "arg"); queryToExpectedMap.put("\targ", "arg"); queryToExpectedMap.put("a\trg", "arg"); queryToExpectedMap.put("\rarg", "arg"); queryToExpectedMap.put("a\rrg", "arg"); queryToExpectedMap.put("\narg", "arg"); queryToExpectedMap.put("a\nrg", "arg"); queryToExpectedMap.put("\u0000arg", "arg"); queryToExpectedMap.put("\u0000arg", "arg"); queryToExpectedMap.put("a\u0005rg", "arg"); queryToExpectedMap.put("a\u0005rg", "arg"); queryToExpectedMap.put("<arg", "arg"); queryToExpectedMap.put("a<rg", "arg"); queryToExpectedMap.put(">arg", "arg"); queryToExpectedMap.put("a>rg", "arg"); queryToExpectedMap.put("&arg", "arg"); queryToExpectedMap.put("a&rg", "arg"); queryToExpectedMap.put("\"arg", "arg"); queryToExpectedMap.put("a\"rg", "arg"); queryToExpectedMap.put("\'arg", "arg"); queryToExpectedMap.put("a\'rg", "arg"); queryToExpectedMap.put("\\arg", "arg"); queryToExpectedMap.put("a\\rg", "arg"); queryToExpectedMap.put(" a<r>\u0005g &\"\'\\\r\n ", "arg"); Map<String, String> queryToReturnedMap = new HashMap<>(); for (String query : queryToExpectedMap.keySet()) { queryToReturnedMap.put(query, apiUtil.cleanArgument(query)); } int failureCount = 0; StringBuilder failureReport = new StringBuilder(); for (String query : queryToExpectedMap.keySet()) { String expectedString = queryToExpectedMap.get(query); String returnedString = queryToReturnedMap.get(query); failureCount = failureCount + failuresInReturnedStringComparison(query, expectedString, returnedString, failureReport); } if (failureCount > 0) { fail(Integer.toString(failureCount) + " failed test conditions. Details follow... " + failureReport.toString()); } return; }