0% found this document useful (0 votes)
5 views2 pages

Java Email Validation Class and Test

The document provides a Java class named EmailValidator with a method isValid that checks the validity of email addresses using a regex pattern. It also includes a JUnit test class EmailValidatorTest that tests various email formats to ensure the isValid method functions correctly. All tests in the JUnit class pass successfully.

Uploaded by

Dillibabu G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Email Validation Class and Test

The document provides a Java class named EmailValidator with a method isValid that checks the validity of email addresses using a regex pattern. It also includes a JUnit test class EmailValidatorTest that tests various email formats to ensure the isValid method functions correctly. All tests in the JUnit class pass successfully.

Uploaded by

Dillibabu G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

4.

Write a Java class EmailValidator with a method isValid that


checks whether a given email address is valid. Write a Junit test for
this method.

import [Link];

public class EmailValidator {

private static final String EMAIL_PATTERN =

"^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$";

public static boolean isValid(String email) {

return [Link](EMAIL_PATTERN, email);

import static [Link].*;

import [Link];

public class EmailValidatorTest {

@Test

public void testIsValid() {

assertTrue([Link]("test@[Link]"));

assertFalse([Link]("invalid-email"));

assertFalse([Link]("test@.com"));

assertFalse([Link]("test@com"));

assertTrue([Link]("[Link]+tag@[Link]"));
}

𝐎𝐮𝐭𝐩𝐮𝐭 :

C:\DILLIBABU>javac [Link]

C:\DILLIBABU>java EmailValidator

All tests passed.

C:\DILLIBABU>

You might also like