#104 shock, the first unit test works

This commit is contained in:
Nightblade73 2019-05-14 00:02:30 +04:00
parent ff7f535980
commit 9da5fd8a7a
2 changed files with 39 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package ru.ulstu.conference.service; package ru.ulstu.conference.service;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -43,6 +44,7 @@ public class ConferenceService {
private final ConferenceNotificationService conferenceNotificationService; private final ConferenceNotificationService conferenceNotificationService;
private final EventService eventService; private final EventService eventService;
@Autowired
public ConferenceService(ConferenceRepository conferenceRepository, public ConferenceService(ConferenceRepository conferenceRepository,
ConferenceUserService conferenceUserService, ConferenceUserService conferenceUserService,
DeadlineService deadlineService, DeadlineService deadlineService,

View File

@ -0,0 +1,37 @@
package conference.module_test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.domain.Sort;
import ru.ulstu.conference.model.Conference;
import ru.ulstu.conference.repository.ConferenceRepository;
import ru.ulstu.conference.service.ConferenceService;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
@RunWith(MockitoJUnitRunner.class)
public class ConferenceServiceTest {
@Mock
ConferenceRepository conferenceRepository;
@InjectMocks
ConferenceService conferenceService;
@Test
public void testFindAllConferences() {
List<Conference> conferences = new ArrayList<>();
Conference conference = new Conference();
conference.setId(1);
conferences.add(conference);
Mockito.when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences);
assertEquals(conferences, conferenceService.findAll());
}
}