Assignment

๐Ÿ“˜ Objective

The objective of this assignment is to help the learner gain hands-on experience with:

  • Unit testing
  • Validation
  • Exception handling
  • Logging
  • Debugging
  • Backend reliability practices

The learner will enhance an existing Spring Boot application by implementing testing and production-quality engineering practices.


๐ŸŽฏ Assignment Overview

In this assignment, the learner will improve a Spring Boot REST API application by:

  • Adding unit tests
  • Implementing validation
  • Handling exceptions globally
  • Adding logging
  • Debugging intentionally broken scenarios

The assignment focuses on developing production-grade backend engineering skills.


๐Ÿ— Project Scenario

You are developing a backend application for managing users in a small organization.

The application currently supports:

  • Creating users
  • Fetching users
  • Updating users
  • Deleting users

However, the application lacks:

  • Automated testing
  • Proper validation
  • Centralized exception handling
  • Structured logging

Your task is to improve the application quality.


๐Ÿ“‚ Suggested Project Structure

```text id=โ€xytyf5โ€ src/ โ”œโ”€โ”€ main/ โ”‚ โ”œโ”€โ”€ controller/ โ”‚ โ”œโ”€โ”€ service/ โ”‚ โ”œโ”€โ”€ repository/ โ”‚ โ”œโ”€โ”€ entity/ โ”‚ โ”œโ”€โ”€ dto/ โ”‚ โ””โ”€โ”€ exception/ โ”‚ โ””โ”€โ”€ test/ โ”œโ”€โ”€ controller/ โ”œโ”€โ”€ service/ โ””โ”€โ”€ repository/


---

# ๐Ÿ“‹ Assignment Tasks

# Task 1 - Add Validation

## Objective

Ensure invalid requests are rejected before business processing.

---

## Requirements

Create a DTO class with validation annotations.

Example validations:

| Field | Validation             |
| ----- | ---------------------- |
| name  | Cannot be blank        |
| email | Must be valid          |
| age   | Must be greater than 0 |

---

## Example DTO

```java id="0n0v6e"
public class UserRequest {

    @NotBlank
    private String name;

    @Email
    private String email;

    @Min(1)
    private int age;
}

Deliverables

  • Add validation annotations
  • Use @Valid in controller
  • Ensure invalid requests fail properly

Task 2 - Global Exception Handling

Objective

Handle application exceptions consistently.


Requirements

Create a global exception handler using:

```java id=โ€x5kh6kโ€ @ControllerAdvice


Handle:

* Validation exceptions
* Resource not found exceptions
* Generic exceptions

---

## Expected Behavior

The API should return:

* Proper HTTP status codes
* Meaningful error messages
* Consistent error response structure

---

# Task 3 - Add Logging

## Objective

Improve application observability using logs.

---

## Requirements

Add logging to:

* User creation
* User deletion
* Validation failures
* Exception handling
* Service layer operations

---

## Example

```java id="h8u4kr"
logger.info("Creating user with email: {}", request.getEmail());

Important Notes

Do NOT:

  • Use System.out.println()
  • Log passwords or sensitive information
  • Over-log unnecessary details

Task 4 - Write Unit Tests

Objective

Write automated tests for service methods.


Requirements

Write tests for:

  • Successful user creation
  • Invalid user creation
  • User lookup
  • User deletion
  • Exception scenarios

Suggested Technologies

  • JUnit 5
  • Mockito

Example Test

```java id=โ€2sn8e0โ€ @Test void shouldCreateUserSuccessfully() {

User savedUser = service.create(request);

assertNotNull(savedUser); } ```

Task 5 - Mock Repository Layer

Objective

Use Mockito to isolate service layer testing.


Requirements

Mock:

  • Repository dependencies
  • External service dependencies if present

Example

java id="8t9mq2" when(repository.findById(1L)) .thenReturn(Optional.of(user));


Task 6 - Debugging Exercise

Objective

Develop debugging and troubleshooting skills.


Scenario

The mentor will intentionally introduce:

  • Null pointer issues
  • Incorrect validations
  • Logical bugs
  • Broken test cases

The learner should:

  • Identify the issue
  • Explain root cause
  • Fix the issue
  • Verify correctness

๐Ÿ“Œ Technical Requirements

Mandatory Requirements

The solution must:

โœ… Use Spring Boot โœ… Use JUnit 5 โœ… Use Mockito โœ… Use SLF4J logging โœ… Use Bean Validation โœ… Follow clean coding practices


๐Ÿ“ Code Quality Guidelines

Naming Standards

Use:

  • Meaningful method names
  • Descriptive variable names
  • Clear class names

Method Design

Methods should:

  • Be small
  • Have single responsibility
  • Avoid duplication

Exception Handling

Exceptions should:

  • Be meaningful
  • Provide useful messages
  • Avoid exposing internal details

๐Ÿงช Testing Expectations

Tests should include:

Type Example
Positive Tests Valid request
Negative Tests Invalid input
Boundary Tests Empty strings
Exception Tests Missing data

๐Ÿ“Š Evaluation Criteria

Category Marks
Validation Implementation 20
Exception Handling 20
Logging Practices 15
Unit Testing 30
Debugging Skills 15

๐Ÿง  Engineering Mindset Expectations

While implementing the assignment, always think:

  • What happens if input is invalid?
  • How will this be debugged later?
  • Is this code testable?
  • Can another developer understand this easily?
  • Are edge cases handled properly?

This mindset is essential for professional backend engineering.


๐Ÿ“ฆ Submission Requirements

The learner should submit:

  • Source code
  • Test classes
  • Screenshots of successful test execution
  • API testing evidence
  • README explaining implementation

๐Ÿ Expected Outcome

By completing this assignment, the learner should be able to:

โœ… Write basic unit tests โœ… Validate REST API requests โœ… Handle backend exceptions properly โœ… Add meaningful application logs โœ… Debug common backend issues โœ… Improve backend application quality


๐Ÿ“š Bonus Challenges (Optional)

Advanced learners may additionally implement:

  • Custom validation annotations
  • Structured JSON logging
  • Test coverage reporting
  • Integration tests
  • Parameterized tests

๐Ÿ’ก Mentor Notes

The goal of this assignment is not perfection.

The goal is to:

  • Build confidence
  • Encourage experimentation
  • Develop debugging skills
  • Learn production-quality backend practices

Mistakes are expected and encouraged during learning.


ยฉ 2026 Aditya Pratap Bhuyan Licensed under GPL-3.0 Maintained for backend engineering mentorship and learning.


This site uses Just the Docs, a documentation theme for Jekyll.