Commit 4a9cc889 by Paktalin

Test refactoring: created parent MoveStrategyTest

parent fc9af304
package com.example.paktalin.agilejava_exercises.moves;
import com.example.paktalin.agilejava_exercises.Board;
import com.example.paktalin.agilejava_exercises.Piece;
import com.example.paktalin.agilejava_exercises.Position;
import junit.framework.TestCase;
/**
* Created by Paktalin on 31/05/2018.
*/
public class KingMoveStrategyTest extends TestCase {
private Piece king;
private Board board;
public class KingMoveStrategyTest extends MoveStrategyTest {
@Override
protected void setUp() throws Exception {
board = Board.createEmpty();
board.placePiece(Piece.createKing(Piece.Color.Black), "b5");
king = board.getPieceAtPosition("b5");
void setAccessiblePosition() {
accessiblePosition = Position.create("a6");
}
public void testMove() {
Position currentPosition = king.getPosition();
assertEquals("b5", currentPosition.toString());
Position accessiblePosition = Position.create("a6");
board.move(currentPosition, accessiblePosition);
assertTrue(king.isAtPosition(accessiblePosition));
assertFalse(king.isAtPosition(currentPosition));
currentPosition = accessiblePosition;
Position notAccessiblePosition = Position.create("d4");
board.move(currentPosition, notAccessiblePosition);
assertTrue(king.isAtPosition(currentPosition));
assertFalse(king.isAtPosition(notAccessiblePosition));
@Override
void setNotAccessiblePosition() {
notAccessiblePosition = Position.create("d4");
}
}
package com.example.paktalin.agilejava_exercises.moves;
import com.example.paktalin.agilejava_exercises.Board;
import com.example.paktalin.agilejava_exercises.Piece;
import com.example.paktalin.agilejava_exercises.Position;
import junit.framework.TestCase;
/**
* Created by Paktalin on 31/05/2018.
*/
public abstract class MoveStrategyTest extends TestCase {
private Piece piece;
private Board board;
Position accessiblePosition, notAccessiblePosition;
@Override
protected void setUp() throws Exception {
board = Board.createEmpty();
board.placePiece(Piece.createKing(Piece.Color.Black), "b5");
piece = board.getPieceAtPosition("b5");
setAccessiblePosition();
setNotAccessiblePosition();
}
abstract void setAccessiblePosition();
abstract void setNotAccessiblePosition();
public void testMove() {
Position currentPosition = piece.getPosition();
board.move(currentPosition, accessiblePosition);
assertTrue(piece.isAtPosition(accessiblePosition));
assertFalse(piece.isAtPosition(currentPosition));
currentPosition = accessiblePosition;
board.move(currentPosition, notAccessiblePosition);
assertTrue(piece.isAtPosition(currentPosition));
assertFalse(piece.isAtPosition(notAccessiblePosition));
}
}
package com.example.paktalin.agilejava_exercises.moves;
import com.example.paktalin.agilejava_exercises.Board;
import com.example.paktalin.agilejava_exercises.Piece;
import com.example.paktalin.agilejava_exercises.Position;
import junit.framework.TestCase;
/**
* Created by Paktalin on 31/05/2018.
*/
public class QueenMoveStrategyTest extends TestCase {
private Piece queen;
private Board board;
public class QueenMoveStrategyTest extends MoveStrategyTest {
@Override
protected void setUp() throws Exception {
board = Board.createEmpty();
board.placePiece(Piece.createQueen(Piece.Color.Black), "b5");
queen = board.getPieceAtPosition("b5");
void setAccessiblePosition() {
accessiblePosition = Position.create("d3");
}
public void testMove() {
Position currentPosition = queen.getPosition();
Position accessiblePosition = Position.create("d3");
board.move(currentPosition, accessiblePosition);
assertTrue(queen.isAtPosition(accessiblePosition));
assertFalse(queen.isAtPosition(currentPosition));
currentPosition = accessiblePosition;
Position notAccessiblePosition = Position.create("f7");
board.move(currentPosition, notAccessiblePosition);
assertTrue(queen.isAtPosition(currentPosition));
assertFalse(queen.isAtPosition(notAccessiblePosition));
@Override
void setNotAccessiblePosition() {
notAccessiblePosition = Position.create("f7");
}
}
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