#104 test create
This commit is contained in:
parent
c88c77cd7d
commit
11cab955b4
@ -221,8 +221,12 @@ public class ConferenceDto {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ConferenceDto that = (ConferenceDto) o;
|
||||
return ping == that.ping &&
|
||||
disabledTakePart == that.disabledTakePart &&
|
||||
@ -243,6 +247,7 @@ public class ConferenceDto {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds, userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart);
|
||||
return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds,
|
||||
userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart);
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,14 @@ import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.conference.model.ConferenceDto;
|
||||
import ru.ulstu.conference.model.ConferenceUser;
|
||||
import ru.ulstu.conference.repository.ConferenceRepository;
|
||||
import ru.ulstu.conference.service.ConferenceNotificationService;
|
||||
import ru.ulstu.conference.service.ConferenceService;
|
||||
import ru.ulstu.conference.service.ConferenceUserService;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.deadline.service.DeadlineService;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.service.PaperService;
|
||||
import ru.ulstu.timeline.service.EventService;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
@ -26,6 +28,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ -46,6 +49,12 @@ public class ConferenceServiceTest {
|
||||
@Mock
|
||||
UserService userService;
|
||||
|
||||
@Mock
|
||||
ConferenceNotificationService conferenceNotificationService;
|
||||
|
||||
@Mock
|
||||
EventService eventService;
|
||||
|
||||
@InjectMocks
|
||||
ConferenceService conferenceService;
|
||||
|
||||
@ -53,7 +62,9 @@ public class ConferenceServiceTest {
|
||||
private List<Deadline> deadlines;
|
||||
private List<Paper> papers;
|
||||
private List<ConferenceUser> conferenceUsers;
|
||||
private Conference conference;
|
||||
|
||||
private Conference conferenceWithId;
|
||||
private Conference conferenceWithoutId;
|
||||
private ConferenceUser conferenceUser;
|
||||
|
||||
private Paper paperWithId;
|
||||
@ -66,10 +77,15 @@ public class ConferenceServiceTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
conferences = new ArrayList<>();
|
||||
conference = new Conference();
|
||||
conferenceWithId = new Conference();
|
||||
conferenceWithoutId = new Conference();
|
||||
|
||||
conference.setTitle("Название");
|
||||
conference.setDescription("Описание");
|
||||
conferenceWithId.setId(1);
|
||||
conferenceWithId.setTitle("Название");
|
||||
conferenceWithId.setDescription("Описание");
|
||||
|
||||
conferenceWithoutId.setTitle("Название");
|
||||
conferenceWithoutId.setDescription("Описание");
|
||||
|
||||
paperWithId = new Paper();
|
||||
paperWithId.setId(1);
|
||||
@ -97,12 +113,16 @@ public class ConferenceServiceTest {
|
||||
conferenceUsers = new ArrayList<>();
|
||||
conferenceUsers.add(conferenceUser);
|
||||
|
||||
conference.setPapers(papers);
|
||||
conference.setDeadlines(deadlines);
|
||||
conference.setUsers(conferenceUsers);
|
||||
conferenceWithId.setPapers(papers);
|
||||
conferenceWithId.setDeadlines(deadlines);
|
||||
conferenceWithId.setUsers(conferenceUsers);
|
||||
|
||||
conferences.add(conference);
|
||||
conferenceDto = new ConferenceDto(conference);
|
||||
conferenceWithoutId.setPapers(papers);
|
||||
conferenceWithoutId.setDeadlines(deadlines);
|
||||
conferenceWithoutId.setUsers(conferenceUsers);
|
||||
|
||||
conferences.add(conferenceWithId);
|
||||
conferenceDto = new ConferenceDto(conferenceWithId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -117,7 +137,7 @@ public class ConferenceServiceTest {
|
||||
when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId);
|
||||
when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines);
|
||||
when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers);
|
||||
assertEquals(conference, conferenceService.copyFromDto(new Conference(), conferenceDto));
|
||||
assertEquals(conferenceWithoutId, conferenceService.copyFromDto(new Conference(), conferenceDto));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -136,7 +156,17 @@ public class ConferenceServiceTest {
|
||||
|
||||
@Test
|
||||
public void testFindOneDto() throws IOException {
|
||||
when(conferenceRepository.findOne(1)).thenReturn(conference);
|
||||
when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId);
|
||||
assertEquals(conferenceDto, conferenceService.findOneDto(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() throws IOException {
|
||||
when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId);
|
||||
when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId);
|
||||
when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines);
|
||||
when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers);
|
||||
when(conferenceRepository.save(conferenceWithoutId)).thenReturn(conferenceWithoutId);
|
||||
assertNull(conferenceService.create(conferenceDto));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user