Last active
June 14, 2020 08:19
-
-
Save harikrishnan83/ec39dc6edb689517a6bfd2f7918ba98f to your computer and use it in GitHub Desktop.
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
class HttpRequest(private val url: String, private val method: HttpMethod, private val body: String) { | |
fun matches(anotherRequest: HttpRequest): Result { | |
when (val result = matchUrl(anotherRequest)) { | |
is Failure -> return result | |
} | |
when (val result = matchMethod(anotherRequest)) { | |
is Failure -> return result | |
} | |
when (val result = matchBody(anotherRequest)) { | |
is Failure -> return result | |
} | |
return Success("everything matches") | |
} | |
private fun matchUrl(anotherRequest: HttpRequest): Result { | |
if (this.url != anotherRequest.url) | |
return Failure("URL did not match. ${this.url} not equal to ${anotherRequest.url}") | |
return Success("Url matches") | |
} | |
private fun matchMethod(anotherRequest: HttpRequest): Result { | |
if (this.body != anotherRequest.body) | |
return Failure("Method did not match. ${this.method} not equal to ${anotherRequest.method}") | |
return Success("Method matches") | |
} | |
private fun matchBody(anotherRequest: HttpRequest): Result { | |
if (this.body != anotherRequest.body) | |
return Failure("Body did not match. ${this.body} not equal to ${anotherRequest.body}") | |
return Success("Body matches") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment