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
@Test public void | |
print_transactions_in_reverse_chronological_order() { | |
given(clock.timeAsString()).willReturn("01/04/2014", "02/04/2014", "10/04/2014"); | |
account.deposit(1000); | |
account.withdraw(100); | |
account.deposit(500); | |
account.printStatement(); |
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
public class TripService { | |
public List<Trip> getTripsByUser(User user) throws UserNotLoggedInException { | |
List<Trip> tripList = new ArrayList<Trip>(); | |
User loggedUser = loggedUser(); | |
boolean isFriend = false; | |
if (loggedUser != null) { | |
for (User friend : user.getFriends()) { | |
if (friend.equals(loggedUser)) { | |
isFriend = true; |
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
public List<Trip> getTripsByUser(User user) throws UserNotLoggedInException { | |
User loggedUser = loggedUser(); | |
validate(loggedUser); | |
List<Trip> tripList = new ArrayList<Trip>(); | |
boolean isFriend = false; | |
for (User friend : user.getFriends()) { | |
if (friend.equals(loggedUser)) { | |
isFriend = true; | |
break; | |
} |
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
@Test public void | |
shouldReturnTrueWhenUsersAreFriends() throws Exception { | |
User John = new User(); | |
User Bob = new User(); | |
John.addFriend(Bob); | |
assertTrue(John.isFriendsWith(Bob)); | |
} |
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
public class User { | |
... | |
private List<User> friends = new ArrayList<User>(); | |
public void addFriend(User user) { | |
friends.add(user); | |
} |
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
public List<Trip> getTripsByUser(User user) throws UserNotLoggedInException { | |
User loggedUser = loggedUser(); | |
validate(loggedUser); | |
return (user.isFriendsWith(loggedUser)) | |
? findTripsByUser(user) | |
: new ArrayList<Trip>(); | |
} |
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
public class TripService { | |
public List<Trip> getFriendTrips(User loggedUser, User friend) throws UserNotLoggedInException { | |
validate(loggedUser); | |
return (friend.isFriendsWith(loggedUser)) | |
? findTripsForFriend(friend) | |
: new ArrayList<Trip>(); | |
} | |
private void validate(User loggedUser) throws UserNotLoggedInException { |
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
public abstract class PrincingService { | |
public double calculatePrice(ShoppingBasket shoppingBasket, User user, String voucher) { | |
double discount = calculateDiscount(user); | |
double total = 0; | |
for (ShoppingBasket.Item item : shoppingBasket.items()) { | |
total += calculateProductPrice(item.getProduct(), item.getQuantity()); | |
} | |
total = applyAdditionalDiscounts(total, user, voucher); | |
return total * ((100 - discount) / 100); |
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
public class StandardPricingServiceTest { | |
private TestableStandardPricingService standardPricingService = new TestableStandardPricingService(); | |
@Test public void | |
should_return_product_price_when_quantity_is_one() { | |
Product book = aProduct().costing(10).build(); | |
double price = standardPricingService.calculateProductPrice(book, 1); |
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
public class StandardPriceCalculation { | |
public double calculateProductPrice(Product product, int quantity) { | |
return product.getPrice() * quantity; | |
} | |
} |
OlderNewer