Skip to content

Commit

Permalink
. td Documenting Test update on Step 6
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottBob committed Aug 8, 2024
1 parent d846198 commit f45f668
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ public void sendOutSeniorDiscounts(MailServer mailServer, Loader<List<Customer>>
mailServer.sendMessage(customer, message);
}
}
// begin-snippet: step0_b
@Test
public void senior_customer_list_includes_only_those_over_age_65()
{
Loader<List<Customer>> mailingList = () -> List.of(new Customer("Bob"), new Customer("Mary"), new Customer("Tom"));
MailServer mailServer = initializeMailServer();
sendOutSeniorDiscounts(mailServer, mailingList);
Approvals.verifyAll("", mailServer.getRecipients());
}
// end-snippet
private MailServer initializeMailServer()
{
return new MailServer();
}
private DataBase initializeDatabase()
{
return null;
}

}
private String generateDiscountMessage(Customer customer, Discount seniorDiscount)
{
Expand Down
36 changes: 26 additions & 10 deletions approvaltests-util/docs/how_to/LoadersAndSavers.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,35 @@ Step 5: Now we introduce the new loader function as a parameter to the original
}
</pre>

Step 6: Update the calls to this function (including tests) to use the new Loader parameter.
Step 6: Update the unit tests to use the new Loader parameter.
We have now removed the reliance on the database to retrieve the data.
We still rely on a mail server to send the results.

public void senior_customer_list_includes_only_those_over_age_65() {

&nbsp; MailServer mailServer = // initialize server

&nbsp; List&lt;Customer&gt; seniorCustomers = List.of(new Customer("Bob", "Jones", /\* ... /), / ... \*/);

&nbsp; sendOutSeniorDiscounts(null, mailServer, () -> seniorCustomers));
<!-- Snippet Compare: step0, step0_b -->

&nbsp; Approvals.verifyAll(mailServer.getRecipients());
<pre style="color: gray">
@Test
public void senior_customer_list_includes_only_those_over_age_65()
{
<b style="color: red"> DataBase database = initializeDatabase(); </b>
MailServer mailServer = initializeMailServer();
sendOutSeniorDiscounts( mailServer, <b style="color: red">database </b>);
Approvals.verifyAll("", mailServer.getRecipients());
}
</pre>
#
<pre style="color: gray">
@Test
public void senior_customer_list_includes_only_those_over_age_65()
{
<s style="color: red"> DataBase database = initializeDatabase(); </s>
<b style="color: green"> Loader&lt;List&lt;Customer>> mailingList = () -> List.of(new Customer("Bob"), new Customer("Mary"), new Customer("Tom")); </b>
MailServer mailServer = initializeMailServer();
sendOutSeniorDiscounts( mailServer, <s style="color: red">database </s> <b style="color: green">mailingList </b>);
Approvals.verifyAll("", mailServer.getRecipients());
}
</pre>

}

Step 7: Now we can remove the DataBase as a parameter altogether.

Expand Down

0 comments on commit f45f668

Please sign in to comment.