diff --git a/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java b/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java index 258be231..1341b63e 100644 --- a/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java +++ b/approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java @@ -5,134 +5,146 @@ import java.util.List; -public class LoadersAndSaversExamplesTest { - public static class Step0 { - // begin-snippet: step0 - @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()); - } - // end-snippet - - private MailServer initializeMailServer() { - return new MailServer(); - } - - private DataBase initializeDatabase() { - return null; - } - - private void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) { - - } +public class LoadersAndSaversExamplesTest +{ + public static class Step0 + { + // begin-snippet: step0 + @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 static class Step0_5 { - @Test - void test_dump_data() { - MyDatabase database = new MyDatabase(); - // begin-snippet: step_capture_data - List seniorCustomers = database.getSeniorCustomers(); - seniorCustomers.stream().forEach(System.out::println); - // end-snippet - Approvals.verifyAll("", seniorCustomers, c -> c.toString()); - } - public static class MyDatabase { - public List getSeniorCustomers() { - return - // begin-snippet: step_fake_data - 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")); - // end-snippet - } - } + // end-snippet + private MailServer initializeMailServer() + { + return new MailServer(); } - - class Step1 { - // begin-snippet: step1 - public void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) { - List seniorCustomers = database.getSeniorCustomers(); - for (Customer customer : seniorCustomers) { - Discount seniorDiscount = getSeniorDiscount(); - String message = generateDiscountMessage(customer, seniorDiscount); - mailServer.sendMessage(customer, message); - } - } - // end-snippet + private DataBase initializeDatabase() + { + return null; } - - class Step2 { - // begin-snippet: step2 - public void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) { - Loader> seniorCustomerLoader = () -> database.getSeniorCustomers(); - List seniorCustomers = seniorCustomerLoader.load(); - for (Customer customer : seniorCustomers) { - Discount seniorDiscount = getSeniorDiscount(); - String message = generateDiscountMessage(customer, seniorDiscount); - mailServer.sendMessage(customer, message); - } - } - // end-snippet + private void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) + { } - - class Step3 { - // begin-snippet: step3 - public void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) { - sendOutSeniorDiscounts(mailServer, database::getSeniorCustomers); // + - } // + - - // + - public void sendOutSeniorDiscounts(MailServer mailServer, Loader> seniorCustomerLoader) { // + - List seniorCustomers = seniorCustomerLoader.load(); - for (Customer customer : seniorCustomers) { - Discount seniorDiscount = getSeniorDiscount(); - String message = generateDiscountMessage(customer, seniorDiscount); - mailServer.sendMessage(customer, message); - } - } + } + public static class Step0_5 + { + @Test + void test_dump_data() + { + MyDatabase database = new MyDatabase(); + // begin-snippet: step_capture_data + List seniorCustomers = database.getSeniorCustomers(); + seniorCustomers.stream().forEach(System.out::println); + // end-snippet + Approvals.verifyAll("", seniorCustomers, c -> c.toString()); + } + public static class MyDatabase + { + public List getSeniorCustomers() + { + return + // begin-snippet: step_fake_data + 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")); // end-snippet + } } - - private String generateDiscountMessage(Customer customer, Discount seniorDiscount) { - return null; + } + class Step1 + { + // begin-snippet: step1 + public void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) + { + List seniorCustomers = database.getSeniorCustomers(); + for (Customer customer : seniorCustomers) + { + Discount seniorDiscount = getSeniorDiscount(); + String message = generateDiscountMessage(customer, seniorDiscount); + mailServer.sendMessage(customer, message); + } } - - private Discount getSeniorDiscount() { - return null; + // end-snippet + } + class Step2 + { + // begin-snippet: step2 + public void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) + { + Loader> seniorCustomerLoader = () -> database.getSeniorCustomers(); + List seniorCustomers = seniorCustomerLoader.load(); + for (Customer customer : seniorCustomers) + { + Discount seniorDiscount = getSeniorDiscount(); + String message = generateDiscountMessage(customer, seniorDiscount); + mailServer.sendMessage(customer, message); + } } - - private class DataBase { - public List getSeniorCustomers() { - return List.of(); - } + // end-snippet + } + class Step3 + { + // begin-snippet: step3 + public void sendOutSeniorDiscounts(DataBase database, MailServer mailServer) + { + sendOutSeniorDiscounts(mailServer, database::getSeniorCustomers); // + + } // + + // + + public void sendOutSeniorDiscounts(MailServer mailServer, Loader> seniorCustomerLoader) + { // + + List seniorCustomers = seniorCustomerLoader.load(); + for (Customer customer : seniorCustomers) + { + Discount seniorDiscount = getSeniorDiscount(); + String message = generateDiscountMessage(customer, seniorDiscount); + mailServer.sendMessage(customer, message); + } } - - private static class MailServer { - public void sendMessage(Customer customer, String message) { - } - - public String[] getRecipients() { - return new String[] {}; - } + // end-snippet + } + private String generateDiscountMessage(Customer customer, Discount seniorDiscount) + { + return null; + } + private Discount getSeniorDiscount() + { + return null; + } + private class DataBase + { + public List getSeniorCustomers() + { + return List.of(); } - - private static class Customer { - private final String s; - - public Customer(String s) { - this.s = s; - } - - @Override - public String toString() { - return s; - } + } + private static class MailServer + { + public void sendMessage(Customer customer, String message) + { } - - private class Discount { + public String[] getRecipients() + { + return new String[]{}; + } + } + private static class Customer + { + private final String s; + public Customer(String s) + { + this.s = s; + } + @Override + public String toString() + { + return s; } + } + private class Discount + { + } }