Skip to content

Commit

Permalink
Will solve tasks from README file
Browse files Browse the repository at this point in the history
  • Loading branch information
DEz-1996 committed Oct 2, 2023
1 parent faec460 commit f8d6904
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.

This file was deleted.

11 changes: 9 additions & 2 deletions src/main/java/core/basesyntax/PasswordValidator.java
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");
}
}
}
12 changes: 11 additions & 1 deletion src/main/java/core/basesyntax/UserService.java
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!!!");

}
}
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);
}
}
1 change: 1 addition & 0 deletions src/test/java/core/basesyntax/UserServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package core.basesyntax;

import core.basesyntax.exceptions.PasswordValidationException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down

0 comments on commit f8d6904

Please sign in to comment.