@@ -8,6 +8,7 @@ import org.junit.Assert.assertEquals
88import org.junit.Assert.assertTrue
99import org.junit.Test
1010import kotlin.test.assertFailsWith
11+ import kotlin.test.assertIs
1112
1213class ApiResponseExtensionsTest {
1314
@@ -26,45 +27,48 @@ class ApiResponseExtensionsTest {
2627 }
2728
2829 @Test
29- fun emitApiResponse_onFailure_throwsException () = runTest {
30+ fun emitApiResponse_onFailure_throwsUnprocessableError () = runTest {
3031 val response = ApiResponse .Failure .Exception (Exception (" network error" ))
31- assertFailsWith<Exception > {
32+ val exception = assertFailsWith<ApiException . UnprocessableError > {
3233 flow { emitApiResponse<String >(response) }.first()
3334 }
35+ assertEquals(" network error" , exception.rawMessage)
3436 }
3537
3638 @Test
37- fun emitApiResponse_withTransform_onFailure_throwsException () = runTest {
39+ fun emitApiResponse_withTransform_onFailure_throwsUnprocessableError () = runTest {
3840 val response = ApiResponse .Failure .Exception (Exception (" network error" ))
39- assertFailsWith<Exception > {
41+ val exception = assertFailsWith<ApiException . UnprocessableError > {
4042 flow { emitApiResponse<String , Boolean >(response) { true } }.first()
4143 }
44+ assertEquals(" network error" , exception.rawMessage)
4245 }
4346
4447 @Test
45- fun throwApiError_includesErrorMessageInException () {
48+ fun throwApiError_throwsUnprocessableError_withMessage () {
4649 val response: ApiResponse <String > = ApiResponse .Failure .Exception (Exception (" timeout" ))
47- val exception = assertFailsWith<Exception > {
50+ val exception = assertFailsWith<ApiException . UnprocessableError > {
4851 throwApiError(response, " timeout" )
4952 }
53+ assertEquals(" timeout" , exception.rawMessage)
5054 assertEquals(" Not processable error(timeout)." , exception.message)
5155 }
5256
5357 @Test
54- fun emitApiResponse_onFailure_exceptionContainsNotProcessableError () = runTest {
58+ fun emitApiResponse_onFailure_exceptionIsApiException () = runTest {
5559 val response: ApiResponse <String > = ApiResponse .Failure .Exception (Exception (" server error" ))
56- val exception = assertFailsWith<Exception > {
60+ val exception = assertFailsWith<ApiException > {
5761 flow { emitApiResponse<String >(response) }.first()
5862 }
59- assertTrue(exception.message !! .contains( " Not processable error " ) )
63+ assertIs< ApiException . UnprocessableError >(exception )
6064 }
6165
6266 @Test
63- fun emitApiResponse_withTransform_onFailure_exceptionContainsNotProcessableError () = runTest {
67+ fun emitApiResponse_withTransform_onFailure_exceptionIsApiException () = runTest {
6468 val response: ApiResponse <String > = ApiResponse .Failure .Exception (Exception (" server error" ))
65- val exception = assertFailsWith<Exception > {
69+ val exception = assertFailsWith<ApiException > {
6670 flow { emitApiResponse<String , Boolean >(response) { true } }.first()
6771 }
68- assertTrue(exception.message !! .contains( " Not processable error " ) )
72+ assertIs< ApiException . UnprocessableError >(exception )
6973 }
7074}
0 commit comments