package de.panikco.pmdb.service;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import de.panikco.pmdb.model.Media;
import de.panikco.pmdb.repos.MediaRepository;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
public class MediaServiceTest {
@InjectMocks
MediaService ms = new MediaServiceImpl();
@Mock
MediaRepository repository;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
}
@Test
public void addMediaTest() {
List <Media> media = new ArrayList<Media>();
Media aMedium = new Media();
aMedium.setTitle("Herr der Ringe");
media.add(aMedium);
when(repository.findAll()).thenReturn(media);
List<Media> result = ms.getAllMedia();
verify(repository).findAll();
verifyNoMoreInteractions(repository);
assertEquals(media, result);
}
}