import
static
org.junit.jupiter.api.Assertions.assertAll;
import
static
org.junit.jupiter.api.Assertions.assertArrayEquals;
import
static
org.junit.jupiter.api.Assertions.assertEquals;
import
static
org.junit.jupiter.api.Assertions.assertFalse;
import
static
org.junit.jupiter.api.Assertions.assertNotEquals;
import
static
org.junit.jupiter.api.Assertions.assertTrue;
import
static
org.junit.jupiter.api.Assumptions.assumeFalse;
import
static
org.junit.jupiter.api.Assumptions.assumingThat;
import
org.junit.jupiter.api.Assertions;
import
org.junit.jupiter.api.Test;
public
class
TestUtilityService {
@Test
public
void
testForValidPhoneNumbersWithoutCoutryCode() {
UtilityServices phoneNumberService =
new
UtilityServices();
assertEquals(
true
, phoneNumberService.checkValidPhoneWithoutCountryCode(
"1234567890"
));
assertNotEquals(
true
, phoneNumberService.checkValidPhoneWithoutCountryCode(
"13579"
));
assertEquals(
true
, phoneNumberService.checkValidPhoneWithoutCountryCode(
"1122334455"
));
assertTrue(phoneNumberService.checkValidPhoneWithoutCountryCode(
"2244668800"
));
assertFalse(phoneNumberService.checkValidPhoneWithoutCountryCode(
"13ab@A"
),
"Invalid PhoneNumber"
);
String validationName =
"phoneNumberValidation"
;
assertAll(
"phoneNumberValidation"
, () -> assertTrue(phoneNumberService.checkValidPhoneWithoutCountryCode(
"1357924680"
)),
() -> assertTrue(phoneNumberService.checkValidPhoneWithoutCountryCode(
"1234567890"
)));
assumingThat(
"phoneNumberValidation"
.equals(validationName), () -> {
System.out.println(
"Checking for phone number validation!!!"
);
assertEquals(
true
, phoneNumberService.checkValidPhoneWithoutCountryCode(
"9988776612"
));
});
assumeFalse(
"loginValidation"
.equals(validationName));
assertTrue(phoneNumberService.checkValidPhoneWithoutCountryCode(
"9977661244"
));
assertArrayEquals(
new
long
[]{9940123456L,9940123457L,9940123458L},
new
long
[]{9940123456L,9940123457L,9940123458L});
Assertions.assertThrows(IllegalArgumentException.
class
, () -> {
Integer.parseInt(
"one two 3 4 5 6 7 8 nine 0"
);
});
}
@Test
public
void
testForValidPhoneNumbersWithCoutryCode() {
UtilityServices phoneNumberService =
new
UtilityServices();
assertEquals(
true
, phoneNumberService.checkValidPhoneWithCountryCode(
"+91 1234567890"
));
assertNotEquals(
true
, phoneNumberService.checkValidPhoneWithoutCountryCode(
"13579"
));
assertEquals(
true
, phoneNumberService.checkValidPhoneWithCountryCode(
"+1 1122334455"
));
assertTrue(phoneNumberService.checkValidPhoneWithCountryCode(
"+61 2244668800"
));
assertFalse(phoneNumberService.checkValidPhoneWithCountryCode(
"+61 131211"
),
"Invalid PhoneNumber"
);
assertAll(
"phoneNumberValidation"
, () -> assertTrue(phoneNumberService.checkValidPhoneWithCountryCode(
"+64 1357924680"
)),
() -> assertTrue(phoneNumberService.checkValidPhoneWithCountryCode(
"+57 1234567890"
)));
}
}