Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tests
Browse files Browse the repository at this point in the history
nikclayton committed Jan 23, 2025
1 parent 825a5b3 commit 31be2e1
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ class ApiResultCallTest {
val exception = (error as ClientError.NotFound).exception
assertThat(exception).isInstanceOf(HttpException::class.java)
assertThat(exception.code()).isEqualTo(404)
assertThat(error.formatArgs).isEqualTo(arrayOf("HTTP 404 Not Found: GET https://example.com/"))
assertThat(error.formatArgs).isEqualTo(arrayOf("HTTP 404 Not Found: GET /foo?x=1"))
}

override fun onFailure(call: Call<ApiResult<String>>, t: Throwable) {
@@ -189,7 +189,7 @@ class ApiResultCallTest {
val exception = (error as ClientError.NotFound).exception
assertThat(exception).isInstanceOf(HttpException::class.java)
assertThat(exception.code()).isEqualTo(404)
assertThat(error.formatArgs).isEqualTo(arrayOf("$errorMsg: GET https://example.com/"))
assertThat(error.formatArgs).isEqualTo(arrayOf("$errorMsg: GET /foo?x=1"))
}

override fun onFailure(call: Call<ApiResult<String>>, t: Throwable) {
@@ -218,7 +218,7 @@ class ApiResultCallTest {
val exception = (error as ClientError.NotFound).exception
assertThat(exception).isInstanceOf(HttpException::class.java)
assertThat(exception.code()).isEqualTo(404)
assertThat(error.formatArgs).isEqualTo(arrayOf("$errorMsg: $descriptionMsg: GET https://example.com/"))
assertThat(error.formatArgs).isEqualTo(arrayOf("$errorMsg: $descriptionMsg: GET /foo?x=1"))
}

override fun onFailure(call: Call<ApiResult<String>>, t: Throwable) {
@@ -241,7 +241,7 @@ class ApiResultCallTest {
assertThat(err).isInstanceOf(Err::class.java)
assertThat(err?.error?.request).isEqualTo(call.request())
assertThat(err?.error?.throwable).isEqualTo(exception)
assertThat(err?.error?.formatArgs).isEqualTo(arrayOf("GET https://example.com/"))
assertThat(err?.error?.formatArgs).isEqualTo(arrayOf("GET /foo?x=1"))
}

override fun onFailure(call: Call<ApiResult<String>>, t: Throwable) {
Original file line number Diff line number Diff line change
@@ -28,16 +28,19 @@ class TestCall<T> : Call<T> {
private var executed = false
private var canceled = false
private var callback: Callback<T>? = null
private var request = Request.Builder().url("https://example.com").build()

/**
* Request. Includes a path and query parameter to test that these are shown
* correctly in error messages.
*/
private var request = Request.Builder().url("https://example.com/foo?x=1").build()

fun completeWithException(t: Throwable) {
synchronized(this) {
callback?.onFailure(this, t)
}
}

fun complete(body: T): Unit = complete(Response.success(body))

fun complete(response: Response<T>) {
synchronized(this) {
callback?.onResponse(this, response)

0 comments on commit 31be2e1

Please sign in to comment.