### Question:
HqlTranslator { public String translate(String viewQualifiedName, String hql) { List<TableTranslation> translations = mappings.get(viewQualifiedName); if (translations == null) { return hql; } return translate(hql, translations); } @Autowired  HqlTranslator(TableReplications tableReplications); String translate(String viewQualifiedName, String hql);  }### Answer:
@Test public void unescapedStatement() { Map<String, String> replicationMappings = ImmutableMap .<String, String> builder() .put("db1.table_a", "r_db.a_table") .build(); when(tableReplication.getTableMappings()).thenReturn(replicationMappings); HqlTranslator translator = new HqlTranslator(tableReplications); String translatedStatement = translator.translate(VIEW_NAME, UNESCAPED_SELECT_STATEMENT); String expectedTranslatedStatement = new StringBuilder() .append("SELECT a_table.col1, b.col2 \n") .append(" FROM r_db.a_table \n") .append(" JOIN db2.table_b AS B ON B.key = a_table.key \n") .append(" WHERE a_table.cond = 'VAL' \n") .append(" AND a_table.cmp < b.cmp \n") .toString(); assertThat(translatedStatement, is(expectedTranslatedStatement)); }
@Test public void escapedStatment() { Map<String, String> replicationMappings = ImmutableMap .<String, String> builder() .put("db1.table_a", "r_db.a_table") .put("db2.table_b", "r_db.b_table") .build(); when(tableReplication.getTableMappings()).thenReturn(replicationMappings); HqlTranslator translator = new HqlTranslator(tableReplications); String translatedStatement = translator.translate(VIEW_NAME, ESCAPED_SELECT_STATEMENT); String expectedTranslatedStatement = new StringBuilder() .append("SELECT `A`.`col1`, `b_table`.`col2` \n") .append(" FROM `r_db`.`a_table` AS `A` \n") .append(" JOIN `r_db`.`b_table` ON `b_table`.`key` = `A`.`key` \n") .append(" WHERE `A`.`cond` = 'VAL' \n") .append(" AND `A`.`cmp` < `b_table`.`cmp` \n") .toString(); assertThat(translatedStatement, is(expectedTranslatedStatement)); }