#2768 - ENH: Add eqIfPresent() - a helper expression for fluid style when some EQ are optional

This commit is contained in:
Rob Bygrave
2022-08-01 16:36:09 +12:00
parent f930471beb
commit 7474430a63
6 changed files with 116 additions and 3 deletions
@@ -1,17 +1,20 @@
package org.querytest;
import io.ebean.DB;
import io.ebean.test.LoggedSql;
import org.example.domain.MyInner;
import org.example.domain.query.QMyInner;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
class MyInnerTest {
@Test
void insert_and_find() {
MyInner myInner = new MyInner()
.id(42).one("one").description("foo");
@@ -26,5 +29,25 @@ class MyInnerTest {
.findOne();
assertThat(found2).isNotNull();
LoggedSql.start();
MyInner found3 = new QMyInner()
.one.eqIfPresent("one")
.findOne();
assertThat(found3).isNotNull();
MyInner found4 = new QMyInner()
.one.eqIfPresent(null)
.description.eqIfPresent("foo")
.findOne();
assertThat(found4).isNotNull();
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.id, t0.one, t0.id, t0.one, t0.description from my_inner t0 where t0.one = ?;");
assertThat(sql.get(1)).contains("select t0.id, t0.one, t0.id, t0.one, t0.description from my_inner t0 where t0.description = ?;");
}
}