### Question:
QuerySqlTranslator { protected static SqlParts selectStatementForAndClause(List<Object> clause, String indexName) { Misc.checkArgument(!(clause == null || clause.isEmpty()), "clause cannot be null or empty"); Misc.checkNotNullOrEmpty(indexName, "indexName"); SqlParts where = whereSqlForAndClause(clause, indexName); Misc.checkNotNull(where, "where"); String tableName = QueryImpl.tableNameForIndex(indexName); String sql = String.format(Locale.ENGLISH, "SELECT _id FROM \"%s\" WHERE %s", tableName, where.sqlWithPlaceHolders); return SqlParts.partsForSql(sql, where.placeHolderValues); }  static QueryNode translateQuery(Map<String, Object> query,
                                           List<Index> indexes,
                                           Boolean[] indexesCoverQuery);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void nullSelectClauseWhenQueryEmpty() throws QueryException { QuerySqlTranslator.selectStatementForAndClause(new ArrayList<Object>(), "named"); }
@Test(expected = IllegalArgumentException.class) public void nullSelectClauseWhenQueryNull() throws QueryException { QuerySqlTranslator.selectStatementForAndClause(null, "named"); }
@Test(expected = IllegalArgumentException.class) public void nullSelectClauseWhenIndexEmpty() throws QueryException { Map<String, Object> eq = new HashMap<String, Object>(); eq.put("$eq", "mike"); Map<String, Object> name = new HashMap<String, Object>(); name.put("name", eq); List<Object> clause = Arrays.<Object>asList(name); QuerySqlTranslator.selectStatementForAndClause(clause, ""); }
@Test(expected = IllegalArgumentException.class) public void nullSelectClauseWhenIndexNull() throws QueryException { Map<String, Object> eq = new HashMap<String, Object>(); eq.put("$eq", "mike"); Map<String, Object> name = new HashMap<String, Object>(); name.put("name", eq); List<Object> clause = Arrays.<Object>asList(name); QuerySqlTranslator.selectStatementForAndClause(clause, null); }
@Test public void validSelectClauseForSingleTermEQ() throws QueryException { Map<String, Object> eq = new HashMap<String, Object>(); eq.put("$eq", "mike"); Map<String, Object> name = new HashMap<String, Object>(); name.put("name", eq); List<Object> clause = Arrays.<Object>asList(name); SqlParts sql = QuerySqlTranslator.selectStatementForAndClause(clause, "anIndex"); String expected = "SELECT _id FROM \"_t_cloudant_sync_query_index_anIndex\" WHERE \"name\" = ?"; assertThat(sql.sqlWithPlaceHolders, is(expected)); assertThat(sql.placeHolderValues, is(arrayContaining("mike"))); }
@Test public void validSelectClauseForMultiTermEQ() throws QueryException { Map<String, Object> nameEq = new HashMap<String, Object>(); nameEq.put("$eq", "mike"); Map<String, Object> name = new HashMap<String, Object>(); name.put("name", nameEq); Map<String, Object> ageEq = new HashMap<String, Object>(); ageEq.put("$eq", 12); Map<String, Object> age = new HashMap<String, Object>(); age.put("age", ageEq); Map<String, Object> petEq = new HashMap<String, Object>(); petEq.put("$eq", "cat"); Map<String, Object> pet = new HashMap<String, Object>(); pet.put("pet", petEq); List<Object> clause = Arrays.<Object>asList(name, age, pet); SqlParts sql = QuerySqlTranslator.selectStatementForAndClause(clause, "anIndex"); String select = "SELECT _id FROM \"_t_cloudant_sync_query_index_anIndex\""; String where = " WHERE \"name\" = ? AND \"age\" = ? AND \"pet\" = ?"; String expected = String.format("%s%s", select, where); assertThat(sql.sqlWithPlaceHolders, is(expected)); assertThat(sql.placeHolderValues, is(arrayContainingInAnyOrder("mike", "12", "cat"))); }