OrphanedPositionRemover { public void run() { final Set<ObjectId> validPositions = getValidPositions(); final Set<UniqueId> orphanedPositions = getOrphanedPositions(validPositions); removePositions(orphanedPositions); } OrphanedPositionRemover(PortfolioMaster portfolioMaster, PositionMaster positionMaster); void run();  }
@Test public void removeOrphanedPosition() { PositionDocument positionDocument = _positionMaster.get(_pos1.getUniqueId()); AssertJUnit.assertNotNull(positionDocument.getPosition()); positionDocument = _positionMaster.get(_pos2.getUniqueId()); AssertJUnit.assertNotNull(positionDocument.getPosition()); positionDocument = _positionMaster.get(_pos3.getUniqueId()); AssertJUnit.assertNotNull(positionDocument.getPosition()); positionDocument = _positionMaster.get(_pos4.getUniqueId()); AssertJUnit.assertNotNull(positionDocument.getPosition()); OrphanedPositionRemover positionRemover = new OrphanedPositionRemover(_portfolioMaster, _positionMaster); positionRemover.run(); positionDocument = _positionMaster.get(_pos1.getUniqueId()); AssertJUnit.assertNotNull(positionDocument.getPosition()); positionDocument = _positionMaster.get(_pos2.getUniqueId()); AssertJUnit.assertNotNull(positionDocument.getPosition()); positionDocument = _positionMaster.get(_pos3.getUniqueId()); AssertJUnit.assertNotNull(positionDocument.getPosition()); try { _positionMaster.get(_pos4.getUniqueId()); AssertJUnit.fail("position 4 should have been removed"); } catch (DataNotFoundException ex) { } }