BAEL-3416 - Mockito and Fluent APIs

- stage changes
This commit is contained in:
Jon Cook 2019-11-11 23:19:35 +01:00
parent be6021a4af
commit e42ce73616
3 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,82 @@
package com.baeldung.mockito.fluentapi;
import java.util.List;
public class Pizza {
public enum PizzaSize {
LARGE, MEDIUM, SMALL;
}
private String name;
private PizzaSize size;
private List<String> toppings;
private String email;
private boolean stuffedCrust;
private Pizza(PizzaBuilder builder) {
this.name = builder.name;
this.size = builder.size;
this.toppings = builder.toppings;
this.stuffedCrust = builder.stuffedCrust;
}
public static class PizzaBuilder {
private String name;
private PizzaSize size;
private String email;
private boolean stuffedCrust;
private List<String> toppings;
public PizzaBuilder(String name) {
this.name = name;
}
public PizzaBuilder size(PizzaSize size) {
this.size = size;
return this;
}
public PizzaBuilder withExtaTopping(String extraTopping) {
this.toppings.add(extraTopping);
return this;
}
public PizzaBuilder withStuffedCrust(boolean stuffedCrust) {
this.stuffedCrust = stuffedCrust;
return this;
}
public BankAccountBuilder willCollect(boolean collect) {
this.newsletter = newsletter;
return this;
}
public BankAccountBuilder applyDiscount(boolean collect) {
this.newsletter = newsletter;
return this;
}
public Pizza build() {
return new Pizza(this);
}
}
public String getName() {
return name;
}
public PizzaSize getSize() {
return size;
}
public String getEmail() {
return email;
}
public boolean isNewsletter() {
return newsletter;
}
}

View File

@ -0,0 +1,5 @@
package com.baeldung.mockito.fluentapi;
public class PizzaService {
}

View File

@ -0,0 +1,23 @@
package com.baeldung.mockito.fluentapi;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
public class PizzaServiceUnitTest {
@Test
public void test() {
}
public List<String> convertAllToUpperCase(List<String> words) {
return words.stream()
.map(String::toUpperCase)
.collect(Collectors.toList());
}
}