jeudi 25 août 2016

Unit Testing on a Xmpp Android app on Android Studio

I'm trying to code some unit test for some OnCreate() methode on my XMPP app on android Studio, the problem is that i have never done that and i'm a little bit lost.

Here is my methode :

public class ChatActivity extends AppCompatActivity { private static final String TAG ="ChatActivity";

private String contactJid;
private ChatView mChatView;
private SendButton mSendButton;
private BroadcastReceiver mBroadcastReceiver;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    mChatView =(ChatView) findViewById(R.id.rooster_chat_view);
    mChatView.setEventListener(new ChatViewEventListener() {
        @Override
        public void userIsTyping() {
            //Here you know that the user is typing
        }

        @Override
        public void userHasStoppedTyping() {
            //Here you know that the user has stopped typing.
        }
    });

    mSendButton = mChatView.getSendButton();
    mSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //Only send the message if the client is connected
            //to the server.

            if (RoosterConnectionService.getState().equals(RoosterConnection.ConnectionState.CONNECTED)) {
                Log.d(TAG, "The client is connected to the server,Sending Message");
                //Send the message to the server

                Intent intent = new Intent(RoosterConnectionService.SEND_MESSAGE);
                intent.putExtra(RoosterConnectionService.BUNDLE_MESSAGE_BODY,
                        mChatView.getTypedString());
                intent.putExtra(RoosterConnectionService.BUNDLE_TO, contactJid);

                sendBroadcast(intent);

                //Update the chat view.
                mChatView.sendMessage();
            } else if (RoosterConnectionService.getState().equals(RoosterConnection.ConnectionState.DISCONNECTED)){
                Toast.makeText(getApplicationContext(),
                        "Client not connected to server ,Message not sent!",
                        Toast.LENGTH_LONG).show();
            }
        }
    });

    Intent intent = getIntent();
    contactJid = intent.getStringExtra("EXTRA_CONTACT_JID");
    setTitle(contactJid);
}

Aucun commentaire:

Enregistrer un commentaire