Skip to content

Commit

Permalink
Make MaestroCommand toString more concise (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
tokou authored Sep 3, 2024
1 parent c95fe9d commit 022840f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,10 @@ data class MaestroCommand(
fun description(): String {
return asCommand()?.description() ?: "No op"
}

override fun toString(): String =
asCommand()?.let { command ->
val argName = command::class.simpleName?.replaceFirstChar(Char::lowercaseChar) ?: "command"
"MaestroCommand($argName=$command)"
} ?: "MaestroCommand()"
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,29 @@ internal class MaestroCommandTest {
assertThat(description)
.isEqualTo("Set location with negative coordinates")
}

@Test
fun `toString (no commands)`() {
// given
val maestroCommand = MaestroCommand(null)

// when
val toString = maestroCommand.toString()

// then
assertThat(toString).isEqualTo("MaestroCommand()")
}

@Test
fun `toString (at least one command)`() {
// given
val command = BackPressCommand()
val maestroCommand = MaestroCommand(command)

// when
val toString = maestroCommand.toString()

// then
assertThat(toString).isEqualTo("MaestroCommand(backPressCommand=$command)")
}
}

0 comments on commit 022840f

Please sign in to comment.