Skip to content

Commit

Permalink
. d updated markdown snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 13, 2024
1 parent 7399174 commit 9a45919
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions approvaltests-util/docs/how_to/LoadersAndSavers.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ We want to test the following method:
<!-- snippet: step1 -->
<a id='snippet-step1'></a>
```java
public void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) {
List<Customer> seniorCustomers = database.getSeniorCustomers();
for (Customer customer : seniorCustomers) {
Discount seniorDiscount = getSeniorDiscount();
String message = generateDiscountMessage(customer, seniorDiscount);
mailServer.sendMessage(customer, message);
}
public void sendOutSeniorDiscounts(DataBase database, MailServer mailServer)
{
List<Customer> seniorCustomers = database.getSeniorCustomers();
for (Customer customer : seniorCustomers)
{
Discount seniorDiscount = getSeniorDiscount();
String message = generateDiscountMessage(customer, seniorDiscount);
mailServer.sendMessage(customer, message);
}
}
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java#L56-L65' title='Snippet source file'>snippet source</a> | <a href='#snippet-step1' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java#L60-L71' title='Snippet source file'>snippet source</a> | <a href='#snippet-step1' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

In this case, we want to replace the functions that use the DataBase object with Loaders :
Expand All @@ -62,14 +64,15 @@ We start with the test:
<a id='snippet-step0'></a>
```java
@Test
public void senior_customer_list_includes_only_those_over_age_65() {
DataBase database = initializeDatabase();
MailServer mailServer = initializeMailServer();
sendOutSeniorDiscounts(database, mailServer);
Approvals.verifyAll("", mailServer.getRecipients());
public void senior_customer_list_includes_only_those_over_age_65()
{
DataBase database = initializeDatabase();
MailServer mailServer = initializeMailServer();
sendOutSeniorDiscounts(database, mailServer);
Approvals.verifyAll("", mailServer.getRecipients());
}
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java#L10-L18' title='Snippet source file'>snippet source</a> | <a href='#snippet-step0' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java#L12-L21' title='Snippet source file'>snippet source</a> | <a href='#snippet-step0' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

This test works against a live database with a live mail server.
Expand All @@ -91,7 +94,7 @@ Now we dump the data resulting from a successful query so that we can create a f
List<Customer> seniorCustomers = database.getSeniorCustomers();
seniorCustomers.stream().forEach(System.out::println);
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java#L37-L40' title='Snippet source file'>snippet source</a> | <a href='#snippet-step_capture_data' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java#L40-L43' title='Snippet source file'>snippet source</a> | <a href='#snippet-step_capture_data' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

generates
Expand All @@ -110,11 +113,10 @@ Step 3: Create a result object populated with these values (or at least enough o
<!-- snippet: step_fake_data -->
<a id='snippet-step_fake_data'></a>
```java
List.of(
new Customer( "Bob, Jones, 123 Elm St., Tempe, AZ, 14-MAR-1958"),
new Customer("Mary, Smith, 345 Oak St., Mason, VA, 04-MAY-1944"));
List.of(new Customer("Bob, Jones, 123 Elm St., Tempe, AZ, 14-MAR-1958"),
new Customer("Mary, Smith, 345 Oak St., Mason, VA, 04-MAY-1944"));
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java#L46-L50' title='Snippet source file'>snippet source</a> | <a href='#snippet-step_fake_data' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java#L51-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-step_fake_data' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Step 4: In the original method, replace the function call with a Loader
Expand Down

0 comments on commit 9a45919

Please sign in to comment.