mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-29 04:12:14 -05:00
Add tests that do not use constructors
This commit is contained in:
parent
d3c4f89316
commit
d80d3dee93
@ -28,6 +28,17 @@ public interface QmDao extends JdbcMapper {
|
|||||||
"FROM person p " +
|
"FROM person p " +
|
||||||
"JOIN boss b ON p.person_no = b.person_no " +
|
"JOIN boss b ON p.person_no = b.person_no " +
|
||||||
"WHERE p.person_no = {personNo}";
|
"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 " +
|
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 " +
|
"FROM person p " +
|
||||||
"JOIN boss b ON p.person_no = b.person_no " +
|
"JOIN boss b ON p.person_no = b.person_no " +
|
||||||
@ -63,6 +74,12 @@ public interface QmDao extends JdbcMapper {
|
|||||||
@JdbcMapper.SQL(bossRegularAndUnderscoreReverse)
|
@JdbcMapper.SQL(bossRegularAndUnderscoreReverse)
|
||||||
FieldBoss getFieldRegularAndUnderscoreReverse(long personNo) throws SQLException;
|
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)
|
@JdbcMapper.SQL(bossRegular)
|
||||||
FieldBoss getFieldRegular(long personNo) throws SQLException;
|
FieldBoss getFieldRegular(long personNo) throws SQLException;
|
||||||
|
|
||||||
@ -72,6 +89,9 @@ public interface QmDao extends JdbcMapper {
|
|||||||
@JdbcMapper.SQL(personRegular)
|
@JdbcMapper.SQL(personRegular)
|
||||||
SetPerson getSetRegularPerson(long personNo) throws SQLException;
|
SetPerson getSetRegularPerson(long personNo) throws SQLException;
|
||||||
|
|
||||||
|
@JdbcMapper.SQL(personRegularNoConstructor)
|
||||||
|
SetPerson getSetRegularPersonNoConstructor(long personNo) throws SQLException;
|
||||||
|
|
||||||
@JdbcMapper.SQL(bossRegularAndUnderscore)
|
@JdbcMapper.SQL(bossRegularAndUnderscore)
|
||||||
SetBoss getSetRegularAndUnderscore(long personNo) throws SQLException;
|
SetBoss getSetRegularAndUnderscore(long personNo) throws SQLException;
|
||||||
|
|
||||||
|
@ -30,6 +30,17 @@ public class QueryMapperQmDao implements QmDao {
|
|||||||
"FROM person p " +
|
"FROM person p " +
|
||||||
"JOIN boss b ON p.person_no = b.person_no " +
|
"JOIN boss b ON p.person_no = b.person_no " +
|
||||||
"WHERE p.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 " +
|
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 " +
|
"FROM person p " +
|
||||||
"JOIN boss b ON p.person_no = b.person_no " +
|
"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);
|
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
|
@Override
|
||||||
public FieldBoss getFieldRegular(final long personNo) throws SQLException {
|
public FieldBoss getFieldRegular(final long personNo) throws SQLException {
|
||||||
return qm.toObject(bossRegular, FieldBoss.class, personNo);
|
return qm.toObject(bossRegular, FieldBoss.class, personNo);
|
||||||
@ -100,6 +121,11 @@ public class QueryMapperQmDao implements QmDao {
|
|||||||
return qm.toObject(personRegular, SetPerson.class, personNo);
|
return qm.toObject(personRegular, SetPerson.class, personNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SetPerson getSetRegularPersonNoConstructor(final long personNo) throws SQLException {
|
||||||
|
return qm.toObject(personRegularNoConstructor, SetPerson.class, personNo);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SetBoss getSetRegularAndUnderscore(final long personNo) throws SQLException {
|
public SetBoss getSetRegularAndUnderscore(final long personNo) throws SQLException {
|
||||||
return qm.toObject(bossRegularAndUnderscore, SetBoss.class, personNo);
|
return qm.toObject(bossRegularAndUnderscore, SetBoss.class, personNo);
|
||||||
|
@ -33,6 +33,10 @@ public class FieldBoss extends FieldPerson implements Boss {
|
|||||||
return first_name;
|
return first_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDummy(String dummy) {
|
||||||
|
// do nothing, this is simply to avoid calling the constructor in some cases
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -33,4 +33,8 @@ public class SetPerson extends FieldPerson {
|
|||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDummy(String dummy) {
|
||||||
|
// do nothing, this is simply to avoid calling the constructor in some cases
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -167,10 +167,22 @@ public class QueryMapperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFieldRegularAndUnderscoreReverse() throws Throwable {
|
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()));
|
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
|
@Test
|
||||||
public void testFieldRegular() throws Throwable {
|
public void testFieldRegular() throws Throwable {
|
||||||
final Person expected = fieldBoss2;
|
final Person expected = fieldBoss2;
|
||||||
@ -191,6 +203,12 @@ public class QueryMapperTest {
|
|||||||
Assert.assertEquals(expected, qm.getSetRegularPerson(expected.getPersonNo()));
|
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
|
@Test
|
||||||
public void testSetRegularAndUnderscore() throws Throwable {
|
public void testSetRegularAndUnderscore() throws Throwable {
|
||||||
final Person expected = setBoss1;
|
final Person expected = setBoss1;
|
||||||
|
Loading…
Reference in New Issue
Block a user