-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handle specific exceptions while email verification (#191)
- Loading branch information
1 parent
c77fde2
commit 1f76302
Showing
7 changed files
with
145 additions
and
21 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/amu/zhcet/auth/verification/DuplicateEmailException.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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
package amu.zhcet.auth.verification; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = false) | ||
public class DuplicateEmailException extends RuntimeException { | ||
|
||
private String email; | ||
|
||
public DuplicateEmailException(String email) { | ||
super("'" + email + "' is already registered by another user"); | ||
this.email = email; | ||
} | ||
|
||
} |
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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/amu/zhcet/auth/verification/RecentVerificationException.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,29 @@ | ||
package amu.zhcet.auth.verification; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import org.springframework.lang.Nullable; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = false) | ||
public class RecentVerificationException extends RuntimeException { | ||
|
||
public static final String MESSAGE = "Verification link was recently sent. Please wait for some time"; | ||
|
||
@Nullable | ||
private LocalDateTime sentTime; | ||
|
||
public RecentVerificationException() { | ||
super(MESSAGE); | ||
} | ||
|
||
public RecentVerificationException(LocalDateTime sentTime) { | ||
super(String.format( | ||
"Verification link was recently sent at %s. Please wait for some time", | ||
sentTime.toString())); | ||
this.sentTime = sentTime; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/amu/zhcet/auth/verification/TokenVerificationException.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,9 @@ | ||
package amu.zhcet.auth.verification; | ||
|
||
public class TokenVerificationException extends IllegalStateException { | ||
|
||
public TokenVerificationException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/amu/zhcet/auth/verification/DuplicateEmailExceptionTest.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,29 @@ | ||
package amu.zhcet.auth.verification; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class DuplicateEmailExceptionTest { | ||
|
||
private DuplicateEmailException duplicateEmailException; | ||
|
||
@Before | ||
public void setUp() { | ||
duplicateEmailException = new DuplicateEmailException("[email protected]"); | ||
} | ||
|
||
@Test | ||
public void testConstructorMessage() { | ||
assertEquals( | ||
"'[email protected]' is already registered by another user", | ||
duplicateEmailException.getMessage()); | ||
} | ||
|
||
@Test | ||
public void testGettingEmail() { | ||
assertEquals("[email protected]", duplicateEmailException.getEmail()); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/amu/zhcet/auth/verification/RecentVerificationExceptionTest.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,35 @@ | ||
package amu.zhcet.auth.verification; | ||
|
||
import org.junit.Test; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class RecentVerificationExceptionTest { | ||
|
||
private LocalDateTime localDateTime = LocalDateTime.of(2018, 9, 1, 12, 23); | ||
|
||
@Test | ||
public void testNoConstructorMessage() { | ||
RecentVerificationException recentVerificationException = new RecentVerificationException(); | ||
assertEquals( | ||
"Verification link was recently sent. Please wait for some time", | ||
recentVerificationException.getMessage()); | ||
} | ||
|
||
@Test | ||
public void testConstructorMessage() { | ||
RecentVerificationException recentVerificationException = new RecentVerificationException(localDateTime); | ||
assertEquals( | ||
"Verification link was recently sent at 2018-09-01T12:23. Please wait for some time", | ||
recentVerificationException.getMessage()); | ||
} | ||
|
||
@Test | ||
public void testGettingSentTime() { | ||
RecentVerificationException recentVerificationException = new RecentVerificationException(localDateTime); | ||
assertEquals(localDateTime, recentVerificationException.getSentTime()); | ||
} | ||
|
||
} |