In this sprint challenge, you'll demonstrate your mastery of advanced testing techniques by implementing a solution that requires mocking, handling static methods, and working with AWS Lambda functions.
You'll need to apply concepts from all four modules to complete the challenge successfully:
By completing this challenge, you'll demonstrate your ability to:
You'll be assessed on:
The challenge will require you to work with code similar to:
// A class with dependencies that needs testing
public class OrderProcessor {
private final PaymentService paymentService;
private final OrderRepository orderRepository;
private final NotificationService notificationService;
// Constructor with dependencies injected (testable approach)
public OrderProcessor(PaymentService paymentService,
OrderRepository orderRepository,
NotificationService notificationService) {
this.paymentService = paymentService;
this.orderRepository = orderRepository;
this.notificationService = notificationService;
}
public OrderResult processOrder(Order order) throws PaymentException {
// Validate the order
if (order == null || order.getItems().isEmpty()) {
throw new IllegalArgumentException("Order cannot be empty");
}
// Process payment
PaymentResult payment = paymentService.processPayment(order.getPaymentDetails());
if (payment.isSuccessful()) {
// Save the order
Order savedOrder = orderRepository.save(order);
// Send notification
notificationService.sendOrderConfirmation(savedOrder);
return new OrderResult(savedOrder.getId(), "Order processed successfully");
} else {
throw new PaymentException("Payment failed: " + payment.getErrorMessage());
}
}
}
You'll need to write tests that verify all paths through this code, using mocks for the dependencies.