@Test public void testValidatePlantPageDataWithTwoProjectsAndTwoArticlesToFalse() { Integer wantedToPlantB = 12; Integer wantedToPlantA = 15; Integer treesRemaining = 10; PlantBag plantBag = plantBagBuilder.initializeProjectDataAndAddToPlantBag("Project A").initializeProjectDataAndAddToPlantBag("Project B") .createPlantItemAndAddToPlantBag(15, 100, "wood", "Project A").createPlantItemAndAddToPlantBag(5, 100, "doow", "Project B").createPlantItemAndAddToPlantBag(6, 100, "wood", "Project B") .createPlantItemAndAddToPlantBag(wantedToPlantB, 100, "doow", "Project B").build(); try { _plantBagValidator.validatePlantBag(plantBag); } catch (IpatException e) { List<IpatErrorInfo> errorInfos = e.getErrorInfos(); assertEquals(2, errorInfos.size()); IpatErrorInfo error = errorInfos.get(0); assertEquals(ErrorCodes.NOT_ENOUGH_TREES, error.getErrorCode()); assertEquals("Project A", error.getErrorParams()[0]); assertEquals("wood", error.getErrorParams()[1]); assertEquals(wantedToPlantA.toString(), error.getErrorParams()[2]); assertEquals(treesRemaining.toString(), error.getErrorParams()[3]); error = errorInfos.get(1); assertEquals(ErrorCodes.NOT_ENOUGH_TREES, error.getErrorCode()); assertEquals("Project B", error.getErrorParams()[0]); assertEquals("doow", error.getErrorParams()[1]); assertEquals(wantedToPlantB.toString(), error.getErrorParams()[2]); assertEquals(treesRemaining.toString(), error.getErrorParams()[3]); } }
public void validatePlantBag(PlantBag plantBag) throws IpatException { Set<String> projectNames = plantBag.getProjects().keySet(); checkProjects(plantBag, projectNames); if (errorInfos.size() > 0) { List<IpatErrorInfo> returnedErrors = this.errorInfos; this.errorInfos = new ArrayList<IpatErrorInfo>(); throw new IpatException(returnedErrors); } }
PlantBagValidator extends AbstractPlantBagValidator { public void validatePlantBag(PlantBag plantBag) throws IpatException { Set<String> projectNames = plantBag.getProjects().keySet(); checkProjects(plantBag, projectNames); if (errorInfos.size() > 0) { List<IpatErrorInfo> returnedErrors = this.errorInfos; this.errorInfos = new ArrayList<IpatErrorInfo>(); throw new IpatException(returnedErrors); } } }
PlantBagValidator extends AbstractPlantBagValidator { public void validatePlantBag(PlantBag plantBag) throws IpatException { Set<String> projectNames = plantBag.getProjects().keySet(); checkProjects(plantBag, projectNames); if (errorInfos.size() > 0) { List<IpatErrorInfo> returnedErrors = this.errorInfos; this.errorInfos = new ArrayList<IpatErrorInfo>(); throw new IpatException(returnedErrors); } } @Autowired private  PlantBagValidator(TreeRepository treeRepository, ProjectArticleRepository projectArticleRepository, ProjectRepository projectRepository); }
PlantBagValidator extends AbstractPlantBagValidator { public void validatePlantBag(PlantBag plantBag) throws IpatException { Set<String> projectNames = plantBag.getProjects().keySet(); checkProjects(plantBag, projectNames); if (errorInfos.size() > 0) { List<IpatErrorInfo> returnedErrors = this.errorInfos; this.errorInfos = new ArrayList<IpatErrorInfo>(); throw new IpatException(returnedErrors); } } @Autowired private  PlantBagValidator(TreeRepository treeRepository, ProjectArticleRepository projectArticleRepository, ProjectRepository projectRepository); void validatePlantBag(PlantBag plantBag); }
PlantBagValidator extends AbstractPlantBagValidator { public void validatePlantBag(PlantBag plantBag) throws IpatException { Set<String> projectNames = plantBag.getProjects().keySet(); checkProjects(plantBag, projectNames); if (errorInfos.size() > 0) { List<IpatErrorInfo> returnedErrors = this.errorInfos; this.errorInfos = new ArrayList<IpatErrorInfo>(); throw new IpatException(returnedErrors); } } @Autowired private  PlantBagValidator(TreeRepository treeRepository, ProjectArticleRepository projectArticleRepository, ProjectRepository projectRepository); void validatePlantBag(PlantBag plantBag);  }