feat(paint-calculator): add round room support with shape selection menu#22
feat(paint-calculator): add round room support with shape selection menu#22durimkryeziu wants to merge 6 commits into
Conversation
…angularRoom and RoundRoom
…separate files with permits clause
…nsions; PaintCalculator updated to use RectangularRoom
… for shape menu support
📝 WalkthroughWalkthroughThe PR extends the paint calculator to support round rooms in addition to rectangular rooms by introducing a sealed interface-based type hierarchy and refactoring the user input flow to let users select room shape before entering dimensions. ChangesRoom dimension type abstraction
Calculator shape-selection refactoring
Sequence Diagram(s)sequenceDiagram
participant User
participant Calculator
participant Estimator
User->>Calculator: Provide shape (1 or 2) + dimensions
Calculator->>Calculator: Display shape menu
Calculator->>Calculator: Parse user shape choice
alt shape == 1
Calculator->>Calculator: readRectangularDimensions()
else shape == 2
Calculator->>Calculator: readRoundDimensions()
end
Calculator->>Estimator: Invoke with RoomDimensions
Estimator->>Calculator: Return PaintEstimate
Calculator->>User: Print purchase message
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #22 +/- ##
============================================
+ Coverage 77.41% 77.85% +0.43%
- Complexity 116 120 +4
============================================
Files 33 34 +1
Lines 403 420 +17
Branches 24 25 +1
============================================
+ Hits 312 327 +15
- Misses 84 85 +1
- Partials 7 8 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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
`@paint-calculator/src/test/java/dev/delivercraft/paint/PaintCalculatorTest.java`:
- Around line 152-162: Add unit tests that assert PaintCalculator.calculatePaint
throws IllegalArgumentException for invalid shape input: create tests using
StubLineReader and CapturingLineWriter to pass values like "3","0","abc","", "
" (use a `@ParameterizedTest` with `@ValueSource`) and a separate test for a null
input, then
assertThatIllegalArgumentException().isThrownBy(calculator::calculatePaint).withMessage("Please
enter 1 or 2"); also assert the CapturingLineWriter contains only SHAPE_MENU +
System.lineSeparator() before the exception is thrown to verify prompt output.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0c9e3205-4819-4d22-8536-9d505964ee7d
📒 Files selected for processing (8)
paint-calculator/src/main/java/dev/delivercraft/paint/PaintCalculator.javapaint-calculator/src/main/java/dev/delivercraft/paint/RectangularRoom.javapaint-calculator/src/main/java/dev/delivercraft/paint/RoomDimensions.javapaint-calculator/src/main/java/dev/delivercraft/paint/RoundRoom.javapaint-calculator/src/test/java/dev/delivercraft/paint/MainTest.javapaint-calculator/src/test/java/dev/delivercraft/paint/PaintCalculatorTest.javapaint-calculator/src/test/java/dev/delivercraft/paint/PaintEstimatorTest.javapaint-calculator/src/test/java/dev/delivercraft/paint/RoundRoomTest.java
| @Test | ||
| void calculatePaint_GivenRoundRoomSelection_ShouldCalculateCorrectArea() { | ||
| LineWriter lineWriter = new CapturingLineWriter(); | ||
| PaintCalculator calculator = new PaintCalculator(new StubLineReader("2", "10"), lineWriter); | ||
|
|
||
| calculator.calculatePaint(); | ||
|
|
||
| String output = lineWriter.toString(); | ||
| assertThat(output).startsWith(SHAPE_MENU + System.lineSeparator() + RADIUS_PROMPT); | ||
| assertThat(output).contains("You will need to purchase 1 gallon of paint to cover"); | ||
| } |
There was a problem hiding this comment.
Add test coverage for invalid shape selection.
The new shape-selection logic correctly throws IllegalArgumentException for invalid input, but there's no explicit test verifying this behavior. Consider adding a test case to document expected behavior and prevent regressions.
🧪 Suggested test case
`@ParameterizedTest`
`@ValueSource`(strings = {"3", "0", "abc", "", " "})
void calculatePaint_GivenInvalidShapeSelection_ShouldThrowException(String invalidShape) {
LineWriter lineWriter = new CapturingLineWriter();
PaintCalculator calculator = new PaintCalculator(
new StubLineReader(invalidShape), lineWriter);
assertThatIllegalArgumentException()
.isThrownBy(calculator::calculatePaint)
.withMessage("Please enter 1 or 2");
assertThat(lineWriter).hasToString(SHAPE_MENU + System.lineSeparator());
}
`@Test`
void calculatePaint_GivenNullShapeSelection_ShouldThrowException() {
LineWriter lineWriter = new CapturingLineWriter();
PaintCalculator calculator = new PaintCalculator(
new StubLineReader((String) null), lineWriter);
assertThatIllegalArgumentException()
.isThrownBy(calculator::calculatePaint)
.withMessage("Please enter 1 or 2");
}🤖 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
`@paint-calculator/src/test/java/dev/delivercraft/paint/PaintCalculatorTest.java`
around lines 152 - 162, Add unit tests that assert
PaintCalculator.calculatePaint throws IllegalArgumentException for invalid shape
input: create tests using StubLineReader and CapturingLineWriter to pass values
like "3","0","abc","", " " (use a `@ParameterizedTest` with `@ValueSource`) and a
separate test for a null input, then
assertThatIllegalArgumentException().isThrownBy(calculator::calculatePaint).withMessage("Please
enter 1 or 2"); also assert the CapturingLineWriter contains only SHAPE_MENU +
System.lineSeparator() before the exception is thrown to verify prompt output.
Summary
RoomDimensionsinterface withRectangularRoomandRoundRoomimplementing recordsPaintCalculator(1=Rectangular, 2=Round)PaintEstimatorto work polymorphically with sealed interfaceRoundRoomTestwith nested JUnit test classesTest Plan
Changes
RoomDimensions.java— sealed interface withpermitsclauseRectangularRoom.java— extracted record implementing sealed interfaceRoundRoom.java— new circular room record (πr² area calculation)PaintCalculator.java— menu-driven shape selection with switch expressionPaintCalculatorTest.java— updated for menu flow, added round room testRoundRoomTest.java— new test class with area, validation, and paint estimation nested testsMainTest.java— updated input to include shape selectionSummary by CodeRabbit
Release Notes