feat(game): GameSession bundles savable state; turn + autosave hook
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package thb.jeanluc.adventure.game;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import thb.jeanluc.adventure.io.TestIO;
|
||||
import thb.jeanluc.adventure.model.Player;
|
||||
import thb.jeanluc.adventure.model.Room;
|
||||
import thb.jeanluc.adventure.model.World;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class GameSessionTest {
|
||||
|
||||
private GameSession session() {
|
||||
Room k = new Room("k", "Kitchen", "d");
|
||||
World w = new World(Map.of("k", k), Map.of(), Map.of(), "t", "w");
|
||||
return new GameSession(w, new Player(k, 0), "slot-a");
|
||||
}
|
||||
|
||||
@Test
|
||||
void exposesStateAndIncrementsTurn() {
|
||||
GameSession s = session();
|
||||
assertThat(s.getSlotName()).isEqualTo("slot-a");
|
||||
assertThat(s.getTurn()).isZero();
|
||||
s.incrementTurn();
|
||||
s.incrementTurn();
|
||||
assertThat(s.getTurn()).isEqualTo(2);
|
||||
s.setTurn(10);
|
||||
assertThat(s.getTurn()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextDelegatesToSession() {
|
||||
GameSession s = session();
|
||||
GameContext ctx = new GameContext(s, new TestIO());
|
||||
assertThat(ctx.getWorld()).isSameAs(s.getWorld());
|
||||
assertThat(ctx.getPlayer()).isSameAs(s.getPlayer());
|
||||
assertThat(ctx.getState()).isSameAs(s.getState());
|
||||
assertThat(ctx.getQuestLog()).isSameAs(s.getQuestLog());
|
||||
assertThat(ctx.getSession()).isSameAs(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyConstructorBuildsFreshSession() {
|
||||
Room k = new Room("k", "Kitchen", "d");
|
||||
World w = new World(Map.of("k", k), Map.of(), Map.of(), "t", "w");
|
||||
GameContext ctx = new GameContext(w, new Player(k, 0), new TestIO());
|
||||
assertThat(ctx.getSession()).isNotNull();
|
||||
assertThat(ctx.getSession().getTurn()).isZero();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user