Writing a MockWebServer test for GET("joke.json") fails on Android 9 and above

Dear Experts,

There is a problem in “Writing a MockWebServer test” section in Chapter 10 - Testing Network Layer.

When we try to run mock server test with GET(“joke.json”) URL it gives error below because CLEAR_TEXT communication it’s not permitted in API Level 28 and above → Details

How To Reproduce Issue
You can run test on an emulator Android 9 or above

@GET("joke.json")

It gives error:
java.lang.AssertionError: Error(s) present: [java.net.UnknownServiceException: CLEARTEXT communication to localhost not permitted by network security policy] (latch = 0, values = 0, errors = 1, completions = 0)

When you run this test on Android 8 and below, it runs successfully.

Regards