Skip to content

Commit 4783e62

Browse files
committed
Add failing test for automatic detection of association javaType (#1381)
1 parent 7c3bac6 commit 4783e62

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/test/java/org/apache/ibatis/submitted/associationtest/AssociationTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,20 @@ public void shouldGetAllCarsNonUnique() {
7979
Assert.assertEquals(1, cars.size());
8080
}
8181
}
82+
83+
@Test
84+
public void shouldGetAllCarsAndDetectAssociationType() {
85+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
86+
Mapper mapper = sqlSession.getMapper(Mapper.class);
87+
List<Car> cars = mapper.getCarsAndDetectAssociationType();
88+
Assert.assertEquals(4, cars.size());
89+
Assert.assertEquals("VW", cars.get(0).getType());
90+
Assert.assertNotNull(cars.get(0).getEngine());
91+
Assert.assertNull(cars.get(0).getBrakes());
92+
Assert.assertEquals("Opel", cars.get(1).getType());
93+
Assert.assertNull(cars.get(1).getEngine());
94+
Assert.assertNotNull(cars.get(1).getBrakes());
95+
}
96+
}
8297

8398
}

src/test/java/org/apache/ibatis/submitted/associationtest/Mapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ public interface Mapper {
2121

2222
List<Car> getCars();
2323
List<Car> getCars2();
24-
24+
List<Car> getCarsAndDetectAssociationType();
2525
}

src/test/java/org/apache/ibatis/submitted/associationtest/Mapper.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,20 @@
4444
select 1 as carid, cartype, enginetype, enginecylinders, brakestype from cars where carid in (1,2)
4545
</select>
4646

47+
<resultMap type="org.apache.ibatis.submitted.associationtest.Car" id="carResultTypeDetect">
48+
<id column="carid" property="id"/>
49+
<result column="cartype" property="type"/>
50+
<association property="engine">
51+
<result column="enginetype" property="type"/>
52+
<result column="enginecylinders" property="cylinders"/>
53+
</association>
54+
<association property="brakes">
55+
<result column="brakesType" property="type"/>
56+
</association>
57+
</resultMap>
58+
59+
<select id="getCarsAndDetectAssociationType" resultMap="carResultTypeDetect">
60+
select * from cars
61+
</select>
62+
4763
</mapper>

0 commit comments

Comments
 (0)