### Question:
UsersService extends BaseService { public int getUserIdByName(String name) { int executorId = 0; if (StringUtils.isNotEmpty(name)) { User executor = queryUser(name); if (null != executor) { executorId = executor.getId(); } else { executorId = -1; } } return executorId; }  @Transactional(rollbackFor = Exception.class) Map<String, Object> createUser(User loginUser,
                                          String userName,
                                          String userPassword,
                                          String email,
                                          int tenantId,
                                          String phone,
                                          String queue,
                                          int state); @Transactional(rollbackFor = RuntimeException.class) User createUser(String userName,
                                          String userPassword,
                                          String email,
                                          int tenantId,
                                          String phone,
                                          String queue,
                                          int state); User queryUser(int id); User queryUser(String name); User queryUser(String name, String password); int getUserIdByName(String name); Map<String, Object> queryUserList(User loginUser, String searchVal, Integer pageNo, Integer pageSize); Map<String, Object> updateUser(int userId,
                                          String userName,
                                          String userPassword,
                                          String email,
                                          int tenantId,
                                          String phone,
                                          String queue,
                                          int state); Map<String, Object> deleteUserById(User loginUser, int id); @Transactional(rollbackFor = RuntimeException.class) Map<String, Object> grantProject(User loginUser, int userId, String projectIds); @Transactional(rollbackFor = RuntimeException.class) Map<String, Object> grantResources(User loginUser, int userId, String resourceIds); @Transactional(rollbackFor = RuntimeException.class) Map<String, Object> grantUDFFunction(User loginUser, int userId, String udfIds); @Transactional(rollbackFor = RuntimeException.class) Map<String, Object> grantDataSource(User loginUser, int userId, String datasourceIds); Map<String, Object> getUserInfo(User loginUser); Map<String, Object> queryAllGeneralUsers(User loginUser); Map<String, Object> queryUserList(User loginUser); Result verifyUserName(String userName); Map<String, Object> unauthorizedUser(User loginUser, Integer alertgroupId); Map<String, Object> authorizedUser(User loginUser, Integer alertgroupId); @Transactional(rollbackFor = RuntimeException.class) Map<String, Object> registerUser(String userName, String userPassword, String repeatPassword, String email); Map<String, Object> activateUser(User loginUser, String userName); Map<String, Object> batchActivateUser(User loginUser, List<String> userNames);  }### Answer:
@Test public void testGetUserIdByName() { User user = new User(); user.setId(1); user.setUserType(UserType.ADMIN_USER); user.setUserName("test_user"); int userId = usersService.getUserIdByName(""); Assert.assertEquals(0, userId); when(usersService.queryUser(user.getUserName())).thenReturn(null); int userNotExistId = usersService.getUserIdByName(user.getUserName()); Assert.assertEquals(-1, userNotExistId); when(usersService.queryUser(user.getUserName())).thenReturn(user); int userExistId = usersService.getUserIdByName(user.getUserName()); Assert.assertEquals(user.getId(), userExistId); }