260616_11_유재우#53
Conversation
코드 리뷰 - 상속과 메서드 오버라이딩 구현🎉 잘 구현된 부분상속 구조와 계층 설계
캡슐화 (Encapsulation)
메서드 오버라이딩
💭 개선을 위한 안내 (소크라테스식 질문)1. 마나 관리의 캡슐화
2. 중복 코드 제거
3. 메서드 이름 관례
4. 책임 분리 (Single Responsibility)
📝 제출 완성도✅ 모든 JUnit 테스트 통과 학생이 OOP의 핵심 개념을 잘 이해하고 있으며, 위의 개선 사항들을 반영한다면 더욱 견고한 코드가 될 수 있습니다. 좋은 첫 단계입니다! 🚀 Walkthrough
Changes게임 클래스 계층 구현 및 테스트
TIL 학습 문서
Sequence Diagram(s)sequenceDiagram
participant GameTest
participant Wizard
participant GreatWizard
participant Hero
rect rgba(100, 149, 237, 0.5)
Note over GameTest,Hero: 일반 힐 (Wizard.heal)
GameTest->>Wizard: heal(hero)
Wizard->>Hero: incrementHP(20)
Hero-->>Wizard: hp = min(hp+20, maxhp)
end
rect rgba(144, 238, 144, 0.5)
Note over GameTest,Hero: 슈퍼 힐 (GreatWizard.SuperHeal)
GameTest->>GreatWizard: SuperHeal(hero)
GreatWizard->>Hero: getMaxhp()
Hero-->>GreatWizard: maxhp
GreatWizard->>Hero: incrementHP(maxhp)
Hero-->>GreatWizard: hp = min(hp+maxhp, maxhp)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
game/src/test/java/com/survivalcoding/gametest.java (1)
22-46: ⚡ Quick win테스트 설명의 계약(마나 소모/비소모)을 assert로 실제 검증해 주세요.
현재 테스트명은 MP 변화를 명시하지만 HP만 검증하고 있습니다. MP assert를 추가하면 회귀 탐지가 훨씬 정확해집니다.
제안 수정안
void wizardHealTest() { wizard.heal(targetHero); assertEquals(70, targetHero.getHp(), "전사의 HP는 50에서 20이 더해져 70이 되어야 합니다."); + assertEquals(20, wizard.mp, "힐 후 마나는 30에서 10 소모되어 20이어야 합니다."); } @@ void greatWizardSuperHealTest() { greatWizard.SuperHeal(targetHero); assertEquals(100, targetHero.getHp(), "슈퍼 힐을 받으면 최대 체력인 100이 되어야 합니다."); + assertEquals(10, greatWizard.mp, "슈퍼 힐 후 마나는 60에서 50 소모되어 10이어야 합니다."); } @@ void outOfManaTest() { Wizard oomWizard = new Wizard("마나없는법사", 50, 50, 5, 50); oomWizard.heal(targetHero); assertEquals(50, targetHero.getHp(), "마나가 부족하므로 타겟의 HP는 변하면 안 됩니다."); + assertEquals(5, oomWizard.mp, "마나 부족 시 마나는 소모되면 안 됩니다."); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@game/src/test/java/com/survivalcoding/gametest.java` around lines 22 - 46, The test methods wizardHealTest, greatWizardSuperHealTest, and outOfManaTest have names that describe expected mana consumption, but they only assert HP changes and do not verify the mana (MP) values. Add assertEquals assertions for the expected mana values after each spell cast to match the contract described in the test display names: wizardHealTest should verify mana decreased by 10, greatWizardSuperHealTest should verify mana decreased by 50, and outOfManaTest should verify mana remained unchanged when insufficient.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@game/src/main/java/com/survivalcoding/Hero.java`:
- Around line 8-12: The Hero constructor does not validate the HP invariant that
requires 0 <= hp <= maxhp. Add validation logic in the Hero constructor to
ensure the hp parameter is within the valid range before assignment. If hp is
negative, clamp it to 0; if hp exceeds maxhp, clamp it to maxhp. This ensures
the object maintains its invariant from creation and aligns with the upper bound
correction logic used elsewhere like incrementHP.
In `@TIL/sample/2026-06-16-상속.md`:
- Around line 183-190: The fenced code block in the document lacks a language
identifier after the opening triple backticks, which triggers a markdownlint
warning. Add a language tag such as `text` immediately after the opening code
fence (the ```) on line 183 to specify the code block language and resolve the
linting error.
---
Nitpick comments:
In `@game/src/test/java/com/survivalcoding/gametest.java`:
- Around line 22-46: The test methods wizardHealTest, greatWizardSuperHealTest,
and outOfManaTest have names that describe expected mana consumption, but they
only assert HP changes and do not verify the mana (MP) values. Add assertEquals
assertions for the expected mana values after each spell cast to match the
contract described in the test display names: wizardHealTest should verify mana
decreased by 10, greatWizardSuperHealTest should verify mana decreased by 50,
and outOfManaTest should verify mana remained unchanged when insufficient.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6c36b170-5453-405c-83af-68f44ec14980
📒 Files selected for processing (5)
TIL/sample/2026-06-16-상속.mdgame/src/main/java/com/survivalcoding/GreatWizard.javagame/src/main/java/com/survivalcoding/Hero.javagame/src/main/java/com/survivalcoding/Wizard.javagame/src/test/java/com/survivalcoding/gametest.java
| public Hero(String name, int hp, int maxhp) { | ||
| this.name = name; | ||
| this.hp = hp; | ||
| this.maxhp = maxhp; | ||
| } |
There was a problem hiding this comment.
생성자에서 HP 불변식(0 <= hp <= maxhp)이 보장되지 않습니다.
현재는 생성 시 hp > maxhp 또는 음수 값이 그대로 들어갈 수 있어 객체가 즉시 비정상 상태가 됩니다. incrementHP의 상한 보정 계약과도 어긋납니다.
제안 수정안
public Hero(String name, int hp, int maxhp) {
- this.name = name;
- this.hp = hp;
- this.maxhp = maxhp;
+ if (hp < 0 || maxhp < 0) {
+ throw new IllegalArgumentException("hp와 maxhp는 0 이상이어야 합니다.");
+ }
+ this.name = name;
+ this.maxhp = maxhp;
+ this.hp = Math.min(hp, maxhp);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public Hero(String name, int hp, int maxhp) { | |
| this.name = name; | |
| this.hp = hp; | |
| this.maxhp = maxhp; | |
| } | |
| public Hero(String name, int hp, int maxhp) { | |
| if (hp < 0 || maxhp < 0) { | |
| throw new IllegalArgumentException("hp와 maxhp는 0 이상이어야 합니다."); | |
| } | |
| this.name = name; | |
| this.maxhp = maxhp; | |
| this.hp = Math.min(hp, maxhp); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@game/src/main/java/com/survivalcoding/Hero.java` around lines 8 - 12, The
Hero constructor does not validate the HP invariant that requires 0 <= hp <=
maxhp. Add validation logic in the Hero constructor to ensure the hp parameter
is within the valid range before assignment. If hp is negative, clamp it to 0;
if hp exceeds maxhp, clamp it to maxhp. This ensures the object maintains its
invariant from creation and aligns with the upper bound correction logic used
elsewhere like incrementHP.
| ``` | ||
| 설정 | ||
| └─ 빌드, 실행, 배포 | ||
| └─ 빌드 도구 | ||
| └─ Gradle | ||
| └─ 다음을 사용하여 테스트 실행 | ||
| Gradle → IntelliJ IDEA | ||
| ``` |
There was a problem hiding this comment.
코드 블록 언어를 지정해 주세요.
183행의 fenced code block에 언어 태그가 없어 markdownlint 경고가 납니다. text 같은 언어를 붙이거나, 코드 펜스를 제거하면 됩니다.
🛠️ 제안 수정
-```
+```text
설정
└─ 빌드, 실행, 배포
└─ 빌드 도구
└─ Gradle
└─ 다음을 사용하여 테스트 실행
Gradle → IntelliJ IDEA
-```
+```🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 183-183: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@TIL/sample/2026-06-16-상속.md` around lines 183 - 190, The fenced code block in
the document lacks a language identifier after the opening triple backticks,
which triggers a markdownlint warning. Add a language tag such as `text`
immediately after the opening code fence (the ```) on line 183 to specify the
code block language and resolve the linting error.
Source: Linters/SAST tools
260616_11_유재우
📝 과제 정보
📋 체크리스트
📷 실행 결과 (또는 테스트 결과)
클래스 다이어그램
❓질문 및 어려웠던 점
@DisplayName이 적용되지 않는 것처럼 보여 원인을 찾는 데 시간이 걸렸다.@DisplayName이 보이지 않았음을 확인했다.🔄 자체 평가 & 회고
Gradle Runner
IntelliJ Runner