Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maciej Kaszyński
committed
Nov 25, 2019
1 parent
3234e61
commit ab45db5
Showing
3 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
5-facade/src/test/java/com/mkaszynski/tdd/pricing/InMemoryBasketRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mkaszynski.tdd.pricing; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.mkaszynski.tdd.pricing.Campaign.emptyCampaign; | ||
import static java.util.Collections.emptyList; | ||
|
||
class InMemoryBasketRepo implements BasketRepository { | ||
private Map<Long, Basket> map = new HashMap<>(); | ||
|
||
@Override | ||
public Basket getBasket(Long basketId) { | ||
return map.getOrDefault(basketId, emptyBasket()); | ||
} | ||
|
||
@Override | ||
public Long save(Basket basket) { | ||
long id = map.size(); | ||
map.put(id, basket); | ||
return id; | ||
} | ||
|
||
private Basket emptyBasket() { | ||
return new Basket(1L, emptyList(), emptyCampaign()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
5-facade/src/test/java/com/mkaszynski/tdd/pricing/InMemoryProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mkaszynski.tdd.pricing; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
class InMemoryProductRepository implements ProductRepository { | ||
private Map<String, Product> map = new HashMap<>(); | ||
|
||
@Override | ||
public Product getProduct(String name) { | ||
return map.get(name); | ||
} | ||
|
||
@Override | ||
public String save(Product product) { | ||
map.put(product.getName(), product); | ||
return product.getName(); | ||
} | ||
} |