How to write unit test for chat socket

I want to write a unit test for my class. i saw this also. My class is using socket. i init Chat.class first

chat = Chat.init(context);

then i called

chat.connect(String serverAddress, String appId, String severName);

after that i called getUserInfo.When i get the respond of this method then i called my chatListener.callOnUserInfo. I know that if i have a context i should use InstrumentedTest.

This is my test class

public class ExampleInstrumentedTest extends ChatAdapter {
    private static Chat chat;
    private static String TOKEN = "bebc31c4ead6458c90b607496dae25c6";
    private static ChatListener chatListener;
    private ChatAdapter chatAdapter;
    private static Context appContext;

public void useAppContext() {
    // Context of the app under test.
    appContext = InstrumentationRegistry.getTargetContext();
    assertEquals("com.fanap.podchat.test", appContext.getPackageName());

public static void init() {
    chat = Chat.init(appContext).addListener(chatListener);
            "Chat", "server", TOKEN, "",

public void getUserInfo() {