Add tests that do not use constructors

This commit is contained in:
Travis Burtrum 2018-05-10 16:01:57 -04:00
parent d3c4f89316
commit d80d3dee93
5 changed files with 73 additions and 1 deletions

View File

@ -28,6 +28,17 @@ public interface QmDao extends JdbcMapper {
"FROM person p " +
"JOIN boss b ON p.person_no = b.person_no " +
"WHERE p.person_no = {personNo}";
public static final String personRegularNoConstructor = "SELECT person_no, first_name, last_name, birth_date, first_name AS dummy FROM person WHERE person_no = {personNo}";
public static final String bossRegularAndUnderscoreNoConstructor = "SELECT p.person_no, p.first_name AS firstName, p.last_name, p.birth_date, b.department, p.first_name, p.first_name AS dummy " +
"FROM person p " +
"JOIN boss b ON p.person_no = b.person_no " +
"WHERE p.person_no = {personNo}";
public static final String bossRegularAndUnderscoreReverseNoConstructor = "SELECT p.person_no, p.first_name, p.last_name, p.birth_date, b.department, p.first_name AS firstName, p.first_name AS dummy " +
"FROM person p " +
"JOIN boss b ON p.person_no = b.person_no " +
"WHERE p.person_no = {personNo}";
public static final String bossRegular = "SELECT p.person_no, p.first_name AS firstName, p.last_name, p.birth_date, b.department " +
"FROM person p " +
"JOIN boss b ON p.person_no = b.person_no " +
@ -63,6 +74,12 @@ public interface QmDao extends JdbcMapper {
@JdbcMapper.SQL(bossRegularAndUnderscoreReverse)
FieldBoss getFieldRegularAndUnderscoreReverse(long personNo) throws SQLException;
@JdbcMapper.SQL(bossRegularAndUnderscoreNoConstructor)
FieldBoss getFieldRegularAndUnderscoreNoConstructor(long personNo) throws SQLException;
@JdbcMapper.SQL(bossRegularAndUnderscoreReverseNoConstructor)
FieldBoss getFieldRegularAndUnderscoreReverseNoConstructor(long personNo) throws SQLException;
@JdbcMapper.SQL(bossRegular)
FieldBoss getFieldRegular(long personNo) throws SQLException;
@ -72,6 +89,9 @@ public interface QmDao extends JdbcMapper {
@JdbcMapper.SQL(personRegular)
SetPerson getSetRegularPerson(long personNo) throws SQLException;
@JdbcMapper.SQL(personRegularNoConstructor)
SetPerson getSetRegularPersonNoConstructor(long personNo) throws SQLException;
@JdbcMapper.SQL(bossRegularAndUnderscore)
SetBoss getSetRegularAndUnderscore(long personNo) throws SQLException;

View File

@ -30,6 +30,17 @@ public class QueryMapperQmDao implements QmDao {
"FROM person p " +
"JOIN boss b ON p.person_no = b.person_no " +
"WHERE p.person_no = ?";
public static final String personRegularNoConstructor = "SELECT person_no, first_name, last_name, birth_date, first_name AS dummy FROM person WHERE person_no = ?";
public static final String bossRegularAndUnderscoreNoConstructor = "SELECT p.person_no, p.first_name AS firstName, p.last_name, p.birth_date, b.department, p.first_name, p.first_name AS dummy " +
"FROM person p " +
"JOIN boss b ON p.person_no = b.person_no " +
"WHERE p.person_no = ?";
public static final String bossRegularAndUnderscoreReverseNoConstructor = "SELECT p.person_no, p.first_name, p.last_name, p.birth_date, b.department, p.first_name AS firstName, p.first_name AS dummy " +
"FROM person p " +
"JOIN boss b ON p.person_no = b.person_no " +
"WHERE p.person_no = ?";
public static final String bossRegular = "SELECT p.person_no, p.first_name AS firstName, p.last_name, p.birth_date, b.department " +
"FROM person p " +
"JOIN boss b ON p.person_no = b.person_no " +
@ -85,6 +96,16 @@ public class QueryMapperQmDao implements QmDao {
return qm.toObject(bossRegularAndUnderscoreReverse, FieldBoss.class, personNo);
}
@Override
public FieldBoss getFieldRegularAndUnderscoreNoConstructor(final long personNo) throws SQLException {
return qm.toObject(bossRegularAndUnderscoreNoConstructor, FieldBoss.class, personNo);
}
@Override
public FieldBoss getFieldRegularAndUnderscoreReverseNoConstructor(final long personNo) throws SQLException {
return qm.toObject(bossRegularAndUnderscoreReverseNoConstructor, FieldBoss.class, personNo);
}
@Override
public FieldBoss getFieldRegular(final long personNo) throws SQLException {
return qm.toObject(bossRegular, FieldBoss.class, personNo);
@ -100,6 +121,11 @@ public class QueryMapperQmDao implements QmDao {
return qm.toObject(personRegular, SetPerson.class, personNo);
}
@Override
public SetPerson getSetRegularPersonNoConstructor(final long personNo) throws SQLException {
return qm.toObject(personRegularNoConstructor, SetPerson.class, personNo);
}
@Override
public SetBoss getSetRegularAndUnderscore(final long personNo) throws SQLException {
return qm.toObject(bossRegularAndUnderscore, SetBoss.class, personNo);

View File

@ -33,6 +33,10 @@ public class FieldBoss extends FieldPerson implements Boss {
return first_name;
}
public void setDummy(String dummy) {
// do nothing, this is simply to avoid calling the constructor in some cases
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -33,4 +33,8 @@ public class SetPerson extends FieldPerson {
this.lastName = lastName;
}
public void setDummy(String dummy) {
// do nothing, this is simply to avoid calling the constructor in some cases
}
}

View File

@ -167,10 +167,22 @@ public class QueryMapperTest {
@Test
public void testFieldRegularAndUnderscoreReverse() throws Throwable {
final Person expected = fieldBoss1; // todo: these call constructor, write another test to call setters
final Person expected = fieldBoss1;
Assert.assertEquals(expected, qm.getFieldRegularAndUnderscoreReverse(expected.getPersonNo()));
}
@Test
public void testFieldRegularAndUnderscoreNoConstructor() throws Throwable {
final Person expected = fieldBoss1;
Assert.assertEquals(expected, qm.getFieldRegularAndUnderscoreNoConstructor(expected.getPersonNo()));
}
@Test
public void testFieldRegularAndUnderscoreReverseNoConstructor() throws Throwable {
final Person expected = fieldBoss1;
Assert.assertEquals(expected, qm.getFieldRegularAndUnderscoreReverseNoConstructor(expected.getPersonNo()));
}
@Test
public void testFieldRegular() throws Throwable {
final Person expected = fieldBoss2;
@ -191,6 +203,12 @@ public class QueryMapperTest {
Assert.assertEquals(expected, qm.getSetRegularPerson(expected.getPersonNo()));
}
@Test
public void testSetRegularPersonNoConstructor() throws Throwable {
final Person expected = setPerson1;
Assert.assertEquals(expected, qm.getSetRegularPersonNoConstructor(expected.getPersonNo()));
}
@Test
public void testSetRegularAndUnderscore() throws Throwable {
final Person expected = setBoss1;