public PurchaseExecution withPurchasedSharesOf(int aQuantity) { if (this.wouldOverrunExecutionWith(aQuantity)) { throw new IllegalArgumentException("Acquired too many shares."); } int quantityOfSharesOutstanding = this.quantityOfSharesOutstanding() - aQuantity; return new PurchaseExecution(this.openDate(), this.quantityOfSharesOrdered(), quantityOfSharesOutstanding); }
public void testNoNegativeQuantities() throws Exception { try { new PurchaseExecution(-20); fail("Should not allow negative order quantity."); } catch (Exception e) { // success } try { PurchaseExecution purchaseExecution = new PurchaseExecution(10); purchaseExecution.withPurchasedSharesOf(11); fail("Should not allow overrun purchase execution."); } catch (Exception e) { // success } }
public void testOpenExecution() throws Exception { PurchaseExecution purchaseExecution = new PurchaseExecution(20); assertEquals(20, purchaseExecution.quantityOfSharesOrdered()); assertEquals(20, purchaseExecution.quantityOfSharesOutstanding()); assertNull(purchaseExecution.filledDate()); assertNotNull(purchaseExecution.openDate()); Calendar openDate = Calendar.getInstance(); openDate.setTime(purchaseExecution.openDate()); assertEquals(Calendar.getInstance().get(Calendar.MONTH), openDate.get(Calendar.MONTH)); assertEquals(Calendar.getInstance().get(Calendar.DATE), openDate.get(Calendar.DATE)); assertEquals(Calendar.getInstance().get(Calendar.YEAR), openDate.get(Calendar.YEAR)); }
public void testFillExecution() throws Exception { PurchaseExecution purchaseExecution = new PurchaseExecution(20); for (int count = 0; count < 4; ++count) { assertTrue(purchaseExecution.isOpen()); assertFalse(purchaseExecution.isFilled()); purchaseExecution = purchaseExecution.withPurchasedSharesOf(5); } assertFalse(purchaseExecution.isOpen()); assertTrue(purchaseExecution.isFilled()); assertNotNull(purchaseExecution.filledDate()); Calendar filledDate = Calendar.getInstance(); filledDate.setTime(purchaseExecution.filledDate()); assertEquals(Calendar.getInstance().get(Calendar.MONTH), filledDate.get(Calendar.MONTH)); assertEquals(Calendar.getInstance().get(Calendar.DATE), filledDate.get(Calendar.DATE)); assertEquals(Calendar.getInstance().get(Calendar.YEAR), filledDate.get(Calendar.YEAR)); }
public BuyOrder( AccountId anAccountId, Quote aQuote, int aQuantityOfSharesOrdered, Money anOrderFee) { super(); this.setAccountId(anAccountId); this.setExecution(new PurchaseExecution(aQuantityOfSharesOrdered)); this.setOrderId(OrderId.unique()); this.setQuote(aQuote); DomainEventPublisher.instance().publish( new BuyOrderPlaced( this.accountId(), this.orderId(), this.quote(), this.execution().quantityOfSharesOrdered(), this.execution().openDate(), aQuote.price().multipliedBy(aQuantityOfSharesOrdered), anOrderFee)); }