Skip to content

Commit e26ca61

Browse files
committed
A few corrections in test
- Removed a wrong import. - Column size should be large enough to contain the test data. - Renamed role_name/roleName to name This is not an issue, but it unnecessarily makes the test harder to understand.
1 parent 1385892 commit e26ca61

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_columnprefix/CreateDB.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
-- ----------------------------
2020
CREATE TABLE role (
2121
id int,
22-
role_name varchar(10)
22+
name varchar(30)
2323
);
2424

2525
-- ----------------------------
2626
-- Records of role
2727
-- ----------------------------
28-
INSERT INTO role (id,role_name)
28+
INSERT INTO role (id,name)
2929
VALUES ('1', 'teacher');
30-
INSERT INTO role (id,role_name)
30+
INSERT INTO role (id,name)
3131
VALUES ('2', 'student');
32-
INSERT INTO role (id,role_name)
32+
INSERT INTO role (id,name)
3333
VALUES ('3', 'Headmaster');
34-
INSERT INTO role (id,role_name)
34+
INSERT INTO role (id,name)
3535
VALUES ('4', 'Learning-commissary');
3636

3737
CREATE TABLE user (

src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_columnprefix/OneManyColumnPrefixTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void shouldUseColumnPrefixWithOne() {
7575
assertNotNull(users);
7676
assertEquals(2, users.size());
7777
assertNotNull(users.get(0).getRole());
78-
assertEquals("teacher", users.get(0).getRole().getRoleName());
78+
assertEquals("teacher", users.get(0).getRole().getName());
7979
}
8080
}
8181
}

src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_columnprefix/Role.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public class Role {
2222
public String toString() {
2323
return "Role{" +
2424
"id=" + id +
25-
", roleName='" + roleName + '\'' +
25+
", roleName='" + name + '\'' +
2626
'}';
2727
}
2828

29-
private String roleName;
29+
private String name;
3030

3131
public Integer getId() {
3232
return id;
@@ -36,11 +36,11 @@ public void setId(Integer id) {
3636
this.id = id;
3737
}
3838

39-
public String getRoleName() {
40-
return roleName;
39+
public String getName() {
40+
return name;
4141
}
4242

43-
public void setRoleName(String roleName) {
44-
this.roleName = roleName;
43+
public void setName(String name) {
44+
this.name = name;
4545
}
4646
}

src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_columnprefix/RoleDao.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.apache.ibatis.annotations.Result;
1919
import org.apache.ibatis.annotations.Results;
2020
import org.apache.ibatis.annotations.Select;
21-
import org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.Role;
2221

2322
import java.util.List;
2423

@@ -29,7 +28,7 @@ public interface RoleDao {
2928
@Select("select * from role")
3029
@Results(id = "roleMap1", value = {
3130
@Result(id = true, column = "id", property = "id"),
32-
@Result(column = "name", property = "roleName")
31+
@Result(column = "name", property = "name")
3332
})
3433
public List<Role> findAll();
3534
}

src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_columnprefix/RoleDao.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
<resultMap id="roleMap2"
2525
type="org.apache.ibatis.submitted.annotion_many_one_add_columnprefix.Role">
2626
<id column="id" property="id" />
27-
<result column="name" property="roleName" />
27+
<result column="name" property="name" />
2828
</resultMap>
2929
</mapper>

src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_columnprefix/UserDao.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@
1515
*/
1616
package org.apache.ibatis.submitted.annotion_many_one_add_columnprefix;
1717

18-
import org.apache.ibatis.annotations.*;
19-
2018
import java.util.List;
2119

20+
import org.apache.ibatis.annotations.Many;
21+
import org.apache.ibatis.annotations.One;
22+
import org.apache.ibatis.annotations.Result;
23+
import org.apache.ibatis.annotations.Results;
24+
import org.apache.ibatis.annotations.Select;
25+
2226
/**
2327
* @author lvyang
2428
*/
2529
public interface UserDao {
2630
@Select({ "select",
27-
" u.id, u.username, r.id role_id, r.role_name",
31+
" u.id, u.username, r.id role_id, r.name role_name",
2832
" from user u",
2933
" left join user_role ur on u.id = ur.user_id",
3034
" left join role r on ur.role_id = r.id" })
@@ -36,7 +40,7 @@ public interface UserDao {
3640
List<User> findAll();
3741

3842
@Select({ "select",
39-
" u.id, u.username, r.id role_id, r.role_name",
43+
" u.id, u.username, r.id role_id, r.name role_name",
4044
" from user u",
4145
" left join user_role ur on u.id = ur.user_id",
4246
" left join role r on ur.role_id = r.id" })
@@ -48,7 +52,7 @@ public interface UserDao {
4852
List<User> findAll2();
4953

5054
@Select({ "select",
51-
" u.id, u.username, r.id role_id, r.role_name",
55+
" u.id, u.username, r.id role_id, r.name role_name",
5256
" from user u",
5357
" left join user_role ur on u.id = ur.user_id",
5458
" left join role r on ur.role_id = r.id where u.id in (2, 3)" })

0 commit comments

Comments
 (0)