View Javadoc
1   package de.aikiit.game.kaiser;
2   
3   import lombok.SneakyThrows;
4   import org.junit.jupiter.api.BeforeEach;
5   import org.junit.jupiter.api.Test;
6   import org.mockito.Mock;
7   import uk.org.webcompere.systemstubs.SystemStubs;
8   
9   import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
10  import static org.junit.jupiter.api.Assertions.assertThrows;
11  
12  class KaiserGameTest {
13  
14      private KaiserGame game;
15  
16      @Mock
17      private KaiserEngine mockedEngine;
18  
19      @BeforeEach
20      void createNewGameUnderTest() {
21          this.game = new KaiserGame();
22      }
23  
24      @Test
25      void intro() {
26          assertDoesNotThrow(() -> game.intro());
27      }
28  
29      @Test
30      void banner() {
31          assertDoesNotThrow(() -> game.banner());
32      }
33  
34      @Test
35      void byeByeBanner() {
36          assertDoesNotThrow(() -> game.byeByeBanner());
37      }
38  
39      @Test
40      void finish() {
41          assertDoesNotThrow(() -> game.finish());
42      }
43  
44      @Test
45      void status() {
46          assertDoesNotThrow(() -> game.status());
47      }
48  
49      @SneakyThrows
50      @Test
51      void actionsWithMockedEngine() {
52          KaiserGame gameWithMockedEngine = new KaiserGame(mockedEngine);
53  
54          SystemStubs.withTextFromSystemIn("0")
55                  .execute(() -> {
56                      // as we can only stub one call to System.in, we get an exception from the second call
57                      assertThrows(NullPointerException.class, gameWithMockedEngine::actions);
58                  });
59      }
60  
61      @SneakyThrows
62      @Test
63      void runWithMockedEngine() {
64          KaiserGame gameWithMockedEngine = new KaiserGame(mockedEngine);
65  
66          SystemStubs.withTextFromSystemIn("0")
67                  .execute(() -> {
68                      // as we can only stub one call to System.in, we get an exception from the second call
69                      assertThrows(NullPointerException.class, gameWithMockedEngine::run);
70                  });
71      }
72  }