54 lines
1.6 KiB
Java
54 lines
1.6 KiB
Java
package com.drinkool.utils;
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
public class PhoneValidatorTest {
|
|
|
|
@Test
|
|
public void testValidVietnamesePhoneNumbers() {
|
|
// Số điện thoại VN hợp lệ (có mã vùng hoặc số 0 ở đầu đều được)
|
|
Assertions.assertTrue(
|
|
PhoneValidator.isValidInternationalPhone("0987654321")
|
|
);
|
|
Assertions.assertTrue(
|
|
PhoneValidator.isValidInternationalPhone("+84987654321")
|
|
);
|
|
Assertions.assertTrue(
|
|
PhoneValidator.isValidInternationalPhone("84987654321")
|
|
);
|
|
}
|
|
|
|
@Test
|
|
public void testValidInternationalPhoneNumbers() {
|
|
// Số điện thoại quốc tế hợp lệ (Ví dụ: Mỹ +1)
|
|
Assertions.assertTrue(
|
|
PhoneValidator.isValidInternationalPhone("+14155552671")
|
|
);
|
|
}
|
|
|
|
@Test
|
|
public void testInvalidPhoneNumbers() {
|
|
// Chuỗi không phải số điện thoại
|
|
Assertions.assertFalse(
|
|
PhoneValidator.isValidInternationalPhone("not-a-phone-number")
|
|
);
|
|
|
|
// Số điện thoại quá ngắn hoặc sai định dạng
|
|
Assertions.assertFalse(PhoneValidator.isValidInternationalPhone("123"));
|
|
Assertions.assertFalse(
|
|
PhoneValidator.isValidInternationalPhone("099999999999999")
|
|
);
|
|
|
|
// Chuỗi rỗng
|
|
Assertions.assertFalse(PhoneValidator.isValidInternationalPhone(""));
|
|
}
|
|
|
|
@Test
|
|
public void testNullPhoneNumber() {
|
|
// Cố tình truyền null để xem hàm xử lý thế nào
|
|
// Lưu ý: Đọc thêm phần "Mẹo nhỏ" bên dưới để pass được test này
|
|
Assertions.assertFalse(PhoneValidator.isValidInternationalPhone(null));
|
|
}
|
|
}
|