Skip to content

Commit 50d4844

Browse files
authored
. d Update RemovingEnvironmentAwareReporter.md
1 parent 482e3b1 commit 50d4844

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

approvaltests/docs/explanations/RemovingEnvironmentAwareReporter.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,55 @@ Before October 2023 "ApprovalTests 19.0.0" and before,
77

88
```mermaid
99
classDiagram
10-
interface EnvironmentAwareReporter{
10+
class ApprovalFailureReporter{
11+
<<interface>>
12+
+report(String received, String approved): void
13+
}
14+
class EnvironmentAwareReporter{
15+
<<interface>>
1116
+isWorkingInThisEnvironment(String forFile): boolean
1217
}
13-
interface ApprovalFailureReporter{
14-
+report(String received, String approved): void
18+
ApprovalFailureReporter <|-- EnvironmentAwareReporter
19+
```
20+
21+
This allowed us to use chain of responsibility to determine which Reporter to use.
22+
The problem with `isWorkingInThisEnvironment` is that it is **predictive** but not **complete**.
23+
It is saying that it should work in this environment but maybe something goes wrong when you actually do it.
24+
Instead, we've combined this into
25+
26+
```mermaid
27+
classDiagram
28+
class ApprovalFailureReporter{
29+
<<interface>>
30+
+report(String received, String approved): boolean
1531
}
16-
EnvironmentAwareReporter <|-- ApprovalFailureReporter
1732
```
1833

34+
When you call report, the reporter now tells you if it worked.
35+
36+
## How to upgrade
37+
38+
### Upgrading an EnvironmentAwareReporter
39+
40+
For an EnvironmentAwareReporter there are two things you have to do.
41+
1. Change EnvironmentAwareReporter to ApprovalFailureReporter
42+
2. Change the reporter:
43+
44+
```java
45+
46+
public boolean report(String received, String approved)
47+
{
48+
if (!isWorkingInThisEnvironment(received))
49+
{
50+
return false;
51+
}
52+
// old reporter code here
53+
return true;
54+
}
55+
```
56+
57+
`isWorkingInThisEnvironment()` can be made private now usually or inlined.
58+
59+
### Upgrading an ApprovalFailureReporter
1960

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

0 commit comments

Comments
 (0)