Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Twój kod
- interface Caller {
- public void createNewProduct(Product p);
- }
- class ApiCaller implements Caller {
- public void createNewProduct(Product p) {
- // wysyłamy produkt do API
- }
- }
- class ProductGenerator {
- private Caller caller;
- public ProductGenerator(Caller c) {
- this.caller = c;
- }
- /**
- Tworzymy nowy produkt o danej nazwie i wartości oraz wysyłamy go do API
- */
- public void generateProduct(string name, int amount) {
- Product p = new Product();
- p.setName(name);
- p.setAmount(amount);
- this.caller.createNewProduct(p);
- }
- }
- // TESTY KLASY ProductGenerator
- public void test() {
- string name = "Test product";
- int amount = 15;
- Caller mock = createMock(Caller.class)
- .onMethod(createNewProduct)
- .do(Product p -> {
- assertEquals(p.getName(), name);
- assertEquals(p.getAmount(), amount);
- }
- );
- ProductGenerator generator = new ProductGenerator(mock);
- generator.generateProduct(name, amount);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement