StockMovementRepository { public StockMovementItem getFirstStockMovement() throws LMISException { return dbUtil.withDao(StockMovementItem.class, dao -> dao.queryBuilder() .orderBy("movementDate", true) .orderBy("createdTime", true) .queryForFirst()); } @Inject  StockMovementRepository(Context context); List<StockMovementItem> listUnSynced(); void batchCreateStockMovementItemAndLotItems(final StockMovementItem stockMovementItem); void batchCreateOrUpdateStockMovementsAndLotMovements(final List<StockMovementItem> stockMovementItems); StockMovementItem getFirstStockMovement(); List<String> queryStockMovementDatesByProgram(final String programCode); Date queryEarliestStockMovementDateByProgram(final String programCode); StockMovementItem queryFirstStockMovementByStockCardId(final long stockCardId); List<StockMovementItem> queryStockMovementHistory(final long stockCardId, final long startIndex, final long maxRows); List<StockMovementItem> queryStockItemsByCreatedDate(final long stockCardId, final Date periodBeginDate, final Date periodEndDate); List<StockMovementItem> queryStockMovementsByMovementDate(final long stockCardId, final Date startDate, final Date endDate); List<StockMovementItem> listLastFiveStockMovements(final long stockCardId); List<StockMovementItem> listLastTwoStockMovements(final long stockCardId); List<StockMovementItem> queryMovementByStockCardId(final long stockCardId); List<StockMovementItem> queryEachStockCardNewestMovement(); void deleteStockMovementItems(final StockCard stockCard);  }
@Test public void shouldGetFirstMovement() throws Exception { StockCard stockCard = saveStockCardWithOneMovement(stockRepository, productRepository); StockCard stockCard2 = saveStockCardWithOneMovement(stockRepository, productRepository); createMovementItem(ISSUE, 100, stockCard, new DateTime("2017-01-01").toDate(), new DateTime("2017-01-01").toDate(), false); createMovementItem(ISSUE, 100, stockCard2, new DateTime("2016-01-01").toDate(), new DateTime("2016-01-01").toDate(), false); createMovementItem(ISSUE, 100, stockCard2, new DateTime("2018-03-02").toDate(), new DateTime("2018-03-02").toDate(), false); StockMovementItem stockMovementItem = stockMovementRepository.getFirstStockMovement(); assertTrue(stockMovementItem.getMovementDate().before(new DateTime("2016-01-01").toDate())); }