-3

Hi This is my Row Mapper class.

public class UserRowMapper implements RowMapper<UserData> {

    @Override
    public UserData mapRow(ResultSet resultSet, int line) throws SQLException {
        UserData userData = new UserData();  
        try
        {
            userData.setUserID(resultSet.getString("User_ID"));
            userData.setUserName(resultSet.getString("User_Name"));  
            userData.setUserPassword(resultSet.getString("User_Password"));  
            userData.setUserRole(resultSet.getString("User_Role")); 
            userData.setUserStatus(resultSet.getString("User_Status")); 
            userData.setUserLogStatus(resultSet.getString("UserLog_Status")); 
            userData.setUserAccountName(resultSet.getString("User_AccountName")); 
            userData.setUserAccountID(resultSet.getString("User_AccountID")); 
            userData.setUserEmailID(resultSet.getString("User_EmailID")); 
            userData.setUserPasswordStatus(resultSet.getString("User_Password_ExpiryStatus")); 
            userData.setUserIDStatus(resultSet.getString("User_ID_Status")); 
            userData.setAcatTenantID(resultSet.getLong("acatTenant_ID")); 
            userData.setUserRoleCode(resultSet.getLong("User_Role_Code")); 
            userData.setUserSkillSetCode(resultSet.getLong("User_SkillSet_Code")); 
            userData.setUserAccountCode(resultSet.getLong("User_Account_Code")); 

            return userData;
        }
        catch (EmptyResultDataAccessException e)
        {
            return null;
        }
    }

}

and this is my Model class.

public class UserData {

    private String userID;
    private String userPassword;
    private String userRole;
    private String userStatus;
    private String userLogStatus;
    private String userName;
    private String userAccountName;
    private String userAccountID;
    private String userIDStatus;
    private String userPasswordStatus;
    private String userEmailID;  

    private String userAdminID;
    private String deactivationComment;

    private String reqPageID;
    private String userSessionID;    
    private String reqFunctionalityID;  

    private long userAccountCode;
    private long userRoleCode;
    private long userSkillSetCode;
    private long acatTenantID;


    public long getUserAccountCode() {
        return userAccountCode;
    }
    public void setUserAccountCode(long userAccountCode) {
        this.userAccountCode = userAccountCode;
    }

    public long getUserRoleCode() {
        return userRoleCode;
    }
    public void setUserRoleCode(long userRoleCode) {
        this.userRoleCode = userRoleCode;
    }

    public long getUserSkillSetCode() {
        return userSkillSetCode;
    }
    public void setUserSkillSetCode(long userSkillSetCode) {
        this.userSkillSetCode = userSkillSetCode;
    }

    public long getAcatTenantID() {
        return acatTenantID;
    }
    public void setAcatTenantID(long acatTenantID) {
        this.acatTenantID = acatTenantID;
    }

    public String getReqFunctionalityID() {
        return reqFunctionalityID;
    }
    public void setReqFunctionalityID(String reqFunctionalityID) {
        this.reqFunctionalityID = reqFunctionalityID;
    }

    public String getReqPageID() {
        return reqPageID;
    }
    public void setReqPageID(String reqPageID) {
        this.reqPageID = reqPageID;
    }

    public String getUserSessionID() {
        return userSessionID;
    }
    public void setUserSessionID(String userSessionID) {
        this.userSessionID = userSessionID;
    }

    public String getUserAdminID() {
        return userAdminID;
    }
    public void setUserAdminID(String userAdminID) {
        this.userAdminID = userAdminID;
    }

    public String getDeactivationComment() {
        return deactivationComment;
    }
    public void setDeactivationComment(String deactivationComment) {
        this.deactivationComment = deactivationComment;
    }
    public String getUserIDStatus() {
        return userIDStatus;
    }
    public void setUserIDStatus(String userIDStatus) {
        this.userIDStatus = userIDStatus;
    }
    public String getUserPasswordStatus() {
        return userPasswordStatus;
    }
    public void setUserPasswordStatus(String userPasswordStatus) {
        this.userPasswordStatus = userPasswordStatus;
    }

    public String getUserEmailID() {
        return userEmailID;
    }
    public void setUserEmailID(String userEmailID) {
        this.userEmailID = userEmailID;
    }
    public String getUserAccountID() {
        return userAccountID;
    }
    public void setUserAccountID(String userAccountID) {
        this.userAccountID = userAccountID;
    }
    public String getUserAccountName() {
        return userAccountName;
    }
    public void setUserAccountName(String userAccountName) {
        this.userAccountName = userAccountName;
    }
    public String getUserID() {
        return userID;
    }
    public void setUserID(String userID) {
        this.userID = userID;
    }
    public String getUserPassword() {
        return userPassword;
    }
    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }
    public String getUserRole() {
        return userRole;
    }
    public void setUserRole(String userRole) {
        this.userRole = userRole;
    }
    public String getUserStatus() {
        return userStatus;
    }
    public void setUserStatus(String userStatus) {
        this.userStatus = userStatus;
    }
    public String getUserLogStatus() {
        return userLogStatus;
    }
    public void setUserLogStatus(String userLogStatus) {
        this.userLogStatus = userLogStatus;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }

}

The above classes are my Row Mapper and Model class.i do not know how to write junit test class for Row Mapper class .please any one guide me how to write junit test for these classes.

Hi here is my Junit test code for above classes.

public class UserRowMapperTest {
   UserRowMapper userRowMapper=null;

    @Before
    public void runBeforeEachTest(){
        userRowMapper= new UserRowMapper();

    }
    @After
    public void runAfterEachTest(){
        userRowMapper=null;
    }
    @Test
    public void testMapRow(){
        userRowMapper.mapRow(resultSet, line);
    }    
}
Rufi
  • 2,529
  • 1
  • 20
  • 41
Deepu
  • 9
  • 1
  • 1
  • 2

1 Answers1

3

From my point of view there is nothing to test here.

You should create unit tests only for the methods which have some business logic. I don't see the reason to test the methods which are using just getters and setters because in general they don't do anything.

However, if you want just to practice this is the advice what you could do for the unit test. First of all check some questions on how to write the unit tests because it feels like you don't understand what you need/want to achieve.

In general this is the sketch of what you want:

@Test
public void testMapRow(){
    // SETUP SUT
    UserRowMapper userRowMapper = new UserRowMapper()    
    // fill (prepare) in the Object that you want to pass to a method.
    ResultSet resultSet = createResultSet();

    // EXERCISE
    UserData resultData = userRowMapper.mapRow(resultSet, line);

    // VERIFY
    Assert.assertEquals(expectedValue, resultData.getSomeValue())
}

p.s. By the way, there is no point in line parameter in this method because you don't use it.

And about the NullPointerException, please, have a look to quite popular question about it.

Panda
  • 6,955
  • 6
  • 40
  • 55
Rufi
  • 2,529
  • 1
  • 20
  • 41