Skip to content

Commit

Permalink
. d Update RemovingEnvironmentAwareReporter.md
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsEckart authored Oct 2, 2023
1 parent 482e3b1 commit 50d4844
Showing 1 changed file with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,55 @@ Before October 2023 "ApprovalTests 19.0.0" and before,

```mermaid
classDiagram
interface EnvironmentAwareReporter{
class ApprovalFailureReporter{
<<interface>>
+report(String received, String approved): void
}
class EnvironmentAwareReporter{
<<interface>>
+isWorkingInThisEnvironment(String forFile): boolean
}
interface ApprovalFailureReporter{
+report(String received, String approved): void
ApprovalFailureReporter <|-- EnvironmentAwareReporter
```

This allowed us to use chain of responsibility to determine which Reporter to use.
The problem with `isWorkingInThisEnvironment` is that it is **predictive** but not **complete**.
It is saying that it should work in this environment but maybe something goes wrong when you actually do it.
Instead, we've combined this into

```mermaid
classDiagram
class ApprovalFailureReporter{
<<interface>>
+report(String received, String approved): boolean
}
EnvironmentAwareReporter <|-- ApprovalFailureReporter
```

When you call report, the reporter now tells you if it worked.

## How to upgrade

### Upgrading an EnvironmentAwareReporter

For an EnvironmentAwareReporter there are two things you have to do.
1. Change EnvironmentAwareReporter to ApprovalFailureReporter
2. Change the reporter:

```java

public boolean report(String received, String approved)
{
if (!isWorkingInThisEnvironment(received))
{
return false;
}
// old reporter code here
return true;
}
```

`isWorkingInThisEnvironment()` can be made private now usually or inlined.

### Upgrading an ApprovalFailureReporter

* Add `return true;` to the end of your `report(String received, String approved)` method to satisfy the compiler.

0 comments on commit 50d4844

Please sign in to comment.