Advertisement
Guest User

Untitled

a guest
Nov 5th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. @Entity
  2. public class User extends Model {
  3.  
  4. @Id
  5. @Constraints.Email
  6. public String email;
  7.  
  8. @Constraints.MinLength(3)
  9. @Constraints.MaxLength(255)
  10. public String firstName;
  11.  
  12. @Constraints.MinLength(3)
  13. @Constraints.MaxLength(255)
  14. public String lastName;
  15.  
  16. @Constraints.MinLength(3)
  17. @Constraints.MaxLength(255)
  18. public String username;
  19.  
  20. @Constraints.MinLength(16)
  21. @Constraints.MaxLength(255)
  22. public String password;
  23.  
  24. public static Finder<String, User> finder = new Finder<>(User.class);
  25.  
  26. public static User create(User user){
  27. user.password = BCrypt.hashpw(user.password, BCrypt.gensalt(12));
  28. user.save();
  29. return user;
  30. }
  31. ...
  32. }
  33.  
  34. @Test
  35. public void createEmptyUser(){
  36. User user = new User();
  37. user.email="";
  38. user.save();
  39.  
  40. assertTrue(user.email.isEmpty());
  41. assertNotNull(User.finder.byId(user.email));
  42. assertEquals(true, User.findByEmail(user.email).isPresent());
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement