import
org.junit.jupiter.api.*;
import
org.junit.jupiter.params.ParameterizedTest;
import
org.junit.jupiter.params.provider.CsvSource;
import
org.junit.jupiter.params.provider.ValueSource;
import
java.io.IOException;
import
static
org.junit.jupiter.api.Assertions.fail;
public
class
AccountUtilsTest {
AccountUtils systemUnderTest =
new
AccountUtils();
@BeforeAll
static
void
init(){
System.out.println(
"Initilize connection to Database"
);
}
@AfterAll
static
void
destroy(){
System.out.println(
"Deallocate connection to Database"
);
}
@Test
@DisplayName
(
"AccountID Length Validation Success"
)
void
test_getAccountIDLength_Success(){
boolean
expectedOutput =
true
;
boolean
actualOutput = systemUnderTest.getAccountIDLength(
"SBI-104526"
);
Assertions.assertEquals(expectedOutput, actualOutput);
Assertions.assertTrue(actualOutput);
}
@Test
@Disabled
void
test_validateAccountId_Success()
throws
IOException {
Assertions.assertTrue(systemUnderTest.validateAccountId(
"SBI-104526"
));
}
@Test
@DisplayName
(
"AccountID is Invalid "
)
void
test_validateAccountId_Exception(){
Assertions.assertThrows(IOException.
class
, ()->{
systemUnderTest.validateAccountId(
""
);
});
}
@Test
@DisplayName
(
"Account Bank Details Validation"
)
void
test_AccountIDForBankName_Success(){
String[] expectedOutput =
new
String[]{
"SBI"
,
"104526"
};
String[] actualOutput = systemUnderTest.getBankDetails(
"SBI-104526"
);
Assertions.assertArrayEquals(expectedOutput, actualOutput);
}
@Nested
class
checkValidAccountId
{
@ParameterizedTest
@ValueSource
(strings={
"SBI"
,
"SBI-123456789"
,
" "
,
""
})
@DisplayName
(
"Parameterized Test AccountID Length Validation Failiure"
)
void
test_getAccountIDLength_Failiure(String accountId){
Assertions.assertFalse(systemUnderTest.getAccountIDLength(accountId));
}
@ParameterizedTest
(name=
"AccountID {0} formatted to {1}"
)
@CsvSource
(value={
"sbi-123456, SBI-123456"
,
"cbi-123456, CBI-123456"
})
@DisplayName
(
"AccountID Format Validation"
)
void
getFormattedAccID_Success(String inputString, String expectedOutput){
Assertions.assertEquals(expectedOutput, systemUnderTest.getFormattedAccID(inputString));
}
}
}