-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathFlashCardServiceImplTest.java
More file actions
48 lines (37 loc) · 1.37 KB
/
Copy pathFlashCardServiceImplTest.java
File metadata and controls
48 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.teamtreehouse.flashy.services;
import com.teamtreehouse.flashy.domain.FlashCard;
import com.teamtreehouse.flashy.repositories.FlashCardRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class FlashCardServiceImplTest {
@Mock
private FlashCardRepository repository;
@InjectMocks
private FlashCardService service = new FlashCardServiceImpl();
@Test
public void getRandomFlashCards_ShouldReturnTwo() throws Exception {
List<FlashCard> flashCards = Arrays.asList(
new FlashCard(),
new FlashCard()
);
when(repository.findAll()).thenReturn(flashCards);
assertEquals("getRandomFlashCards should return two favorites", 2, service.getRandomFlashCards(2).size());
verify(repository).findAll();
}
@Test
public void findById_ShouldReturnOne() throws Exception {
when(repository.findOne(1L)).thenReturn(new FlashCard());
assertThat(service.getFlashCardById(1L), instanceOf(FlashCard.class));
}
}