Skip to content

Commit

Permalink
Proposed Solution Day 23
Browse files Browse the repository at this point in the history
  • Loading branch information
ythirion committed Dec 24, 2023
1 parent 4537b6e commit 9bee113
Show file tree
Hide file tree
Showing 43 changed files with 1,943 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ A solution proposal will be published here every day during the `Advent Of Craft
- [Day 20: No more exceptions in our domain.](solution/day20/docs/step-by-step.md)
- [Day 21: Refactor the tests and production code to Output-Based tests.](solution/day21/docs/step-by-step.md)
- [Day 22: Design a diamond program using T.D.D and Property-Based Testing.](solution/day22/docs/step-by-step.md)
- [Day 23: Refactor the code after putting it under test.](solution/day23/docs/step-by-step.md)

## Contributors

Expand Down
40 changes: 40 additions & 0 deletions solution/day23/docs/challenge-done.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Day 23: Refactor the legacy code after putting it under test.
Refactor the `TripService` class to ensure Clean Code / SOLID principles

Legacy code golden rules :
`You cannot change any existing code if not covered by tests.`

The only exception is if we need to change the code to add unit tests, but in this case, just automated refactorings (via IDE) are allowed.

## Step by Step

We use different steps that are all described separately (step-by-step md files):

1. Cover the production code
2. Improve confidence in our tests
3. Refactor the production code
4. Other refactorings

## What did we use / learn ?
- `Seams`
- `Automated refactoring` via our IDE
- Extract Method
- Change Signature
- Rename
- `Mutation Testing`
- Use `Higher Order Functions` to avoid duplication
- Use `code coverage` as a driver
- `Test Data Builder`
- `Feature Envy`
- `Sprout Class`
- `TDD`

>**Tip of the day1: Start testing from shortest to deepest branch.**
>**Tip of the day2: Start refactoring from deepest to shortest branch.**
### Share your experience

How does your code look like?

Please let everyone know in the discord.
Binary file added solution/day23/docs/img/activate-tracing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/change-signature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/coverage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/coverage2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/coverage3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/coverage4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/demo-bracnh-coverage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/demo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/demo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/end-strangler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/introduced-mutants.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/mock-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/move-closer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/pitest-report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/safe-delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/tdd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/test-readability.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/tips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/img/video.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added solution/day23/docs/snippet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions solution/day23/docs/step-by-step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Day 23: Refactor the legacy code after putting it under test.
Refactor the `TripService` class to ensure Clean Code / SOLID principles

Legacy code golden rules :
`You cannot change any existing code if not covered by tests.`

The only exception is if we need to change the code to add unit tests, but in this case, just automated refactorings (via IDE) are allowed.

## Tips
- Start testing from shortest to deepest branch
- Start refactoring from deepest to shortest branch

![Working with Legacy Code Tips](img/tips.png)

## Step by Step
1. [Cover the production code](steps/1.cover-the-code.md)
2. [Improve confidence in our tests](steps/2.mutate-some-code.md)
3. [Refactor the production code](steps/3.refactoring.md)
4. [Other refactorings](steps/4.other-refactorings.md)

## What did we use / learn ?
- `Seams`
- `Automated refactoring` via our IDE
- Extract Method
- Change Signature
- Rename
- `Mutation Testing`
- Use `Higher Order Functions` to avoid duplication
- Use `code coverage` as a driver
- `Test Data Builder`
- `Feature Envy`
- `Sprout Class`
- `TDD`

Sources :
- [Nicolas Carlo - understand legacy code](https://understandlegacycode.com/blog/key-points-of-working-effectively-with-legacy-code/#identify-seams-to-break-your-code-dependencies)
- [Sandro Mancuso - Testing legacy with Hard-wired dependencies](https://www.codurance.com/publications/2011/07/16/testing-legacy-hard-wired-dependencies)
- [Micheal Feathers - Working Effectively with Legacy Code](https://www.oreilly.com/library/view/working-effectively-with/0131177052/)

<a href="https://youtu.be/LSqbXorkyfQ" rel="Sandro's video">![Sandro's video](img/video.png)</a>
Loading

0 comments on commit 9bee113

Please sign in to comment.