@Test(expected = UserNotFoundException.class) public void should_throw_exception_when_user_not_exist(){ memberService.save(new Member().setId(1L)); }
public <T extends Member> Member save(Member<T> member) { Objects.requireNonNull(member, "member is required"); Member<T> persistedMember = memberRepository.findOne(member.getId()); if (persistedMember == null) { throw new UserNotFoundException(); } persistedMember .setLastname(member.getLastname()) .setFirstname(member.getFirstname()) .setCompany(member.getCompany()) .setShortDescription(member.getShortDescription()) .setLongDescription(member.getLongDescription()) .setPublicProfile(Boolean.TRUE) .clearInterests() .clearSharedLinks(); if (!persistedMember.getMemberEvents().stream().anyMatch(e -> EventService.getCurrent().equals(e.getEvent()))) { persistedMember.getMemberEvents().add(new MemberEvent().setMember(persistedMember).setEvent(EventService.getCurrent())); } member.getSharedLinks().stream().forEach(link -> persistedMember.addSharedLink( sharedLinkRepository.save(new SharedLink() .setMember(persistedMember) .setName(link.getName()) .setURL(link.getURL())))); member.getInterests().forEach(i -> { Interest interest = interestRepository.findByName(i.getName()); if (i == null) { interest = interestRepository.save(new Interest().setName(i.getName())); } persistedMember.addInterest(interest); }); return persistedMember; }
MemberService { public <T extends Member> Member save(Member<T> member) { Objects.requireNonNull(member, "member is required"); Member<T> persistedMember = memberRepository.findOne(member.getId()); if (persistedMember == null) { throw new UserNotFoundException(); } persistedMember .setLastname(member.getLastname()) .setFirstname(member.getFirstname()) .setCompany(member.getCompany()) .setShortDescription(member.getShortDescription()) .setLongDescription(member.getLongDescription()) .setPublicProfile(Boolean.TRUE) .clearInterests() .clearSharedLinks(); if (!persistedMember.getMemberEvents().stream().anyMatch(e -> EventService.getCurrent().equals(e.getEvent()))) { persistedMember.getMemberEvents().add(new MemberEvent().setMember(persistedMember).setEvent(EventService.getCurrent())); } member.getSharedLinks().stream().forEach(link -> persistedMember.addSharedLink( sharedLinkRepository.save(new SharedLink() .setMember(persistedMember) .setName(link.getName()) .setURL(link.getURL())))); member.getInterests().forEach(i -> { Interest interest = interestRepository.findByName(i.getName()); if (i == null) { interest = interestRepository.save(new Interest().setName(i.getName())); } persistedMember.addInterest(interest); }); return persistedMember; } }
MemberService { public <T extends Member> Member save(Member<T> member) { Objects.requireNonNull(member, "member is required"); Member<T> persistedMember = memberRepository.findOne(member.getId()); if (persistedMember == null) { throw new UserNotFoundException(); } persistedMember .setLastname(member.getLastname()) .setFirstname(member.getFirstname()) .setCompany(member.getCompany()) .setShortDescription(member.getShortDescription()) .setLongDescription(member.getLongDescription()) .setPublicProfile(Boolean.TRUE) .clearInterests() .clearSharedLinks(); if (!persistedMember.getMemberEvents().stream().anyMatch(e -> EventService.getCurrent().equals(e.getEvent()))) { persistedMember.getMemberEvents().add(new MemberEvent().setMember(persistedMember).setEvent(EventService.getCurrent())); } member.getSharedLinks().stream().forEach(link -> persistedMember.addSharedLink( sharedLinkRepository.save(new SharedLink() .setMember(persistedMember) .setName(link.getName()) .setURL(link.getURL())))); member.getInterests().forEach(i -> { Interest interest = interestRepository.findByName(i.getName()); if (i == null) { interest = interestRepository.save(new Interest().setName(i.getName())); } persistedMember.addInterest(interest); }); return persistedMember; }  }
MemberService { public <T extends Member> Member save(Member<T> member) { Objects.requireNonNull(member, "member is required"); Member<T> persistedMember = memberRepository.findOne(member.getId()); if (persistedMember == null) { throw new UserNotFoundException(); } persistedMember .setLastname(member.getLastname()) .setFirstname(member.getFirstname()) .setCompany(member.getCompany()) .setShortDescription(member.getShortDescription()) .setLongDescription(member.getLongDescription()) .setPublicProfile(Boolean.TRUE) .clearInterests() .clearSharedLinks(); if (!persistedMember.getMemberEvents().stream().anyMatch(e -> EventService.getCurrent().equals(e.getEvent()))) { persistedMember.getMemberEvents().add(new MemberEvent().setMember(persistedMember).setEvent(EventService.getCurrent())); } member.getSharedLinks().stream().forEach(link -> persistedMember.addSharedLink( sharedLinkRepository.save(new SharedLink() .setMember(persistedMember) .setName(link.getName()) .setURL(link.getURL())))); member.getInterests().forEach(i -> { Interest interest = interestRepository.findByName(i.getName()); if (i == null) { interest = interestRepository.save(new Interest().setName(i.getName())); } persistedMember.addInterest(interest); }); return persistedMember; }  Set<ProposalError> checkSpeakerData(Member member); Member save(Member<T> member); }
MemberService { public <T extends Member> Member save(Member<T> member) { Objects.requireNonNull(member, "member is required"); Member<T> persistedMember = memberRepository.findOne(member.getId()); if (persistedMember == null) { throw new UserNotFoundException(); } persistedMember .setLastname(member.getLastname()) .setFirstname(member.getFirstname()) .setCompany(member.getCompany()) .setShortDescription(member.getShortDescription()) .setLongDescription(member.getLongDescription()) .setPublicProfile(Boolean.TRUE) .clearInterests() .clearSharedLinks(); if (!persistedMember.getMemberEvents().stream().anyMatch(e -> EventService.getCurrent().equals(e.getEvent()))) { persistedMember.getMemberEvents().add(new MemberEvent().setMember(persistedMember).setEvent(EventService.getCurrent())); } member.getSharedLinks().stream().forEach(link -> persistedMember.addSharedLink( sharedLinkRepository.save(new SharedLink() .setMember(persistedMember) .setName(link.getName()) .setURL(link.getURL())))); member.getInterests().forEach(i -> { Interest interest = interestRepository.findByName(i.getName()); if (i == null) { interest = interestRepository.save(new Interest().setName(i.getName())); } persistedMember.addInterest(interest); }); return persistedMember; }  Set<ProposalError> checkSpeakerData(Member member); Member save(Member<T> member);  }