Skip to content

Commit

Permalink
a reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 9, 2024
1 parent b95b228 commit b336f9f
Showing 1 changed file with 130 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Customer> seniorCustomers = database.getSeniorCustomers();
seniorCustomers.stream().forEach(System.out::println);
// end-snippet
Approvals.verifyAll("", seniorCustomers, c -> c.toString());
}
public static class MyDatabase {
public List<Customer> 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<Customer> 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<List<Customer>> seniorCustomerLoader = () -> database.getSeniorCustomers();
List<Customer> 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<List<Customer>> seniorCustomerLoader) { // +
List<Customer> 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<Customer> seniorCustomers = database.getSeniorCustomers();
seniorCustomers.stream().forEach(System.out::println);
// end-snippet
Approvals.verifyAll("", seniorCustomers, c -> c.toString());
}
public static class MyDatabase
{
public List<Customer> 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<Customer> 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<List<Customer>> seniorCustomerLoader = () -> database.getSeniorCustomers();
List<Customer> seniorCustomers = seniorCustomerLoader.load();
for (Customer customer : seniorCustomers)
{
Discount seniorDiscount = getSeniorDiscount();
String message = generateDiscountMessage(customer, seniorDiscount);
mailServer.sendMessage(customer, message);
}
}

private class DataBase {
public List<Customer> 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<List<Customer>> seniorCustomerLoader)
{ // +
List<Customer> 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<Customer> 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
{
}
}

0 comments on commit b336f9f

Please sign in to comment.