Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/src/main/java/com/coderabbit/app/calculator/Car.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.coderabbit.app.calculator

class Car {

fun startEngine(): Boolean {
println("Engine is starting...")
return true
}

fun isEngineStarted(): Boolean {
// Simulate engine status
return true
}
}
Comment on lines +3 to +14

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make Car stateful and eliminate println side-effects

Both methods currently hardcode success and provide no observable state, which limits usefulness and testability. Model engine state and remove println side-effects.

Apply:

-class Car {
-
-    fun startEngine(): Boolean {
-        println("Engine is starting...")
-        return true
-    }
-
-    fun isEngineStarted(): Boolean {
-        // Simulate engine status
-        return true
-    }
-}
+class Car {
+    private var engineStarted: Boolean = false
+
+    fun startEngine(): Boolean {
+        if (engineStarted) return true // idempotent
+        // TODO: plug real start logic here
+        engineStarted = true
+        return true
+    }
+
+    fun isEngineStarted(): Boolean = engineStarted
+}
🤖 Prompt for AI Agents
In app/src/main/java/com/coderabbit/app/calculator/Car.kt from lines 3 to 14,
the Car class methods startEngine and isEngineStarted always return true and do
not maintain any engine state, plus startEngine uses println causing side
effects. Refactor the class to include a private Boolean property to track the
engine state, update this state in startEngine without printing anything, and
have isEngineStarted return the current state instead of a hardcoded value.

16 changes: 16 additions & 0 deletions app/src/test/java/com/coderabbit/app/calculator/CarTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.coderabbit.app.calculator

import org.junit.Assert.assertTrue


class CarTest {

fun startEngine() {
// Arrange
val car = Car()
// Act
val result = car.startEngine()
// Assert
assertTrue(result)
}
}