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