{"id":31105939,"url":"https://github.com/bright/bright-training-avoid-mocks","last_synced_at":"2025-09-17T04:48:22.479Z","repository":{"id":302242570,"uuid":"991845899","full_name":"bright/bright-training-avoid-mocks","owner":"bright","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-01T09:10:44.000Z","size":120,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-01T10:25:59.623Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bright.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-28T08:30:59.000Z","updated_at":"2025-05-28T08:38:13.000Z","dependencies_parsed_at":"2025-07-01T10:36:35.538Z","dependency_job_id":null,"html_url":"https://github.com/bright/bright-training-avoid-mocks","commit_stats":null,"previous_names":["bright/bright-training-avoid-mocks"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bright/bright-training-avoid-mocks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fbright-training-avoid-mocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fbright-training-avoid-mocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fbright-training-avoid-mocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fbright-training-avoid-mocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bright","download_url":"https://codeload.github.com/bright/bright-training-avoid-mocks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fbright-training-avoid-mocks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275537147,"owners_count":25482345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-17T04:48:19.398Z","updated_at":"2025-09-17T04:48:22.474Z","avatar_url":"https://github.com/bright.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bright Training: Avoiding Mocks and Improving HTTP Request Handling\n\nThis repository contains training materials for addressing two common issues in Spring Boot applications:\n\n1. **Abuse of mocks in tests** - Overuse of mocks can lead to brittle tests that are tightly coupled to implementation details.\n2. **Reliance on HttpServletRequest and HttpServletResponse in service layers** - Direct use of servlet API in service layers makes code harder to test and less reusable.\n\n## Training Plan\n\nThis repository is organized into branches that demonstrate the progression from problematic code to improved implementations:\n\n### Branch 1: `initial-state`\n- Examples of problematic code with excessive mocking\n- Examples of service layer code tightly coupled to servlet API\n- Tests that are brittle and hard to maintain\n\n### Branch 2: `refactored-code`\n- Refactored code using \"Testing Without Mocks\" patterns\n- Improved HTTP request handling with proper abstractions\n- Tests that are more robust and less coupled to implementation details\n\n## Key Concepts\n\n### Testing Without Mocks\nBased on James Shore's \"Testing Without Mocks: A Pattern Language\", this approach focuses on:\n- Using real objects instead of mocks when possible\n- Creating \"Nullables\" or \"Fakes\" for infrastructure dependencies\n- Using \"Output Trackers\" to verify behavior without mocks\n- Structuring code to be more testable without mocks\n\n### Improved HTTP Request Handling\n- Abstracting HTTP request/response details behind interfaces\n- Using DTOs to pass data between layers\n- Keeping servlet API dependencies at the controller level only\n\n## Getting Started\n\nThis project uses:\n- Java 21\n- Spring Boot 3.2.0\n- Gradle\n\nTo run the application:\n```\n./gradlew bootRun\n```\n\nTo run the tests:\n```\n./gradlew test\n```\n\n## Training Sessions\n\n### Session 1: Understanding the Problems\n- Identify issues with current approach\n- Demonstrate how current tests break during refactoring\n- Show how servlet API dependencies make testing difficult\n\n### Session 2: Implementing Solutions\n- Introduce \"Testing Without Mocks\" patterns\n- Refactor code to remove servlet API dependencies from service layer\n- Create more robust tests using the new patterns\n\n### Session 3: Applying to Real Projects\n- Strategies for incrementally improving existing codebases\n- Identifying good candidates for refactoring\n- Measuring success: fewer test failures during refactoring","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbright%2Fbright-training-avoid-mocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbright%2Fbright-training-avoid-mocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbright%2Fbright-training-avoid-mocks/lists"}