Skip to content

Instantly share code, notes, and snippets.

@automationhacks
Created June 16, 2019 12:20
Show Gist options
  • Save automationhacks/405294314f01550fa6b155acabf82da1 to your computer and use it in GitHub Desktop.
Save automationhacks/405294314f01550fa6b155acabf82da1 to your computer and use it in GitHub Desktop.
Refactored Name Parser file with use of Data classes
package _02_dataClasses
import org.testng.Assert
class FullName(val first: String,
val last: String)
fun parseName(name: String): FullName {
val space = name.indexOf(' ')
return FullName(
name.substring(0, space),
name.substring(space + 1))
}
fun main(args: Array<String>) {
val name = parseName("Jane Doe")
val first = name.first
val last = name.last
println("$first $last")
Assert.assertEquals(first, "Jane")
Assert.assertEquals(last, "Doe")
if (name != parseName("Jane Doe"))
println("Equals does not work...")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment