@Test public void shouldCreateNonExistingLot() { when(lotRepository.getLotOnHandByStockCardAndLotObject(stockCardId, lot)).thenReturn(null); when(lotRepository.getOrCreateLot(lot)).thenReturn(createdLot); LotOnHand lotOnHand = service.getOrCreateLotOnHand(lot, dummyCard); assertEquals(lotOnHand.getQuantityOnHand(), expectedLotOnHand.getQuantityOnHand()); assertEquals(lotOnHand.getLot().getLotCode(), expectedLotOnHand.getLot().getLotCode()); }
@Transactional public LotOnHand getOrCreateLotOnHand(Lot lot, StockCard stockCard) { LotOnHand lotOnHand = lotRepository.getLotOnHandByStockCardAndLotObject(stockCard.getId(), lot); if (null == lotOnHand) { Lot l = lotRepository.getOrCreateLot(lot); lotOnHand = LotOnHand.createZeroedLotOnHand(l, stockCard); lotRepository.saveLotOnHand(lotOnHand); } Objects.requireNonNull(lotOnHand); return lotOnHand; }
StockCardService { @Transactional public LotOnHand getOrCreateLotOnHand(Lot lot, StockCard stockCard) { LotOnHand lotOnHand = lotRepository.getLotOnHandByStockCardAndLotObject(stockCard.getId(), lot); if (null == lotOnHand) { Lot l = lotRepository.getOrCreateLot(lot); lotOnHand = LotOnHand.createZeroedLotOnHand(l, stockCard); lotRepository.saveLotOnHand(lotOnHand); } Objects.requireNonNull(lotOnHand); return lotOnHand; } }
StockCardService { @Transactional public LotOnHand getOrCreateLotOnHand(Lot lot, StockCard stockCard) { LotOnHand lotOnHand = lotRepository.getLotOnHandByStockCardAndLotObject(stockCard.getId(), lot); if (null == lotOnHand) { Lot l = lotRepository.getOrCreateLot(lot); lotOnHand = LotOnHand.createZeroedLotOnHand(l, stockCard); lotRepository.saveLotOnHand(lotOnHand); } Objects.requireNonNull(lotOnHand); return lotOnHand; } StockCardService(FacilityService facilityService,
                   ProductRepository productRepository,
                   LotRepository lotRepository,
                   StockCardRepository repository); }
StockCardService { @Transactional public LotOnHand getOrCreateLotOnHand(Lot lot, StockCard stockCard) { LotOnHand lotOnHand = lotRepository.getLotOnHandByStockCardAndLotObject(stockCard.getId(), lot); if (null == lotOnHand) { Lot l = lotRepository.getOrCreateLot(lot); lotOnHand = LotOnHand.createZeroedLotOnHand(l, stockCard); lotRepository.saveLotOnHand(lotOnHand); } Objects.requireNonNull(lotOnHand); return lotOnHand; } StockCardService(FacilityService facilityService,
                   ProductRepository productRepository,
                   LotRepository lotRepository,
                   StockCardRepository repository); @Transactional LotOnHand getOrCreateLotOnHand(Lot lot, StockCard stockCard); LotOnHand getLotOnHand(Long lotId, Lot lotObj, String productCode, StockCard card, StringBuilder str); StockCard getOrCreateStockCard(Long facilityId, String productCode); StockCard getStockCardById(Long facilityId, Long stockCardId); List<StockCard> getStockCards(Long facilityId); @Transactional void addStockCardEntry(StockCardEntry entry); @Transactional void addStockCardEntries(List<StockCardEntry> entries); }
StockCardService { @Transactional public LotOnHand getOrCreateLotOnHand(Lot lot, StockCard stockCard) { LotOnHand lotOnHand = lotRepository.getLotOnHandByStockCardAndLotObject(stockCard.getId(), lot); if (null == lotOnHand) { Lot l = lotRepository.getOrCreateLot(lot); lotOnHand = LotOnHand.createZeroedLotOnHand(l, stockCard); lotRepository.saveLotOnHand(lotOnHand); } Objects.requireNonNull(lotOnHand); return lotOnHand; } StockCardService(FacilityService facilityService,
                   ProductRepository productRepository,
                   LotRepository lotRepository,
                   StockCardRepository repository); @Transactional LotOnHand getOrCreateLotOnHand(Lot lot, StockCard stockCard); LotOnHand getLotOnHand(Long lotId, Lot lotObj, String productCode, StockCard card, StringBuilder str); StockCard getOrCreateStockCard(Long facilityId, String productCode); StockCard getStockCardById(Long facilityId, Long stockCardId); List<StockCard> getStockCards(Long facilityId); @Transactional void addStockCardEntry(StockCardEntry entry); @Transactional void addStockCardEntries(List<StockCardEntry> entries);  }