BaseQueryBuilder { public String build() { return getFinalQuery(); } BaseQueryBuilder(final String query, final List<String> conditions); List<String> getConditions(); static BaseQueryBuilder getInstance(final String query); BaseQueryBuilder addOrCondition(final String condition, final Object parameter); BaseQueryBuilder addAndCondition(final String condition, final Object parameter); BaseQueryBuilder addCondition(final String condition); BaseQueryBuilder addAndCondition(final String condition, final List<?> parameter); BaseQueryBuilder addAndConditionForLoop(final Function<Object, String> func, final List<?> values); BaseQueryBuilder addAndCondition(final String condition); BaseQueryBuilder openBracket(); BaseQueryBuilder closeBracket(); BaseQueryBuilder where(); BaseQueryBuilder or(); BaseQueryBuilder and(); BaseQueryBuilder orderBy(final List<OrderBy> orders); String getFinalQuery(); String build();  }
@Test public void testBuild() throws Exception { String query = "SELECT FROM SMTH %s"; String condition = "condition "; Object parameter = new Object(); String condition1 = "condition1 "; Object nullParameter = null; String expected = "SELECT FROM SMTH WHERE condition "; String actual = BaseQueryBuilder.getInstance(query) .where() .addOrCondition(condition, parameter) .addOrCondition(condition1, nullParameter) .build(); assertEquals(expected, actual); }