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);  }
@Test(expected = NullPointerException.class) public void should_throw_NPE_when_arg_empty(){ memberService.save(null); }
@Test(expected = UserNotFoundException.class) public void should_throw_exception_when_id_null(){ memberService.save(new Member()); }
@Test(expected = UserNotFoundException.class) public void should_throw_exception_when_user_not_exist(){ memberService.save(new Member().setId(1L)); }
@Test public void should_save_user(){ when(memberRepository.findOne(1L)).thenReturn(new Member()); Member member = memberService.save(new Member() .setId(1L) .setLastname("name") .setFirstname("toto") .setShortDescription("desc") .setLongDescription("long") .setEmail("gui.ehret@gmail.com") .setCompany("company") .addSharedLink(new SharedLink().setName("twitter").setURL("@twitter")) .addInterest(new Interest().setName("Java")) ); assertThat(member.getLongDescription()).isEqualTo("long"); }