如何为DAOImpl类编写Mockito测试

huangapple 未分类评论54阅读模式
英文:

How to write mockito test for DAOImpl class

问题

我有一个负责在数据库中更新用户详细信息的Dao实现类。我对Mockito还不太了解,所以我想知道如何为这个Dao实现类编写Mockito测试。下面是函数实现的详细信息:

public boolean updateUserDetails(UsersModel user) throws IOException {
    Properties properties = SqlProperties.readFromPropertiesFile();
    jdbcTemplate.update(properties.getProperty("updateUserDetails"), new PreparedStatementSetter() {
        
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setString(1, user.getFirstName());
            ps.setString(2, user.getLastName());
            ps.setString(3, user.getContactNumber());
            ps.setString(4, user.getUserName());
            
        }
    });
    
    return true;
}
英文:

I have a Dao Impl class that is responsible for updating the user details in the database. I am new to mockito so i would like to know how to write mockito test for this Dao impl class. The details of the function implementation is given below

public boolean updateUserDetails(UsersModel user) throws IOException {
		Properties properties = SqlProperties.readFromPropertiesFile();
		jdbcTemplate.update(properties.getProperty("updateUserDetails"), new PreparedStatementSetter() {
			
			@Override
			public void setValues(PreparedStatement ps) throws SQLException {
				ps.setString(1, user.getFirstName());
				ps.setString(2, user.getLastName());
				ps.setString(3, user.getContactNumber());
				ps.setString(4, user.getUserName());
				
			}
		});
		
		return true;
		
	}

huangapple
  • 本文由 发表于 2020年3月15日 13:04:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/60689890.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定