Skip to content

Instantly share code, notes, and snippets.

@harikrishnan83
Last active June 14, 2020 08:19
Show Gist options
  • Save harikrishnan83/ec39dc6edb689517a6bfd2f7918ba98f to your computer and use it in GitHub Desktop.
Save harikrishnan83/ec39dc6edb689517a6bfd2f7918ba98f to your computer and use it in GitHub Desktop.
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