Skip to content

Commit

Permalink
♻️ 핏짜파티 리펙토링
Browse files Browse the repository at this point in the history
  • Loading branch information
usadev0813 committed Dec 17, 2024
1 parent 426fa9c commit 7a12c7a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 91 deletions.
29 changes: 29 additions & 0 deletions java/pizza-party/src/main/java/org/example/domain/Piece.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.example.domain;

import java.util.Objects;

public class Piece {
private int pieces;
public Piece(final int pieces) {
if(pieces <= 0) {
throw new IllegalArgumentException("피자 조각 개수는 0개 이상이여야 합니다.");
}
if(pieces % 2 != 0) {
throw new IllegalArgumentException("피자 조각 개수는 짝수여야 합니다.");
}
this.pieces = pieces;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Piece pizza = (Piece) o;
return pieces == pizza.pieces;
}

@Override
public int hashCode() {
return Objects.hash(pieces);
}
}
28 changes: 16 additions & 12 deletions java/pizza-party/src/main/java/org/example/domain/Pizza.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
package org.example.domain;

import java.util.List;
import java.util.Objects;
import java.util.stream.IntStream;

public class Pizza {
private int pieces;
public Pizza(int pieces) {
if(pieces <= 0) {
throw new IllegalArgumentException("피자 조각 개수는 양수여야 합니다.");
}
if(pieces % 2 != 0) {
throw new IllegalArgumentException("피자 조각 개수는 짝수여야 합니다.");
}
this.pieces = pieces;
private final List<Piece> pieces;

private Pizza(final List<Piece> pizzas) {
this.pieces = pizzas;
}

public static Pizza init(final int piece, final int pizzaCount) {
final List<Piece> pizzas = IntStream.range(0, pizzaCount)
.mapToObj(pizza -> new Piece(piece))
.toList();
return new Pizza(pizzas);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pizza pizza = (Pizza) o;
return pieces == pizza.pieces;
Pizza pizzas1 = (Pizza) o;
return Objects.equals(pieces, pizzas1.pieces);
}

@Override
public int hashCode() {
public int hashCode() {
return Objects.hash(pieces);
}
}
32 changes: 0 additions & 32 deletions java/pizza-party/src/main/java/org/example/domain/Pizzas.java

This file was deleted.

5 changes: 0 additions & 5 deletions java/pizza-party/src/main/java/org/example/io/wiㅇget.java

This file was deleted.

29 changes: 29 additions & 0 deletions java/pizza-party/src/test/java/domain/PieceTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package domain;

import org.example.domain.Piece;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class PieceTests {

@ParameterizedTest
@DisplayName("피자 조각 개수가 0 이하일 경우 예외발생")
@ValueSource(ints = {-1, 0})
void 피자_조각_개수가_0이하일_경우_예외_발생(int invalidPieceCount) {
assertThatThrownBy(() -> new Piece(invalidPieceCount))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("피자 조각 개수는 1개 이상이어야 합니다.");
}

@ParameterizedTest
@DisplayName("피자 조각 개수가 홀수일 경우 예외발생")
@ValueSource(ints = {1, 9})
void 피자_조각_개수가_홀수일_경우_예외_발생(int oddPieceCount) {
assertThatThrownBy(() -> new Piece(oddPieceCount))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("피자 조각 개수는 짝수여야 합니다.");
}
}
27 changes: 6 additions & 21 deletions java/pizza-party/src/test/java/domain/PizzaTests.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
package domain;

import org.example.domain.Piece;
import org.example.domain.Pizza;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.*;
import java.util.List;

public class PizzaTests {
@ParameterizedTest
@ValueSource(ints = {-1, 0})
@DisplayName("피자 조각 개수는 양수여야 합니다..")
void test(int pieces) {
assertThatThrownBy(() -> new Pizza(pieces))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("피자 조각 개수는 양수여야 합니다.");
}
@ParameterizedTest
@ValueSource(ints = {1, 5, 7})
@DisplayName("피자 조각 개수는 짝수이어야 합니다.")
void test1(int pieces) {
assertThatThrownBy(() -> new Pizza(pieces))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("피자 조각 개수는 짝수여야 합니다.");
}
}
import static org.assertj.core.api.Assertions.assertThat;

public class PizzaTests {
}
21 changes: 0 additions & 21 deletions java/pizza-party/src/test/java/domain/PizzasTests.java

This file was deleted.

0 comments on commit 7a12c7a

Please sign in to comment.