@Test public void createUser_Returns_Success() { user = new User(0,"test name", "test@email.com", "testPassword"); int condition = uRep.createUser(user); Assert.assertTrue(condition!=-1); }
public int createUser(User user) { int success = 0; int update = 0; try { this.jdbcTemplate.queryForObject("SELECT email FROM user WHERE userName = ?" , new Object[] {user.getUsername()}, String.class); }catch (EmptyResultDataAccessException e) { update = this.jdbcTemplate.update("INSERT INTO user (email, pwd, userName) VALUES(?, ?, ?)", new Object[] {user.getEmail(), user.getPassword(), user.getUsername()}); }finally { if (update == 1) { success = getID(user); }else { success = -1; } } return success; }
UserRepository { public int createUser(User user) { int success = 0; int update = 0; try { this.jdbcTemplate.queryForObject("SELECT email FROM user WHERE userName = ?" , new Object[] {user.getUsername()}, String.class); }catch (EmptyResultDataAccessException e) { update = this.jdbcTemplate.update("INSERT INTO user (email, pwd, userName) VALUES(?, ?, ?)", new Object[] {user.getEmail(), user.getPassword(), user.getUsername()}); }finally { if (update == 1) { success = getID(user); }else { success = -1; } } return success; } }
UserRepository { public int createUser(User user) { int success = 0; int update = 0; try { this.jdbcTemplate.queryForObject("SELECT email FROM user WHERE userName = ?" , new Object[] {user.getUsername()}, String.class); }catch (EmptyResultDataAccessException e) { update = this.jdbcTemplate.update("INSERT INTO user (email, pwd, userName) VALUES(?, ?, ?)", new Object[] {user.getEmail(), user.getPassword(), user.getUsername()}); }finally { if (update == 1) { success = getID(user); }else { success = -1; } } return success; }  }
UserRepository { public int createUser(User user) { int success = 0; int update = 0; try { this.jdbcTemplate.queryForObject("SELECT email FROM user WHERE userName = ?" , new Object[] {user.getUsername()}, String.class); }catch (EmptyResultDataAccessException e) { update = this.jdbcTemplate.update("INSERT INTO user (email, pwd, userName) VALUES(?, ?, ?)", new Object[] {user.getEmail(), user.getPassword(), user.getUsername()}); }finally { if (update == 1) { success = getID(user); }else { success = -1; } } return success; }  List<User> viewAllUsernames(); User getById(int id); String getPasswordTest(); int verifyLogin(User user); int createUser(User user); boolean updateUser(User user, int id); }
UserRepository { public int createUser(User user) { int success = 0; int update = 0; try { this.jdbcTemplate.queryForObject("SELECT email FROM user WHERE userName = ?" , new Object[] {user.getUsername()}, String.class); }catch (EmptyResultDataAccessException e) { update = this.jdbcTemplate.update("INSERT INTO user (email, pwd, userName) VALUES(?, ?, ?)", new Object[] {user.getEmail(), user.getPassword(), user.getUsername()}); }finally { if (update == 1) { success = getID(user); }else { success = -1; } } return success; }  List<User> viewAllUsernames(); User getById(int id); String getPasswordTest(); int verifyLogin(User user); int createUser(User user); boolean updateUser(User user, int id);  }