Skip to content

Commit

Permalink
A few corrections in test
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
harawata committed Feb 14, 2020
1 parent 1385892 commit e26ca61
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
-- ----------------------------
CREATE TABLE role (
id int,
role_name varchar(10)
name varchar(30)
);

-- ----------------------------
-- Records of role
-- ----------------------------
INSERT INTO role (id,role_name)
INSERT INTO role (id,name)
VALUES ('1', 'teacher');
INSERT INTO role (id,role_name)
INSERT INTO role (id,name)
VALUES ('2', 'student');
INSERT INTO role (id,role_name)
INSERT INTO role (id,name)
VALUES ('3', 'Headmaster');
INSERT INTO role (id,role_name)
INSERT INTO role (id,name)
VALUES ('4', 'Learning-commissary');

CREATE TABLE user (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void shouldUseColumnPrefixWithOne() {
assertNotNull(users);
assertEquals(2, users.size());
assertNotNull(users.get(0).getRole());
assertEquals("teacher", users.get(0).getRole().getRoleName());
assertEquals("teacher", users.get(0).getRole().getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class Role {
public String toString() {
return "Role{" +
"id=" + id +
", roleName='" + roleName + '\'' +
", roleName='" + name + '\'' +
'}';
}

private String roleName;
private String name;

public Integer getId() {
return id;
Expand All @@ -36,11 +36,11 @@ public void setId(Integer id) {
this.id = id;
}

public String getRoleName() {
return roleName;
public String getName() {
return name;
}

public void setRoleName(String roleName) {
this.roleName = roleName;
public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.Role;

import java.util.List;

Expand All @@ -29,7 +28,7 @@ public interface RoleDao {
@Select("select * from role")
@Results(id = "roleMap1", value = {
@Result(id = true, column = "id", property = "id"),
@Result(column = "name", property = "roleName")
@Result(column = "name", property = "name")
})
public List<Role> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
<resultMap id="roleMap2"
type="org.apache.ibatis.submitted.annotion_many_one_add_columnprefix.Role">
<id column="id" property="id" />
<result column="name" property="roleName" />
<result column="name" property="name" />
</resultMap>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
*/
package org.apache.ibatis.submitted.annotion_many_one_add_columnprefix;

import org.apache.ibatis.annotations.*;

import java.util.List;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
* @author lvyang
*/
public interface UserDao {
@Select({ "select",
" u.id, u.username, r.id role_id, r.role_name",
" u.id, u.username, r.id role_id, r.name role_name",
" from user u",
" left join user_role ur on u.id = ur.user_id",
" left join role r on ur.role_id = r.id" })
Expand All @@ -36,7 +40,7 @@ public interface UserDao {
List<User> findAll();

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

@Select({ "select",
" u.id, u.username, r.id role_id, r.role_name",
" u.id, u.username, r.id role_id, r.name role_name",
" from user u",
" left join user_role ur on u.id = ur.user_id",
" left join role r on ur.role_id = r.id where u.id in (2, 3)" })
Expand Down

0 comments on commit e26ca61

Please sign in to comment.