@Test public void shouldGenerateRnrFormItemWithCorrectAttributes() throws Exception { int stockExistence = 100; int issueQuantity = 10; int receiveQuantity = 20; int positiveQuantity = 30; int negativeQuantity = 40; Program program = new Program("mmia", "mmia", null, false, null, null); ArrayList<StockMovementItem> stockMovementItems = new ArrayList<>(); StockMovementItemBuilder stockMovementItemBuilder = new StockMovementItemBuilder(); StockMovementItem inventoryItem = stockMovementItemBuilder .withDocumentNo("1") .withMovementReason("reason") .withMovementDate("10/10/2015") .withMovementType(MovementReasonManager.MovementType.PHYSICAL_INVENTORY) .withStockOnHand(stockExistence) .build(); StockMovementItem issueItem = stockMovementItemBuilder .withDocumentNo("1") .withMovementReason("reason") .withMovementDate("10/10/2015") .withMovementType(MovementReasonManager.MovementType.ISSUE) .withQuantity(issueQuantity) .build(); StockMovementItem receiveItem = stockMovementItemBuilder .withDocumentNo("1") .withMovementReason("reason") .withMovementDate("10/11/2015") .withMovementType(MovementReasonManager.MovementType.RECEIVE) .withQuantity(receiveQuantity) .build(); StockMovementItem positiveItem = stockMovementItemBuilder .withDocumentNo("1") .withMovementReason("reason") .withMovementDate("10/12/2015") .withMovementType(MovementReasonManager.MovementType.POSITIVE_ADJUST) .withQuantity(positiveQuantity) .build(); StockMovementItem negativeItem = stockMovementItemBuilder .withDocumentNo("1") .withMovementReason("reason") .withMovementDate("10/12/2015") .withMovementType(MovementReasonManager.MovementType.NEGATIVE_ADJUST) .withQuantity(negativeQuantity) .build(); stockMovementItems.add(inventoryItem); stockMovementItems.add(issueItem); stockMovementItems.add(receiveItem); stockMovementItems.add(positiveItem); stockMovementItems.add(negativeItem); ArrayList<StockCard> stockCards = new ArrayList<>(); Product product = new Product(); product.setCode("01A01"); StockCard stockCard = new StockCardBuilder() .setCreateDate(new Date()) .setProduct(product) .build(); stockCard.setCreatedAt(DateUtil.parseString("10/10/2015", DateUtil.SIMPLE_DATE_FORMAT)); stockCards.add(stockCard); RnRForm form = new RnRForm(); form.setPeriodBegin(DateUtil.parseString("9/21/2015", DateUtil.SIMPLE_DATE_FORMAT)); form.setPeriodEnd(DateUtil.parseString("10/20/2015", DateUtil.SIMPLE_DATE_FORMAT)); form.setProgram(program); DateTime dateTime = new DateTime(); dateTime.millisOfDay(); StockMovementItem stockMovementItem = new StockMovementItem(); stockMovementItem.setMovementDate(dateTime.toDate()); stockMovementItem.setCreatedTime(new Date()); when(mockStockMovementRepository.queryFirstStockMovementByStockCardId(anyLong())).thenReturn(stockMovementItem); when(mockStockMovementRepository.queryStockItemsByCreatedDate(stockCard.getId(), form.getPeriodBegin(), form.getPeriodEnd())).thenReturn(stockMovementItems); ProductProgram productProgram = new ProductProgram(); productProgram.setCategory("Adult"); when(mockProductProgramRepository.queryByCode(anyString(), anyList())).thenReturn(productProgram); when(mockProgramRepository.queryProgramCodesByProgramCodeOrParentCode(anyString())).thenReturn(new ArrayList<String>()); when(mockProgramRepository.queryByCode(anyString())).thenReturn(program); List<RnrFormItem> rnrFormItemList = rnrFormRepository.generateRnrFormItems(form, stockCards); RnrFormItem rnrFormItem = rnrFormItemList.get(0); int expectAdjustment = positiveQuantity - negativeQuantity; int expectInventoryQuantity = stockExistence + receiveQuantity + positiveQuantity - issueQuantity - negativeQuantity; int expectOrderQuantity = 2 * issueQuantity - expectInventoryQuantity; expectOrderQuantity = expectOrderQuantity > 0 ? expectOrderQuantity : 0; assertThat(rnrFormItem.getProduct(), is(product)); assertThat(rnrFormItem.getCategory(), is("Adult")); assertEquals(stockExistence, rnrFormItem.getInitialAmount().longValue()); assertEquals(issueQuantity, rnrFormItem.getIssued().longValue()); assertEquals(receiveQuantity, rnrFormItem.getReceived()); assertEquals(expectAdjustment, rnrFormItem.getAdjustment().longValue()); assertEquals(expectInventoryQuantity, rnrFormItem.getInventory().longValue()); assertEquals(expectOrderQuantity, rnrFormItem.getCalculatedOrderQuantity().longValue()); }
public List<RnrFormItem> generateRnrFormItems(final RnRForm form, List<StockCard> stockCards) throws LMISException { List<RnrFormItem> rnrFormItems = new ArrayList<>(); List<String> programCodes = programRepository.queryProgramCodesByProgramCodeOrParentCode(form.getProgram().getProgramCode()); rnRForms = listInclude(RnRForm.Emergency.No, programCode); if (rnRForms.size() > 1) { rnrFormItemListWrapper = rnRForms.get(rnRForms.size() - 2).getRnrFormItemListWrapper(); } for (StockCard stockCard : stockCards) { RnrFormItem rnrFormItem = createRnrFormItemByPeriod(stockCard, form.getPeriodBegin(), form.getPeriodEnd()); rnrFormItem.setForm(form); rnrFormItems.add(rnrFormItem); rnrFormItem.setCategory(productProgramRepository.queryByCode(rnrFormItem.getProduct().getCode(), programCodes).getCategory()); } return rnrFormItems; }
RnrFormRepository { public List<RnrFormItem> generateRnrFormItems(final RnRForm form, List<StockCard> stockCards) throws LMISException { List<RnrFormItem> rnrFormItems = new ArrayList<>(); List<String> programCodes = programRepository.queryProgramCodesByProgramCodeOrParentCode(form.getProgram().getProgramCode()); rnRForms = listInclude(RnRForm.Emergency.No, programCode); if (rnRForms.size() > 1) { rnrFormItemListWrapper = rnRForms.get(rnRForms.size() - 2).getRnrFormItemListWrapper(); } for (StockCard stockCard : stockCards) { RnrFormItem rnrFormItem = createRnrFormItemByPeriod(stockCard, form.getPeriodBegin(), form.getPeriodEnd()); rnrFormItem.setForm(form); rnrFormItems.add(rnrFormItem); rnrFormItem.setCategory(productProgramRepository.queryByCode(rnrFormItem.getProduct().getCode(), programCodes).getCategory()); } return rnrFormItems; } }
RnrFormRepository { public List<RnrFormItem> generateRnrFormItems(final RnRForm form, List<StockCard> stockCards) throws LMISException { List<RnrFormItem> rnrFormItems = new ArrayList<>(); List<String> programCodes = programRepository.queryProgramCodesByProgramCodeOrParentCode(form.getProgram().getProgramCode()); rnRForms = listInclude(RnRForm.Emergency.No, programCode); if (rnRForms.size() > 1) { rnrFormItemListWrapper = rnRForms.get(rnRForms.size() - 2).getRnrFormItemListWrapper(); } for (StockCard stockCard : stockCards) { RnrFormItem rnrFormItem = createRnrFormItemByPeriod(stockCard, form.getPeriodBegin(), form.getPeriodEnd()); rnrFormItem.setForm(form); rnrFormItems.add(rnrFormItem); rnrFormItem.setCategory(productProgramRepository.queryByCode(rnrFormItem.getProduct().getCode(), programCodes).getCategory()); } return rnrFormItems; } @Inject  RnrFormRepository(Context context); }
RnrFormRepository { public List<RnrFormItem> generateRnrFormItems(final RnRForm form, List<StockCard> stockCards) throws LMISException { List<RnrFormItem> rnrFormItems = new ArrayList<>(); List<String> programCodes = programRepository.queryProgramCodesByProgramCodeOrParentCode(form.getProgram().getProgramCode()); rnRForms = listInclude(RnRForm.Emergency.No, programCode); if (rnRForms.size() > 1) { rnrFormItemListWrapper = rnRForms.get(rnRForms.size() - 2).getRnrFormItemListWrapper(); } for (StockCard stockCard : stockCards) { RnrFormItem rnrFormItem = createRnrFormItemByPeriod(stockCard, form.getPeriodBegin(), form.getPeriodEnd()); rnrFormItem.setForm(form); rnrFormItems.add(rnrFormItem); rnrFormItem.setCategory(productProgramRepository.queryByCode(rnrFormItem.getProduct().getCode(), programCodes).getCategory()); } return rnrFormItems; } @Inject  RnrFormRepository(Context context); RnRForm initNormalRnrForm(Date periodEndDate); RnRForm initEmergencyRnrForm(Date periodEndDate, List<StockCard> stockCards); void create(RnRForm rnRForm); void createRnRsWithItems(final List<RnRForm> forms); void createOrUpdateWithItems(final RnRForm form); boolean isPeriodUnique(final RnRForm form); List<RnRForm> list(); List<RnRForm> listInclude(RnRForm.Emergency includeEmergency, String programCode); List<RnRForm> listInclude(RnRForm.Emergency includeEmergency, String programCode, ReportTypeForm reportTypeForm); List<RnRForm> queryAllUnsyncedForms(); RnRForm queryUnAuthorized(); RnRForm queryRnRForm(final long id); List<RnrFormItem> generateRnrFormItems(final RnRForm form, List<StockCard> stockCards); void removeRnrForm(RnRForm form); boolean hasRequisitionData(); boolean hasOldDate(); List<RnRForm> listNotSynchronizedFromReportStartTime(String programCode); void createAndRefresh(RnRForm rnRForm); void deleteOldData(); void deleteRnrFormDirtyData(List<String> productCodeList); }
RnrFormRepository { public List<RnrFormItem> generateRnrFormItems(final RnRForm form, List<StockCard> stockCards) throws LMISException { List<RnrFormItem> rnrFormItems = new ArrayList<>(); List<String> programCodes = programRepository.queryProgramCodesByProgramCodeOrParentCode(form.getProgram().getProgramCode()); rnRForms = listInclude(RnRForm.Emergency.No, programCode); if (rnRForms.size() > 1) { rnrFormItemListWrapper = rnRForms.get(rnRForms.size() - 2).getRnrFormItemListWrapper(); } for (StockCard stockCard : stockCards) { RnrFormItem rnrFormItem = createRnrFormItemByPeriod(stockCard, form.getPeriodBegin(), form.getPeriodEnd()); rnrFormItem.setForm(form); rnrFormItems.add(rnrFormItem); rnrFormItem.setCategory(productProgramRepository.queryByCode(rnrFormItem.getProduct().getCode(), programCodes).getCategory()); } return rnrFormItems; } @Inject  RnrFormRepository(Context context); RnRForm initNormalRnrForm(Date periodEndDate); RnRForm initEmergencyRnrForm(Date periodEndDate, List<StockCard> stockCards); void create(RnRForm rnRForm); void createRnRsWithItems(final List<RnRForm> forms); void createOrUpdateWithItems(final RnRForm form); boolean isPeriodUnique(final RnRForm form); List<RnRForm> list(); List<RnRForm> listInclude(RnRForm.Emergency includeEmergency, String programCode); List<RnRForm> listInclude(RnRForm.Emergency includeEmergency, String programCode, ReportTypeForm reportTypeForm); List<RnRForm> queryAllUnsyncedForms(); RnRForm queryUnAuthorized(); RnRForm queryRnRForm(final long id); List<RnrFormItem> generateRnrFormItems(final RnRForm form, List<StockCard> stockCards); void removeRnrForm(RnRForm form); boolean hasRequisitionData(); boolean hasOldDate(); List<RnRForm> listNotSynchronizedFromReportStartTime(String programCode); void createAndRefresh(RnRForm rnRForm); void deleteOldData(); void deleteRnrFormDirtyData(List<String> productCodeList); @Inject
    public StockMovementRepository stockMovementRepository; }