1 package de.aikiit.game.kaiser;
2
3 import org.junit.jupiter.api.BeforeEach;
4 import org.junit.jupiter.api.Test;
5
6 import static org.assertj.core.api.Assertions.assertThat;
7 import static org.assertj.core.api.Assertions.assertThatThrownBy;
8
9 class KaiserEngineFeedToPopulationTest {
10 private KaiserEngine engine;
11
12 @BeforeEach
13 void setup() {
14 engine = new KaiserEngine(new BasicRandom());
15 engine.startNewRound();
16 }
17
18 @Test
19 void feedingStoresAllocationAndReducesStocks() {
20 engine.feedToPopulation(2000L);
21 assertThat(engine.getFoodAllocated()).isEqualByComparingTo("2000");
22 assertThat(engine.getGrainStocks()).isEqualByComparingTo("800");
23 assertThat(engine.getPlagueRoll()).isEqualTo(1);
24 }
25
26 @Test
27 void zeroFoodIsAValidAllocation() {
28 engine.feedToPopulation(0L);
29 assertThat(engine.getFoodAllocated()).isZero();
30 assertThat(engine.getGrainStocks()).isEqualByComparingTo("2800");
31 }
32
33 @Test
34 void allStocksCanBeDistributed() {
35 engine.feedToPopulation(2800L);
36 assertThat(engine.getFoodAllocated()).isEqualByComparingTo("2800");
37 assertThat(engine.getGrainStocks()).isZero();
38 }
39
40 @Test
41 void insufficientStocksDoNotChangeState() {
42 assertThatThrownBy(() -> engine.feedToPopulation(2801L))
43 .isInstanceOf(IllegalArgumentException.class)
44 .hasMessage("Not Enough in Stock");
45 assertThat(engine.getFoodAllocated()).isZero();
46 assertThat(engine.getGrainStocks()).isEqualByComparingTo("2800");
47 }
48
49 @Test
50 void negativeInputEndsGame() {
51 engine.feedToPopulation(-1L);
52 assertThat(engine.getState()).isEqualTo(KaiserEngine.GameState.ABORTED);
53 assertThat(engine.getGrainStocks()).isEqualByComparingTo("2800");
54 }
55 }