sonar fix - add test cases for CommanderTest

This commit is contained in:
atayal
2021-11-05 16:59:40 +05:30
parent 094010d6b5
commit 37be2bb2a4

View File

@ -53,7 +53,7 @@ class CommanderTest {
queueTime, queueTaskTime, paymentTime, messageTime, employeeTime);
}
private Commander buildCommanderObject2() {
private Commander buildCommanderObjectUnknownException() {
PaymentService paymentService = new PaymentService
(new PaymentDatabase(), new IllegalStateException());
var shippingService = new ShippingService(new ShippingDatabase());
@ -67,6 +67,20 @@ class CommanderTest {
queueTime, queueTaskTime, paymentTime, messageTime, employeeTime);
}
private Commander buildCommanderObjectNoException() {
PaymentService paymentService = new PaymentService
(new PaymentDatabase());
var shippingService = new ShippingService(new ShippingDatabase());
var messagingService = new MessagingService(new MessagingDatabase());
var employeeHandle = new EmployeeHandle
(new EmployeeDatabase(), new IllegalStateException());
var qdb = new QueueDatabase
(new DatabaseUnavailableException(), new IllegalStateException());
return new Commander(employeeHandle, paymentService, shippingService,
messagingService, qdb, numOfRetries, retryDuration,
queueTime, queueTaskTime, paymentTime, messageTime, employeeTime);
}
private Commander buildCommanderObjectWithDB() {
return buildCommanderObjectWithoutDB(false, false, new IllegalStateException());
}
@ -140,8 +154,16 @@ class CommanderTest {
}
@Test
void testPlaceOrder2() throws Exception {
Commander c = buildCommanderObject2();
void testPlaceOrderNoException() throws Exception {
Commander c = buildCommanderObjectNoException();
var order = new Order(new User("K", "J"), "pen", 1f);
c.placeOrder(order);
assertFalse(StringUtils.isBlank(order.id));
}
@Test
void testPlaceOrderUnknownException() throws Exception {
Commander c = buildCommanderObjectUnknownException();
var order = new Order(new User("K", "J"), "pen", 1f);
c.placeOrder(order);
assertFalse(StringUtils.isBlank(order.id));