Skip to content

Commit 361883e

Browse files
committed
refactor: MoveParameters -> MoveOptions 변경
1 parent 3347861 commit 361883e

File tree

5 files changed

+78
-33
lines changed

5 files changed

+78
-33
lines changed

src/main/java/chess/domain/ChessGame.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import chess.domain.board.Board;
44
import chess.domain.board.Status;
5-
import chess.domain.command.MoveParameters;
5+
import chess.domain.command.MoveOptions;
66

77
public class ChessGame {
88

@@ -13,8 +13,8 @@ public class ChessGame {
1313
public ChessGame() {
1414
}
1515

16-
public void move(final MoveParameters moveParameters) {
17-
board.move(moveParameters, isWhiteTurn);
16+
public void move(final MoveOptions moveOptions) {
17+
board.move(moveOptions, isWhiteTurn);
1818
isWhiteTurn = !isWhiteTurn;
1919

2020
if (board.isEnd()) {

src/main/java/chess/domain/board/Board.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package chess.domain.board;
22

3-
import chess.domain.command.MoveParameters;
3+
import chess.domain.command.MoveOptions;
44
import chess.domain.piece.Color;
55
import chess.domain.piece.Piece;
66
import chess.domain.player.Player;
@@ -17,11 +17,11 @@ public Board() {
1717
this.black = new Player(Color.BLACK);
1818
}
1919

20-
public void move(final MoveParameters moveParameters, final boolean isWhiteTurn) {
20+
public void move(final MoveOptions moveOptions, final boolean isWhiteTurn) {
2121
Player player = currentPlayer(isWhiteTurn);
2222
Player enemy = currentPlayer(!isWhiteTurn);
23-
Position source = moveParameters.getSource();
24-
Position target = moveParameters.getTarget();
23+
Position source = moveOptions.getSource();
24+
Position target = moveOptions.getTarget();
2525

2626
validateSourceOwner(enemy, source);
2727
validateSamePosition(source, target);

src/main/java/chess/domain/command/MoveParameters.java renamed to src/main/java/chess/domain/command/MoveOptions.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
import java.util.List;
66

7-
public class MoveParameters {
7+
public class MoveOptions {
88

99
private static final int SOURCE_INDEX = 0;
1010
private static final int TARGET_INDEX = 1;
1111

1212
private final Position source;
1313
private final Position target;
1414

15-
public MoveParameters(final List<String> parameters) {
16-
this(Position.of(parameters.get(SOURCE_INDEX)), Position.of(parameters.get(TARGET_INDEX)));
15+
public MoveOptions(final List<String> options) {
16+
this(Position.of(options.get(SOURCE_INDEX)), Position.of(options.get(TARGET_INDEX)));
1717
}
1818

19-
public MoveParameters(final Position source, final Position target) {
19+
public MoveOptions(final Position source, final Position target) {
2020
this.source = source;
2121
this.target = target;
2222
}

src/test/java/chess/domain/board/BoardTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package chess.domain.board;
22

3-
import chess.domain.command.MoveParameters;
3+
import chess.domain.command.MoveOptions;
44
import chess.domain.player.Position;
55
import org.junit.jupiter.api.DisplayName;
66
import org.junit.jupiter.api.Test;
@@ -34,11 +34,11 @@ void move_source_position_empty() {
3434
Board board = new Board();
3535
Position source = Position.of("b3");
3636
Position target = Position.of("b4");
37-
MoveParameters moveParameters = new MoveParameters(source, target);
37+
MoveOptions moveOptions = new MoveOptions(source, target);
3838

3939
//when, then
4040
assertThatIllegalArgumentException()
41-
.isThrownBy(() -> board.move(moveParameters, true))
41+
.isThrownBy(() -> board.move(moveOptions, true))
4242
.withMessage("해당 위치에 기물이 존재하지 않습니다.");
4343
}
4444

@@ -50,11 +50,11 @@ void move_source_not_owner(String sourcePosition, String targetPosition, boolean
5050
Board board = new Board();
5151
Position source = Position.of(sourcePosition);
5252
Position target = Position.of(targetPosition);
53-
MoveParameters moveParameters = new MoveParameters(source, target);
53+
MoveOptions moveOptions = new MoveOptions(source, target);
5454

5555
//when, then
5656
assertThatIllegalArgumentException()
57-
.isThrownBy(() -> board.move(moveParameters, isWhiteTurn))
57+
.isThrownBy(() -> board.move(moveOptions, isWhiteTurn))
5858
.withMessage("자신의 기물만 움직일 수 있습니다.");
5959
}
6060

@@ -66,11 +66,11 @@ void move_source_and_target_same_color(String sourcePosition, String targetPosit
6666
Board board = new Board();
6767
Position source = Position.of(sourcePosition);
6868
Position target = Position.of(targetPosition);
69-
MoveParameters moveParameters = new MoveParameters(source, target);
69+
MoveOptions moveOptions = new MoveOptions(source, target);
7070

7171
//when, then
7272
assertThatIllegalArgumentException()
73-
.isThrownBy(() -> board.move(moveParameters, isWhiteTurn))
73+
.isThrownBy(() -> board.move(moveOptions, isWhiteTurn))
7474
.withMessage("같은 색상의 기물은 공격할 수 없습니다.");
7575
}
7676

@@ -82,11 +82,11 @@ void move_source_and_target_same(String sourcePosition, String targetPosition, b
8282
Board board = new Board();
8383
Position source = Position.of(sourcePosition);
8484
Position target = Position.of(targetPosition);
85-
MoveParameters moveParameters = new MoveParameters(source, target);
85+
MoveOptions moveOptions = new MoveOptions(source, target);
8686

8787
//when, then
8888
assertThatIllegalArgumentException()
89-
.isThrownBy(() -> board.move(moveParameters, isWhiteTurn))
89+
.isThrownBy(() -> board.move(moveOptions, isWhiteTurn))
9090
.withMessage("출발 위치와 도착 위치가 같을 수 없습니다.");
9191
}
9292

@@ -98,11 +98,11 @@ void move_invalid_paths(String sourcePosition, String targetPosition, boolean is
9898
Board board = new Board();
9999
Position source = Position.of(sourcePosition);
100100
Position target = Position.of(targetPosition);
101-
MoveParameters moveParameters = new MoveParameters(source, target);
101+
MoveOptions moveOptions = new MoveOptions(source, target);
102102

103103
//when, then
104104
assertThatIllegalArgumentException()
105-
.isThrownBy(() -> board.move(moveParameters, isWhiteTurn))
105+
.isThrownBy(() -> board.move(moveOptions, isWhiteTurn))
106106
.withMessage("기물을 통과하여 이동할 수 없습니다.");
107107
}
108108

@@ -112,11 +112,11 @@ void move_invalid_paths(String sourcePosition, String targetPosition, boolean is
112112
void move_king_invalid_target(String source, String target) {
113113
//given
114114
Board board = setBoardToAttackKing();
115-
MoveParameters moveParameters = new MoveParameters(Position.of(source), Position.of(target));
115+
MoveOptions moveOptions = new MoveOptions(Position.of(source), Position.of(target));
116116

117117
//when, then
118118
assertThatIllegalArgumentException()
119-
.isThrownBy(() -> board.move(moveParameters, true))
119+
.isThrownBy(() -> board.move(moveOptions, true))
120120
.withMessage("킹은 상대방이 공격 가능한 위치로 이동할 수 없습니다.");
121121
}
122122

@@ -136,20 +136,20 @@ void get_status() {
136136

137137
private Board setBoardToGetStatus() {
138138
Board board = new Board();
139-
board.move(new MoveParameters(Position.of("e7"), Position.of("e5")), false);
140-
board.move(new MoveParameters(Position.of("e5"), Position.of("e4")), false);
141-
board.move(new MoveParameters(Position.of("e4"), Position.of("e3")), false);
142-
board.move(new MoveParameters(Position.of("d2"), Position.of("e3")), true);
139+
board.move(new MoveOptions(Position.of("e7"), Position.of("e5")), false);
140+
board.move(new MoveOptions(Position.of("e5"), Position.of("e4")), false);
141+
board.move(new MoveOptions(Position.of("e4"), Position.of("e3")), false);
142+
board.move(new MoveOptions(Position.of("d2"), Position.of("e3")), true);
143143
return board;
144144
}
145145

146146
private Board setBoardToAttackKing() {
147147
Board board = new Board();
148-
board.move(new MoveParameters(Position.of("e2"), Position.of("e4")), true);
149-
board.move(new MoveParameters(Position.of("d2"), Position.of("d4")), true);
150-
board.move(new MoveParameters(Position.of("e1"), Position.of("e2")), true);
151-
board.move(new MoveParameters(Position.of("c7"), Position.of("c5")), false);
152-
board.move(new MoveParameters(Position.of("d8"), Position.of("a5")), false);
148+
board.move(new MoveOptions(Position.of("e2"), Position.of("e4")), true);
149+
board.move(new MoveOptions(Position.of("d2"), Position.of("d4")), true);
150+
board.move(new MoveOptions(Position.of("e1"), Position.of("e2")), true);
151+
board.move(new MoveOptions(Position.of("c7"), Position.of("c5")), false);
152+
board.move(new MoveOptions(Position.of("d8"), Position.of("a5")), false);
153153
return board;
154154
}
155155
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package chess.domain.command;
2+
3+
import chess.domain.board.File;
4+
import chess.domain.board.Rank;
5+
import chess.domain.player.Position;
6+
import org.junit.jupiter.api.DisplayName;
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.util.Arrays;
10+
import java.util.List;
11+
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
14+
class MoveOptionsTest {
15+
16+
@Test
17+
@DisplayName("시작 위치를 반환한다.")
18+
void getSource() {
19+
//given
20+
List<String> options = Arrays.asList("a1", "b2");
21+
MoveOptions moveOptions = new MoveOptions(options);
22+
23+
//when
24+
Position source = moveOptions.getSource();
25+
26+
//then
27+
assertThat(source.getFile()).isEqualTo(File.A);
28+
assertThat(source.getRank()).isEqualTo(Rank.R1);
29+
}
30+
31+
@Test
32+
@DisplayName("도착 위치를 반환한다.")
33+
void getTarget() {
34+
//given
35+
List<String> options = Arrays.asList("a1", "b2");
36+
MoveOptions moveOptions = new MoveOptions(options);
37+
38+
//when
39+
Position target = moveOptions.getTarget();
40+
41+
//then
42+
assertThat(target.getFile()).isEqualTo(File.B);
43+
assertThat(target.getRank()).isEqualTo(Rank.R2);
44+
}
45+
}

0 commit comments

Comments
 (0)