Skip to content

Commit

Permalink
#63: test cover the simplest game.
Browse files Browse the repository at this point in the history
  • Loading branch information
lrozenblyum committed Jun 13, 2023
1 parent 861a7a4 commit c764d5e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/test/java/com/leokom/games/chess/pgn/PGNGameTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.leokom.games.chess.pgn;

import com.leokom.games.chess.Game;
import com.leokom.games.chess.engine.Move;
import com.leokom.games.chess.engine.Position;
import com.leokom.games.chess.engine.Side;
import com.leokom.games.chess.player.Player;
import com.leokom.games.chess.player.PlayerBuilder;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -13,6 +15,7 @@

import static org.junit.Assert.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

public class PGNGameTest {
private Player whitePlayer;
Expand All @@ -22,10 +25,10 @@ public class PGNGameTest {

@Before
public void prepare() {
this.whitePlayer = Mockito.mock(Player.class);
this.blackPlayer = Mockito.mock(Player.class);
this.whitePlayer = mock(Player.class);
this.blackPlayer = mock(Player.class);
//game at the moment depends on whitePlayer's position, the test needs to resolve this dependency
this.positionAfterTheGame = Mockito.mock( Position.class );
this.positionAfterTheGame = mock( Position.class );
Mockito.when( whitePlayer.getPosition() ).thenReturn(positionAfterTheGame);
this.game = new Game( whitePlayer, blackPlayer );
}
Expand Down Expand Up @@ -122,6 +125,15 @@ public void blackWins() {
assertEquals( "[Result \"0-1\"]", pgn.split( "\n" )[ 6 ] );
}

@Test
public void whiteResignsBeforeFirstMove() {
Player whitePlayer = new PlayerBuilder(blackPlayer).move(Move.RESIGN).build();
Game game = new Game(whitePlayer, blackPlayer);
String pgn = new PGNGame(new Event(null, null, null), game).run();

assertEquals( "[Result \"0-1\"]", pgn.split( "\n" )[ 6 ] );
}

@Test
public void draw() {
Game spyGame = Mockito.spy(new Game(whitePlayer, blackPlayer));
Expand Down

0 comments on commit c764d5e

Please sign in to comment.