diff --git a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java index fef2f1a6e..b2581bcc7 100644 --- a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java +++ b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java @@ -370,7 +370,7 @@ public Lot getLot(String lotCode) throws OHServiceException { public List updateLot(List lots) throws OHServiceException { List updatedLots = new ArrayList<>(); for (Lot lot : lots) { - Lot updatedLot = ioOperations.updateLot(lot); + Lot updatedLot = updateLot(lot); updatedLots.add(updatedLot); } return updatedLots; diff --git a/src/test/java/org/isf/medicalstock/Tests.java b/src/test/java/org/isf/medicalstock/Tests.java index 0284b5205..23b03069f 100644 --- a/src/test/java/org/isf/medicalstock/Tests.java +++ b/src/test/java/org/isf/medicalstock/Tests.java @@ -31,6 +31,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Stream; @@ -124,14 +125,14 @@ class Tests extends OHCoreTestCase { static Stream automaticlot() { return Stream.of( - Arguments.of(false, false, false), - Arguments.of(false, false, true), - Arguments.of(false, true, false), - Arguments.of(false, true, true), - Arguments.of(true, false, false), - Arguments.of(true, false, true), - Arguments.of(true, true, false), - Arguments.of(true, true, true)); + Arguments.of(false, false, false), + Arguments.of(false, false, true), + Arguments.of(false, true, false), + Arguments.of(false, true, true), + Arguments.of(true, false, false), + Arguments.of(true, false, true), + Arguments.of(true, true, false), + Arguments.of(true, true, true)); } private static void setGeneralData(boolean in, boolean out, boolean toward) { @@ -273,10 +274,10 @@ void testIoNewAutomaticDischargingMovementLotQuantityLessMovementQuantity(boolea movement.setQuantity(100); medicalStockIoOperation.newAutomaticDischargingMovement(movement); }) - .isInstanceOf(OHServiceException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 1, "Expecting one validation errors")); + .isInstanceOf(OHServiceException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 1, "Expecting one validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -294,14 +295,14 @@ void testIoNewAutomaticDischargingMovementDifferentLots(boolean in, boolean out, Lot lot2 = testLot.setup(medical, false); // we are going to create a second lot lot2.setCode("second"); Movement newMovement = new Movement( - medical, - movementType, - null, - lot2, - TimeTools.getNow(), - 7, // new lot with 10 quantity - supplier, - "newReference"); + medical, + movementType, + null, + lot2, + TimeTools.getNow(), + 7, // new lot with 10 quantity + supplier, + "newReference"); medicalStockIoOperation.newMovement(newMovement); MovementType dischargeMovementType = testMovementType.setup(false); // prepare discharge movement @@ -310,14 +311,14 @@ void testIoNewAutomaticDischargingMovementDifferentLots(boolean in, boolean out, medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(dischargeMovementType); Movement dischargeMovement = new Movement( - medical, - dischargeMovementType, - ward, - null, // automatic lot selection - TimeTools.getNow(), - 15, // quantity of 15 should use first lot of 10 + second lot of 5 - null, - "newReference2"); + medical, + dischargeMovementType, + ward, + null, // automatic lot selection + TimeTools.getNow(), + 15, // quantity of 15 should use first lot of 10 + second lot of 5 + null, + "newReference2"); boolean automaticLotMode = GeneralData.AUTOMATICLOT_OUT; GeneralData.AUTOMATICLOT_OUT = true; medicalStockIoOperation.newAutomaticDischargingMovement(dischargeMovement); @@ -341,14 +342,14 @@ void testIoNewMovementOutGoingLots(boolean in, boolean out, boolean toward) thro Supplier supplier = movement.getSupplier(); Lot lot = movement.getLot(); Movement newMovement = new Movement( - medical, - medicalType, - ward, - lot, - TimeTools.getNow(), - 10, // new lot with 10 quantity - supplier, - "newReference"); + medical, + medicalType, + ward, + lot, + TimeTools.getNow(), + 10, // new lot with 10 quantity + supplier, + "newReference"); Movement storedMovement = medicalStockIoOperation.newMovement(newMovement); Movement foundMovement = movementIoOperationRepository.findById(storedMovement.getCode()).orElse(null); assertThat(foundMovement).isNotNull(); @@ -370,14 +371,14 @@ void testIoNewMovementOutGoingLotsWardNull(boolean in, boolean out, boolean towa Supplier supplier = movement.getSupplier(); Lot lot = movement.getLot(); Movement newMovement = new Movement( - medical, - medicalType, - null, - lot, - TimeTools.getNow(), - 10, // new lot with 10 quantity - supplier, - "newReference"); + medical, + medicalType, + null, + lot, + TimeTools.getNow(), + 10, // new lot with 10 quantity + supplier, + "newReference"); Movement storedMovement = medicalStockIoOperation.newMovement(newMovement); Movement foundMovement = movementIoOperationRepository.findById(storedMovement.getCode()).orElse(null); assertThat(foundMovement).isNotNull(); @@ -423,7 +424,7 @@ void testIoNewMovementUpdateMedicalWardQuantityMedicalWardFound(boolean in, bool MedicalWard medicalWard = new MedicalWard(movement.getWard(), movement.getMedical(), 0, 0, movement.getLot()); medicalStockWardIoOperationRepository.saveAndFlush(medicalWard); Movement newMovement = new Movement(movement.getMedical(), movementType, movement.getWard(), movement.getLot(), - TimeTools.getNow(), 10, movement.getSupplier(), "newReference"); + TimeTools.getNow(), 10, movement.getSupplier(), "newReference"); Movement storedMovement = medicalStockIoOperation.newMovement(newMovement); Movement foundMovement = movementIoOperationRepository.findById(storedMovement.getCode()).orElse(null); assertThat(foundMovement).isNotNull(); @@ -485,9 +486,9 @@ void testIoGetMovementsWithParameters(boolean in, boolean out, boolean toward) t Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); List movements = medicalStockIoOperation.getMovements( - foundMovement.getWard().getCode(), - fromDate, - toDate); + foundMovement.getWard().getCode(), + fromDate, + toDate); assertThat(movements.get(0).getCode()).isEqualTo(foundMovement.getCode()); } @@ -501,16 +502,16 @@ void testIoGetMovementsWihAllParameters(boolean in, boolean out, boolean toward) Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); List movements = medicalStockIoOperation.getMovements( - foundMovement.getMedical().getCode(), - foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), - foundMovement.getType().getCode(), - fromDate, - toDate, - fromDate, - toDate, - fromDate, - toDate); + foundMovement.getMedical().getCode(), + foundMovement.getMedical().getType().getCode(), + foundMovement.getWard().getCode(), + foundMovement.getType().getCode(), + fromDate, + toDate, + fromDate, + toDate, + fromDate, + toDate); assertThat(movements.get(0).getCode()).isEqualTo(foundMovement.getCode()); } @@ -525,14 +526,14 @@ void testIoGetMovementForPrintDateOrder(boolean in, boolean out, boolean toward) Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); List movements = medicalStockIoOperation.getMovementForPrint( - foundMovement.getMedical().getDescription(), - foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), - foundMovement.getType().getCode(), - fromDate, - toDate, - foundMovement.getLot().getCode(), - order); + foundMovement.getMedical().getDescription(), + foundMovement.getMedical().getType().getCode(), + foundMovement.getWard().getCode(), + foundMovement.getType().getCode(), + fromDate, + toDate, + foundMovement.getLot().getCode(), + order); assertThat(movements.get(0).getCode()).isEqualTo(foundMovement.getCode()); } @@ -547,14 +548,14 @@ void testIoGetMovementForPrintWardOrderateWard(boolean in, boolean out, boolean Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); List movements = medicalStockIoOperation.getMovementForPrint( - foundMovement.getMedical().getDescription(), - foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), - foundMovement.getType().getCode(), - fromDate, - toDate, - foundMovement.getLot().getCode(), - order); + foundMovement.getMedical().getDescription(), + foundMovement.getMedical().getType().getCode(), + foundMovement.getWard().getCode(), + foundMovement.getType().getCode(), + fromDate, + toDate, + foundMovement.getLot().getCode(), + order); assertThat(movements.get(0).getCode()).isEqualTo(foundMovement.getCode()); } @@ -569,14 +570,14 @@ void testIoGetMovementForPrintPharmaceuticalTypeOrder(boolean in, boolean out, b Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); List movements = medicalStockIoOperation.getMovementForPrint( - foundMovement.getMedical().getDescription(), - foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), - foundMovement.getType().getCode(), - fromDate, - toDate, - foundMovement.getLot().getCode(), - order); + foundMovement.getMedical().getDescription(), + foundMovement.getMedical().getType().getCode(), + foundMovement.getWard().getCode(), + foundMovement.getType().getCode(), + fromDate, + toDate, + foundMovement.getLot().getCode(), + order); assertThat(movements.get(0).getCode()).isEqualTo(foundMovement.getCode()); } @@ -591,14 +592,14 @@ void testIoGetMovementForPrintTypeOrder(boolean in, boolean out, boolean toward) Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); List movements = medicalStockIoOperation.getMovementForPrint( - foundMovement.getMedical().getDescription(), - foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), - foundMovement.getType().getCode(), - fromDate, - toDate, - foundMovement.getLot().getCode(), - order); + foundMovement.getMedical().getDescription(), + foundMovement.getMedical().getType().getCode(), + foundMovement.getWard().getCode(), + foundMovement.getType().getCode(), + fromDate, + toDate, + foundMovement.getLot().getCode(), + order); assertThat(movements.get(0).getCode()).isEqualTo(foundMovement.getCode()); } @@ -681,7 +682,7 @@ void testMgrGetMovementsWihAllParameters(boolean in, boolean out, boolean toward Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); List movements = movBrowserManager.getMovements(foundMovement.getMedical().getCode(), foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), foundMovement.getType().getCode(), fromDate, toDate, fromDate, toDate, fromDate, toDate); + foundMovement.getWard().getCode(), foundMovement.getType().getCode(), fromDate, toDate, fromDate, toDate, fromDate, toDate); assertThat(movements.get(0).getCode()).isEqualTo(foundMovement.getCode()); } @@ -695,12 +696,12 @@ void testMgrGetMovementsCheckMovParameters() { Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); movBrowserManager.getMovements(foundMovement.getMedical().getCode(), foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), foundMovement.getType().getCode(), fromDate, null, fromDate, toDate, fromDate, toDate); + foundMovement.getWard().getCode(), foundMovement.getType().getCode(), fromDate, null, fromDate, toDate, fromDate, toDate); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 1, "Expecting single validation error")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 1, "Expecting single validation error")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -713,12 +714,12 @@ void testMgrGetMovementsCheckLotPrepParameters() { Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); movBrowserManager.getMovements(foundMovement.getMedical().getCode(), foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), foundMovement.getType().getCode(), fromDate, toDate, null, toDate, fromDate, toDate); + foundMovement.getWard().getCode(), foundMovement.getType().getCode(), fromDate, toDate, null, toDate, fromDate, toDate); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 1, "Expecting single validation error")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 1, "Expecting single validation error")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -731,12 +732,12 @@ void testMgrGetMovementsCheckLotDueParameters() { Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); movBrowserManager.getMovements(foundMovement.getMedical().getCode(), foundMovement.getMedical().getType().getCode(), - foundMovement.getWard().getCode(), foundMovement.getType().getCode(), fromDate, toDate, fromDate, toDate, fromDate, null); + foundMovement.getWard().getCode(), foundMovement.getType().getCode(), fromDate, toDate, fromDate, toDate, fromDate, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 1, "Expecting single validation error")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 1, "Expecting single validation error")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -747,7 +748,7 @@ void testMgrGetMovementsWihAllParametersNull(boolean in, boolean out, boolean to Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null); assertThat(foundMovement).isNotNull(); List movements = movBrowserManager.getMovements(null, null, foundMovement.getWard().getCode(), null, - null, null, null, null, null, null); + null, null, null, null, null, null); assertThat(movements.get(0).getCode()).isEqualTo(foundMovement.getCode()); } @@ -762,7 +763,7 @@ void testMgrGetLotsByMedical(boolean in, boolean out, boolean toward) throws Exc assertThat(lots).hasSize(1); assertThat(lots.get(0).getCode()).isEqualTo(foundMovement.getLot().getCode()); } - + @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @MethodSource("automaticlot") void testMgrGetLotsByMedicalWithEmptyLot(boolean in, boolean out, boolean toward) throws Exception { @@ -782,6 +783,26 @@ void testMgrGetLotsByMedicalNull(boolean in, boolean out, boolean toward) throws assertThat(movStockInsertingManager.getLotByMedical(null, true)).isEmpty(); } + @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") + @MethodSource("automaticlot") + public void testMgrUpdateLots() throws Exception { + String code1 = setupTestLot(false); + Lot lot1 = lotIoOperationRepository.findById(code1).orElse(null); + + String code2 = setupTestLot(false); + Lot lot2 = lotIoOperationRepository.findById(code2).orElse(null); + String newCode = "456789"; + lot2.setCode(newCode); + + List lots = Arrays.asList(lot1, lot2); + List updatedLots = movStockInsertingManager.updateLot(lots); + + // Assert the size and content of the updated list + assertThat(updatedLots.size()).isEqualTo(2); + assertThat(updatedLots).contains(lot1); + assertThat(updatedLots).contains(lot2); + } + @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @MethodSource("automaticlot") void testMgrAlertCriticalQuantityUnderLimit(boolean in, boolean out, boolean toward) throws Exception { @@ -848,10 +869,10 @@ void testMgrPrepareChargingMovementBadRefNumber() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHDataValidationException) e).getMessages().size() == 2, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHDataValidationException) e).getMessages().size() == 2, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -879,10 +900,10 @@ void testMgrPrepareDischargingMovementBadRefNumber() { movements.add(movement); movStockInsertingManager.newMultipleDischargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -924,10 +945,10 @@ void testMgrValidateMovementMoveDateAfterToday() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, "refNo"); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -943,10 +964,10 @@ void testMgrValidateMovementDateBeforeLastDate() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, "refNo"); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -960,10 +981,10 @@ void testMgrValidateReferenceNumber() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -979,10 +1000,10 @@ void testMgrValidateNullSupplier() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 3, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 3, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -998,7 +1019,7 @@ void testMgrValidateNullWard() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class); + .isInstanceOf(OHDataValidationException.class); // NB: number of messages not checked because it varies dependent on GeneralData values } @@ -1014,10 +1035,10 @@ void testMgrValidateQuantityZero() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 3, "Expecting three validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 3, "Expecting three validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -1032,10 +1053,10 @@ void testMgrValidateNullMedical() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors: ")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors: ")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -1050,10 +1071,10 @@ void testMgrValidateNullMovementType() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -1068,10 +1089,10 @@ void testMgrValidateLotRefersToAnotherMedical() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHServiceException) e).getMessages().size() == 2, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -1091,7 +1112,7 @@ void testMgrValidateLotWithCostZero() { movStockInsertingManager.newMultipleChargingMovements(movements, null); GeneralData.LOTWITHCOST = lotWithCost; }) - .isInstanceOf(OHDataValidationException.class); + .isInstanceOf(OHDataValidationException.class); // NB: number of messages not checked because it varies dependent on GeneralData values } @@ -1108,10 +1129,10 @@ void testMgrValidateLotCodeTooLong() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class) - .has( - new Condition( - e -> ((OHDataValidationException) e).getMessages().size() == 2, "Expecting two validation errors")); + .isInstanceOf(OHDataValidationException.class) + .has( + new Condition( + e -> ((OHDataValidationException) e).getMessages().size() == 2, "Expecting two validation errors")); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -1127,7 +1148,7 @@ void testMgrValidateLotDueDateNull() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class); + .isInstanceOf(OHDataValidationException.class); // NB: number of messages not checked because it varies dependent on GeneralData values } @@ -1144,7 +1165,7 @@ void testMgrValidateLotPrepationDateNull() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class); + .isInstanceOf(OHDataValidationException.class); // NB: number of messages not checked because it varies dependent on GeneralData values } @@ -1162,7 +1183,7 @@ void testMgrValidateLotPreparationDateAfterDueDate() { movements.add(movement); movStockInsertingManager.newMultipleChargingMovements(movements, null); }) - .isInstanceOf(OHDataValidationException.class); + .isInstanceOf(OHDataValidationException.class); // NB: number of messages not checked because it varies dependent on GeneralData values } @@ -1199,9 +1220,9 @@ void testLotEquals(boolean in, boolean out, boolean toward) throws Exception { String code = setupTestLot(true); Lot lot = lotIoOperationRepository.findById(code).orElse(null); assertThat(lot) - .isEqualTo(lot) - .isNotNull() - .isNotEqualTo("someString"); + .isEqualTo(lot) + .isNotNull() + .isNotEqualTo("someString"); Lot lot2 = new Lot(null); assertThat(lot).isNotEqualTo(lot2); @@ -1264,9 +1285,9 @@ void testMovementEquals(boolean in, boolean out, boolean toward) throws Exceptio int code = setupTestMovement(false); Movement movement = movementIoOperationRepository.findById(code).orElse(null); assertThat(movement) - .isEqualTo(movement) - .isNotNull() - .isNotEqualTo("someString"); + .isEqualTo(movement) + .isNotNull() + .isNotEqualTo("someString"); Movement movement2 = new Movement(); movement2.setCode(-99); @@ -1324,14 +1345,14 @@ void testDeleteLastMovementDenied(boolean in, boolean out, boolean toward) throw Ward ward = movement.getWard(); Lot lot = movement.getLot(); Movement newMovement = new Movement( - medical, - medicalType, - ward, - lot, - TimeTools.getDateToday0(), - 10, - null, - "newReference"); + medical, + medicalType, + ward, + lot, + TimeTools.getDateToday0(), + 10, + null, + "newReference"); Movement storedMovement = medicalStockIoOperation.newMovement(newMovement); MovementWard movementWard = new MovementWard(TimeTools.getNow(), ward, lot, "newDescription", medical, 10.0, "newUnits"); MovementWard saveMovWard = movementWardIoOperationRepository.saveAndFlush(movementWard); @@ -1342,7 +1363,7 @@ void testDeleteLastMovementDenied(boolean in, boolean out, boolean toward) throw assertThat(lastMovement.getType().getType()).isEqualTo("-"); assertThat(lastMovement.getMedical()).isEqualTo(foundMovWard.getMedical()); List movWards = movementWardIoOperationRepository.findByWardMedicalAndLotAfterOrSameDate(ward.getCode(), medical.getCode(), lot.getCode(), - storedMovement.getDate()); + storedMovement.getDate()); assertThat(movWards).hasSizeGreaterThan(0); assertThrows(OHServiceException.class, () -> movBrowserManager.deleteLastMovement(lastMovement)); } @@ -1361,14 +1382,14 @@ void testDeleteLastMovementWithPriorMovements(boolean in, boolean out, boolean t Ward ward = movement.getWard(); Lot lot = movement.getLot(); Movement newMovement = new Movement( - medical, - medicalType, - ward, - lot, - TimeTools.getDateToday0(), - 10, - null, - "newReference"); + medical, + medicalType, + ward, + lot, + TimeTools.getDateToday0(), + 10, + null, + "newReference"); Movement storedMovement = medicalStockIoOperation.newMovement(newMovement); MovementWard movementWard = new MovementWard(TimeTools.getDateToday0(), ward, lot, "newDescription", medical, 10.0, "newUnits"); MovementWard saveMovWard = movementWardIoOperationRepository.saveAndFlush(movementWard); @@ -1379,28 +1400,28 @@ void testDeleteLastMovementWithPriorMovements(boolean in, boolean out, boolean t assertThat(lastMovement.getType().getType()).isEqualTo("-"); assertThat(lastMovement.getMedical()).isEqualTo(foundMovWard.getMedical()); List movWards = movementWardIoOperationRepository.findByWardMedicalAndLotAfterOrSameDate(ward.getCode(), medical.getCode(), lot.getCode(), - storedMovement.getDate()); + storedMovement.getDate()); assertThat(movWards).hasSizeGreaterThan(0); assertThrows(OHServiceException.class, () -> movBrowserManager.deleteLastMovement(lastMovement)); Movement newMovement2 = new Movement( - medical, - medicalType, - ward, - lot, - TimeTools.getNow(), - 10, - null, - "newReference2"); + medical, + medicalType, + ward, + lot, + TimeTools.getNow(), + 10, + null, + "newReference2"); Movement storedMovement2 = medicalStockIoOperation.newMovement(newMovement2); int code2 = storedMovement2.getCode(); Optional followingMovement = movementIoOperationRepository.findById(code2); assertThat(followingMovement).isPresent(); Movement movement2 = followingMovement.get(); movWards = movementWardIoOperationRepository.findByWardMedicalAndLotAfterOrSameDate(movement2.getWard().getCode(), - movement2.getMedical().getCode(), - movement2.getLot().getCode(), - movement2.getDate()); + movement2.getMedical().getCode(), + movement2.getLot().getCode(), + movement2.getDate()); assertThat(movWards).isEmpty(); movBrowserManager.deleteLastMovement(movement2); Optional followingMovement2 = movementIoOperationRepository.findById(code2); @@ -1419,14 +1440,14 @@ void testIoUpdateMedicalStockTableSameDate() throws Exception { int remainQuantity = quantity - quantity / 2; // to overcome tests with not even quantities MedicalStockIoOperations medicalStockIoOperation = new MedicalStockIoOperations(movementIoOperationRepository, lotIoOperationRepository, - medicalsIoOperationRepository, medicalStockIoOperationRepository, medicalStockWardIoOperationRepository); + medicalsIoOperationRepository, medicalStockIoOperationRepository, medicalStockWardIoOperationRepository); Method method = medicalStockIoOperation.getClass().getDeclaredMethod("updateMedicalStockTable", Medical.class, LocalDate.class, int.class); method.setAccessible(true); assertThat((MedicalStock) method.invoke(medicalStockIoOperation, medical, dateTime.toLocalDate(), -quantity / 2)).extracting("balance") - .isEqualTo(remainQuantity); + .isEqualTo(remainQuantity); assertThat((MedicalStock) method.invoke(medicalStockIoOperation, medical, dateTime.toLocalDate(), -remainQuantity)).extracting("balance") - .isEqualTo(0); + .isEqualTo(0); } @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") @@ -1439,7 +1460,7 @@ void testIoUpdateMedicalStockTableDifferentDate() throws Exception { int quantity = movement.getQuantity(); MedicalStockIoOperations medicalStockIoOperation = new MedicalStockIoOperations(movementIoOperationRepository, lotIoOperationRepository, - medicalsIoOperationRepository, medicalStockIoOperationRepository, medicalStockWardIoOperationRepository); + medicalsIoOperationRepository, medicalStockIoOperationRepository, medicalStockWardIoOperationRepository); Method method = medicalStockIoOperation.getClass().getDeclaredMethod("updateMedicalStockTable", Medical.class, LocalDate.class, int.class); method.setAccessible(true); @@ -1469,7 +1490,7 @@ void testIoUpdateMedicalStockTableEmptyTable() throws Exception { int quantity = 10; MedicalStockIoOperations medicalStockIoOperation = new MedicalStockIoOperations(movementIoOperationRepository, lotIoOperationRepository, - medicalsIoOperationRepository, medicalStockIoOperationRepository, medicalStockWardIoOperationRepository); + medicalsIoOperationRepository, medicalStockIoOperationRepository, medicalStockWardIoOperationRepository); Method method = medicalStockIoOperation.getClass().getDeclaredMethod("updateMedicalStockTable", Medical.class, LocalDate.class, int.class); method.setAccessible(true); @@ -1489,7 +1510,7 @@ void testIoUpdateMedicalStockTableEmptyTableWithNegativeQuantity() throws Except int quantity = -10; MedicalStockIoOperations medicalStockIoOperation = new MedicalStockIoOperations(movementIoOperationRepository, lotIoOperationRepository, - medicalsIoOperationRepository, medicalStockIoOperationRepository, medicalStockWardIoOperationRepository); + medicalsIoOperationRepository, medicalStockIoOperationRepository, medicalStockWardIoOperationRepository); Method method = medicalStockIoOperation.getClass().getDeclaredMethod("updateMedicalStockTable", Medical.class, LocalDate.class, int.class); method.setAccessible(true); @@ -1503,7 +1524,7 @@ void testIoUpdateMedicalStockTableEmptyTableWithNegativeQuantity() throws Except } } }) - .isInstanceOf(OHServiceException.class); + .isInstanceOf(OHServiceException.class); } private String setupTestLot(boolean usingSet) throws OHException {