Skip to content

Instantly share code, notes, and snippets.

@dileeph
Last active February 27, 2018 12:50
Show Gist options
  • Save dileeph/a3ef2c97d351932ea41c1888e8959c63 to your computer and use it in GitHub Desktop.
Save dileeph/a3ef2c97d351932ea41c1888e8959c63 to your computer and use it in GitHub Desktop.
Query builder test
import java.io.IOException;
import org.junit.Test;
public class QueryBuilderTest {
@Test
public void testQB() {
String sql = "select x from ";
String parameterValue = "john";
Query finalQuery = new QueryBuilder(sql)
.addQuery(" b, c where d = :dname", "dname",
() -> parameterValue.toUpperCase(),
() -> parameterValue != null && !parameterValue.equals("jane"))
.addQuery(" and p = :pname", "pname", "tom")
.build();
System.out.println(finalQuery );
}
@Test(expected=IOException.class)
public void testQB2() throws Exception {
String sql = "select x from ";
String parameterValue = "jane";
Query finalQuery = new QueryBuilder(sql)
.addQuery(" b, c where d = :dname", "dname",
() -> parameterValue.toUpperCase(),
() -> parameterValue != null && !parameterValue.equals("jane"),
() -> new IOException("dddd"))
.addQuery(" and p = :pname", "pname",
() -> "tom").build();
System.out.println(finalQuery );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment