generated from mate-academy/jv-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
28 additions
and
6 deletions.
There are no files selected for viewing
3 changes: 0 additions & 3 deletions
3
src/main/java/core/basesyntax/PasswordValidationException.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package core.basesyntax; | ||
|
||
import core.basesyntax.exceptions.PasswordValidationException; | ||
|
||
public class PasswordValidator { | ||
public void validate(String password, String repeatPassword) { | ||
//write your code here | ||
public void validate(String password, String repeatPassword) | ||
throws PasswordValidationException { | ||
if (password == null | ||
|| password.length() < 10 | ||
|| !password.equals(repeatPassword)) { | ||
throw new PasswordValidationException("Wrong passwords"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
package core.basesyntax; | ||
|
||
import core.basesyntax.exceptions.PasswordValidationException; | ||
|
||
public class UserService { | ||
private final PasswordValidator passwordValidator = new PasswordValidator(); | ||
|
||
public void registerUser(User user) { | ||
//write your code here | ||
try { | ||
passwordValidator.validate(user.getPassword(), user.getRepeatPassword()); | ||
saveUser(user); | ||
} catch (PasswordValidationException e) { | ||
System.out.println("Your passwords are incorrect. Try again."); | ||
} | ||
} | ||
|
||
public void saveUser(User user) { | ||
System.out.println("User " + user.toString() + " was saved to database!!!"); | ||
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/core/basesyntax/exceptions/PasswordValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package core.basesyntax.exceptions; | ||
|
||
public class PasswordValidationException extends Exception { | ||
public PasswordValidationException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters