Created
June 16, 2019 12:20
-
-
Save automationhacks/405294314f01550fa6b155acabf82da1 to your computer and use it in GitHub Desktop.
Refactored Name Parser file with use of Data classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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