Commit 4a9cc889 by Paktalin

Test refactoring: created parent MoveStrategyTest

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