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 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 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 } }