SqlTranslator implements ISqlTranslator { @Override public String translate(String original) { String query = original; if (sources!=null) { for (String label:sources.keySet()) { Matcher matcher = sources.get(label).matcher(query); if (matcher.find()) { if (log.isTraceEnabled()) log.trace(String.format("Found a match for label [%s] pattern [%s]",label, sources.get(label))); String replacement = targets.get(label); if (StringUtils.isNotEmpty(replacement)) { query = matcher.replaceAll(replacement); } else { query = matcher.replaceAll(""); } } } } if (StringUtils.isEmpty(query)) { return null; } return query; } SqlTranslator(String source, String target); @Override boolean canConvert(String from, String to); @Override String translate(String original);  }
@Test public void test() throws Throwable { try { SqlTranslator translator = new SqlTranslator(source, target); String out = translator.translate(query); System.out.println("IN : " + query); System.out.println("OUT: " + out); assertEquals(query, expected, out); } catch (Throwable t) { if (checkExceptionClass(t, expected)) { Assert.assertTrue(true); } else { throw t; } } }