← Back to Home

Sprint Challenge

Challenge Overview

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:

Challenge Objectives

By completing this challenge, you'll demonstrate your ability to:

  1. Isolate units of code by mocking their dependencies
  2. Verify that code interacts with dependencies as expected
  3. Test exception handling for both expected and unexpected error conditions
  4. Refactor code to improve testability
  5. Apply proper logging techniques to facilitate debugging
  6. Work with AWS Lambda functions and understand their test requirements

You'll be assessed on:

Example Approach

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.

Setup Instructions

  1. Fork and clone the Sprint Challenge Starter Repository
  2. Follow the README instructions to set up your project
  3. Complete all project tasks
  4. Submit your work through the Portal

Resources