@Test public void convertFromSelfPantDataToTree() { _dbInjecter.injectUser("Adam"); _dbInjecter.injectTreeType("wood", "this is wood", 0.5); long plantedOn = System.currentTimeMillis() - TimeConstants.YEAR_IN_MILLISECONDS; SelfPlantData selfPlantData = new SelfPlantData(); selfPlantData.setPlantedOn(plantedOn); selfPlantData.setAmount(10); selfPlantData.setTreeTypeId(1L); selfPlantData.setDescription("I planted a tree by myself in my garden."); selfPlantData.setLongitude(1.0f); selfPlantData.setLatitude(2.0f); long timeNow = System.currentTimeMillis(); Tree tree = _selfPlantDataToTreeConverter.convertSelfPlantDataToTree(selfPlantData, _userRepository.findById(1L).orElse(null)); assertThat(tree.getOwner().getName()).isEqualTo("Adam"); assertThat(tree.getAmount()).isEqualTo(10); assertThat(tree.getPlantedOn()).isEqualTo(plantedOn); assertThat(tree.getSubmittedOn()).isStrictlyBetween(timeNow - 10000, timeNow + 10000); assertThat(tree.getDescription()).isEqualTo("I planted a tree by myself in my garden."); assertThat(tree.getTreeType().getName()).isEqualTo("wood"); assertThat(tree.getLongitude()).isEqualTo(1.0f); assertThat(tree.getLatitude()).isEqualTo(2.0f); }
protected Tree convertSelfPlantDataToTree(SelfPlantData selfPlantData, User owner) { Tree tree = new Tree(); long submittedOn = System.currentTimeMillis(); tree.setOwner(owner); tree.setPlantedOn(selfPlantData.getPlantedOn()); tree.setSubmittedOn(submittedOn); tree.setAmount(selfPlantData.getAmount()); tree.setImagePath(selfPlantData.getImageName()); tree.setTreeType(_treeTypeRepository.findById(selfPlantData.getTreeTypeId()).orElse(null)); tree.setDescription(selfPlantData.getDescription()); tree.setLongitude(selfPlantData.getLongitude()); tree.setLatitude(selfPlantData.getLatitude()); return tree; }
SelfPlantDataToTreeConverter { protected Tree convertSelfPlantDataToTree(SelfPlantData selfPlantData, User owner) { Tree tree = new Tree(); long submittedOn = System.currentTimeMillis(); tree.setOwner(owner); tree.setPlantedOn(selfPlantData.getPlantedOn()); tree.setSubmittedOn(submittedOn); tree.setAmount(selfPlantData.getAmount()); tree.setImagePath(selfPlantData.getImageName()); tree.setTreeType(_treeTypeRepository.findById(selfPlantData.getTreeTypeId()).orElse(null)); tree.setDescription(selfPlantData.getDescription()); tree.setLongitude(selfPlantData.getLongitude()); tree.setLatitude(selfPlantData.getLatitude()); return tree; } }
SelfPlantDataToTreeConverter { protected Tree convertSelfPlantDataToTree(SelfPlantData selfPlantData, User owner) { Tree tree = new Tree(); long submittedOn = System.currentTimeMillis(); tree.setOwner(owner); tree.setPlantedOn(selfPlantData.getPlantedOn()); tree.setSubmittedOn(submittedOn); tree.setAmount(selfPlantData.getAmount()); tree.setImagePath(selfPlantData.getImageName()); tree.setTreeType(_treeTypeRepository.findById(selfPlantData.getTreeTypeId()).orElse(null)); tree.setDescription(selfPlantData.getDescription()); tree.setLongitude(selfPlantData.getLongitude()); tree.setLatitude(selfPlantData.getLatitude()); return tree; } @Autowired private  SelfPlantDataToTreeConverter(UserRepository userRepository, TreeTypeRepository treeTypeRepository); }
SelfPlantDataToTreeConverter { protected Tree convertSelfPlantDataToTree(SelfPlantData selfPlantData, User owner) { Tree tree = new Tree(); long submittedOn = System.currentTimeMillis(); tree.setOwner(owner); tree.setPlantedOn(selfPlantData.getPlantedOn()); tree.setSubmittedOn(submittedOn); tree.setAmount(selfPlantData.getAmount()); tree.setImagePath(selfPlantData.getImageName()); tree.setTreeType(_treeTypeRepository.findById(selfPlantData.getTreeTypeId()).orElse(null)); tree.setDescription(selfPlantData.getDescription()); tree.setLongitude(selfPlantData.getLongitude()); tree.setLatitude(selfPlantData.getLatitude()); return tree; } @Autowired private  SelfPlantDataToTreeConverter(UserRepository userRepository, TreeTypeRepository treeTypeRepository);  }
SelfPlantDataToTreeConverter { protected Tree convertSelfPlantDataToTree(SelfPlantData selfPlantData, User owner) { Tree tree = new Tree(); long submittedOn = System.currentTimeMillis(); tree.setOwner(owner); tree.setPlantedOn(selfPlantData.getPlantedOn()); tree.setSubmittedOn(submittedOn); tree.setAmount(selfPlantData.getAmount()); tree.setImagePath(selfPlantData.getImageName()); tree.setTreeType(_treeTypeRepository.findById(selfPlantData.getTreeTypeId()).orElse(null)); tree.setDescription(selfPlantData.getDescription()); tree.setLongitude(selfPlantData.getLongitude()); tree.setLatitude(selfPlantData.getLatitude()); return tree; } @Autowired private  SelfPlantDataToTreeConverter(UserRepository userRepository, TreeTypeRepository treeTypeRepository);   }