@Test public void testRegisterPurchase() { PublisherContract contract = new PublisherContract(); PublisherContractId publisherContractId = PublisherContractId.randomId(); contract.register(publisherContractId, "Addison Wesley", 10.0, 10000); contract.registerPurchase(ProductId.randomId(), 60000L, 1); contract.registerPurchase(ProductId.randomId(), 60000L, 1); contract.registerPurchase(ProductId.randomId(), 60000L, 1); Iterator<PurchaseRegisteredEvent> purchases = filter(contract.getUncommittedEvents(), PurchaseRegisteredEvent.class).iterator(); assertThat(purchases.next().purchaseAmount, is(60000L)); assertThat(purchases.next().purchaseAmount, is(60000L)); assertThat(purchases.next().purchaseAmount, is(60000L)); purchases = filter(contract.getUncommittedEvents(), PurchaseRegisteredEvent.class).iterator(); assertThat(purchases.next().feeAmount, is(6000L)); assertThat(purchases.next().feeAmount, is(4000L)); assertThat(purchases.next().feeAmount, is(0L)); }
public void registerPurchase(ProductId productId, long unitPrice, int quantity) { long purchaseAmount = unitPrice * quantity; AccumulatedFee newFee = new AccumulatedFee(accumulatedFee, limit, feePercentage).addPurchase(purchaseAmount); applyChange(new PurchaseRegisteredEvent(id(), nextVersion(), now(), productId, purchaseAmount, newFee.lastPurchaseFee(), newFee.accumulatedFee())); }
PublisherContract extends AggregateRoot<PublisherContractId> { public void registerPurchase(ProductId productId, long unitPrice, int quantity) { long purchaseAmount = unitPrice * quantity; AccumulatedFee newFee = new AccumulatedFee(accumulatedFee, limit, feePercentage).addPurchase(purchaseAmount); applyChange(new PurchaseRegisteredEvent(id(), nextVersion(), now(), productId, purchaseAmount, newFee.lastPurchaseFee(), newFee.accumulatedFee())); } }
PublisherContract extends AggregateRoot<PublisherContractId> { public void registerPurchase(ProductId productId, long unitPrice, int quantity) { long purchaseAmount = unitPrice * quantity; AccumulatedFee newFee = new AccumulatedFee(accumulatedFee, limit, feePercentage).addPurchase(purchaseAmount); applyChange(new PurchaseRegisteredEvent(id(), nextVersion(), now(), productId, purchaseAmount, newFee.lastPurchaseFee(), newFee.accumulatedFee())); }  }
PublisherContract extends AggregateRoot<PublisherContractId> { public void registerPurchase(ProductId productId, long unitPrice, int quantity) { long purchaseAmount = unitPrice * quantity; AccumulatedFee newFee = new AccumulatedFee(accumulatedFee, limit, feePercentage).addPurchase(purchaseAmount); applyChange(new PurchaseRegisteredEvent(id(), nextVersion(), now(), productId, purchaseAmount, newFee.lastPurchaseFee(), newFee.accumulatedFee())); }  void register(PublisherContractId publisherContractId, String name, double feePercentage, long limit); void registerPurchase(ProductId productId, long unitPrice, int quantity); }
PublisherContract extends AggregateRoot<PublisherContractId> { public void registerPurchase(ProductId productId, long unitPrice, int quantity) { long purchaseAmount = unitPrice * quantity; AccumulatedFee newFee = new AccumulatedFee(accumulatedFee, limit, feePercentage).addPurchase(purchaseAmount); applyChange(new PurchaseRegisteredEvent(id(), nextVersion(), now(), productId, purchaseAmount, newFee.lastPurchaseFee(), newFee.accumulatedFee())); }  void register(PublisherContractId publisherContractId, String name, double feePercentage, long limit); void registerPurchase(ProductId productId, long unitPrice, int quantity);  }