SqlUtil { public static String concatByAndOperation(List<SqlPredicate> predicates) { if (predicates.isEmpty()) return null; int size = predicates.size(); int i = 0; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("("); for (SqlPredicate predicate : predicates) { stringBuilder.append(predicate.getLeftExpression()); stringBuilder.append(" "); stringBuilder.append(predicate.getOperator()); stringBuilder.append(" "); stringBuilder.append("'"); stringBuilder.append(predicate.getRightExpression()); stringBuilder.append("'"); if (i != size - 1) { stringBuilder.append(" ").append(LogicalOperation.AND.name()).append(" "); } i++; } stringBuilder.append(")"); return stringBuilder.toString(); } private  SqlUtil(); static String concat(List<String> strings, String separator); static String getTableName(String opaUnknownPropertyValue); static String concatByAndOperation(List<SqlPredicate> predicates);  }
@Test void shouldConcatenateAndConstraints() { SqlPredicate sqlPredicate1 = new SqlPredicate("pets.owner", "=", "alice"); SqlPredicate sqlPredicate2 = new SqlPredicate("pets.name", "=", "fluffy"); List<SqlPredicate> predicates = List.of(sqlPredicate1, sqlPredicate2); String result = SqlUtil.concatByAndOperation(predicates); assertThat(result, is("(pets.owner = 'alice' AND pets.name = 'fluffy')")); }
@Test void shouldReturnNullIfListIsEmptyAndOPeration(){ String result = SqlUtil.concatByAndOperation(Collections.emptyList()); assertThat(result, is(nullValue())); }