Commit cb3f5fad by Paktalin

Test refactoring

parent 4a9cc889
......@@ -32,16 +32,28 @@ public class Board {
layout.placePiece(piece, Position.create(position));
}
public void placePiece(Piece piece, Position position) {
layout.placePiece(piece, position);
}
public void move(Position from, Position to) {
Piece piece = layout.getPieceAtPosition(from);
if (piece.isMovable(from, to))
layout.move(from, to);
}
public void move(Piece piece, Position to) {
move(piece.getPosition(), to);
}
public Piece getPieceAtPosition(String position) {
return layout.getPieceAtPosition(Position.create(position));
}
public Piece getPieceAtPosition(Position position) {
return layout.getPieceAtPosition(position);
}
String print() {
return layout.print();
}
......
package com.example.paktalin.agilejava_exercises.moves;
import com.example.paktalin.agilejava_exercises.Piece;
import com.example.paktalin.agilejava_exercises.Position;
/**
......@@ -9,6 +10,11 @@ import com.example.paktalin.agilejava_exercises.Position;
public class KingMoveStrategyTest extends MoveStrategyTest {
@Override
void putPieceOnBoard() {
board.placePiece(Piece.createKing(Piece.Color.Black), currentPosition);
}
@Override
void setAccessiblePosition() {
accessiblePosition = Position.create("a6");
}
......
......@@ -13,30 +13,30 @@ import junit.framework.TestCase;
public abstract class MoveStrategyTest extends TestCase {
private Piece piece;
private Board board;
Board board;
Position accessiblePosition, notAccessiblePosition;
Position currentPosition = Position.create("b5");
@Override
protected void setUp() throws Exception {
board = Board.createEmpty();
board.placePiece(Piece.createKing(Piece.Color.Black), "b5");
piece = board.getPieceAtPosition("b5");
putPieceOnBoard();
piece = board.getPieceAtPosition(currentPosition);
setAccessiblePosition();
setNotAccessiblePosition();
}
abstract void putPieceOnBoard();
abstract void setAccessiblePosition();
abstract void setNotAccessiblePosition();
public void testMove() {
Position currentPosition = piece.getPosition();
board.move(currentPosition, accessiblePosition);
board.move(piece, accessiblePosition);
assertTrue(piece.isAtPosition(accessiblePosition));
assertFalse(piece.isAtPosition(currentPosition));
currentPosition = accessiblePosition;
board.move(currentPosition, notAccessiblePosition);
board.move(piece, notAccessiblePosition);
assertTrue(piece.isAtPosition(currentPosition));
assertFalse(piece.isAtPosition(notAccessiblePosition));
}
......
package com.example.paktalin.agilejava_exercises.moves;
import com.example.paktalin.agilejava_exercises.Piece;
import com.example.paktalin.agilejava_exercises.Position;
/**
......@@ -9,6 +10,11 @@ import com.example.paktalin.agilejava_exercises.Position;
public class QueenMoveStrategyTest extends MoveStrategyTest {
@Override
void putPieceOnBoard() {
board.placePiece(Piece.createQueen(Piece.Color.Black), currentPosition);
}
@Override
void setAccessiblePosition() {
accessiblePosition = Position.create("d3");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment