|
|
@@ -1,4 +1,52 @@
|
|
1
|
1
|
package com.example.demo.ServiceTest;
|
|
2
|
2
|
|
|
|
3
|
+import com.example.demo.Entity.Game;
|
|
|
4
|
+import com.example.demo.Repository.GameRepository;
|
|
|
5
|
+import com.example.demo.Service.GameService;
|
|
|
6
|
+import org.junit.Assert;
|
|
|
7
|
+import org.junit.Before;
|
|
|
8
|
+import org.junit.Test;
|
|
|
9
|
+import org.mockito.InjectMocks;
|
|
|
10
|
+import org.mockito.Mock;
|
|
|
11
|
+import org.mockito.Mockito;
|
|
|
12
|
+import org.mockito.MockitoAnnotations;
|
|
|
13
|
+
|
|
|
14
|
+import java.util.ArrayList;
|
|
|
15
|
+import java.util.Collection;
|
|
|
16
|
+import java.util.List;
|
|
|
17
|
+
|
|
3
|
18
|
public class GameServiceTest {
|
|
|
19
|
+
|
|
|
20
|
+ @Mock
|
|
|
21
|
+ private GameRepository gameRepository;
|
|
|
22
|
+
|
|
|
23
|
+ @InjectMocks
|
|
|
24
|
+ private GameService gameService;
|
|
|
25
|
+
|
|
|
26
|
+ @Before
|
|
|
27
|
+ public void setUp(){
|
|
|
28
|
+ MockitoAnnotations.initMocks(this);
|
|
|
29
|
+ }
|
|
|
30
|
+
|
|
|
31
|
+ @Test
|
|
|
32
|
+ public void createGameTest(){
|
|
|
33
|
+ Game metroid = new Game("metroid","nintendo", "nes");
|
|
|
34
|
+ Mockito.when(gameRepository.save(metroid)).thenReturn(metroid);
|
|
|
35
|
+
|
|
|
36
|
+ Game actual = gameService.createGame(metroid);
|
|
|
37
|
+
|
|
|
38
|
+ Assert.assertEquals(actual, metroid);
|
|
|
39
|
+ }
|
|
|
40
|
+
|
|
|
41
|
+ @Test
|
|
|
42
|
+ public void findAllGamesTest(){
|
|
|
43
|
+ List<Game> games = new ArrayList<>();
|
|
|
44
|
+ games.add(new Game("metroid","nintendo", "nes"));
|
|
|
45
|
+ games.add(new Game("contra","nintendo", "nes"));
|
|
|
46
|
+
|
|
|
47
|
+ Mockito.when(gameRepository.findAll()).thenReturn(games);
|
|
|
48
|
+
|
|
|
49
|
+ Collection<Game> actual = gameService.findAllGames();
|
|
|
50
|
+ Assert.assertEquals(actual, games);
|
|
|
51
|
+ }
|
|
4
|
52
|
}
|