7feba9ade6a18b0a6f134e3bb198b54243e86ce5
[JavaForFun] /
1 package com.weather.information.test;
2
3 import android.content.Intent;
4 import android.widget.Button;
5
6 public class WeatherInformationActivityUnitTest extends
7         ActivityUnitTestCase<WeatherInformationActivity> {
8
9     private WeatherInformationActivity activity;
10
11     public WeatherInformationActivityUnitTest() {
12         super(WeatherInformationActivity.class);
13     }
14
15     @Override
16     protected void setUp() throws Exception {
17         super.setUp();
18         final Intent intent = new Intent(this.getInstrumentation().getTargetContext(),
19                 WeatherInformationActivity.class);
20         this.startActivity(intent, null, null);
21         this.activity = this.getActivity();
22     }
23
24     public void testIntentTriggerViaOnClick() {
25         final int buttonweather = com.weather.information.R.id.buttonweather;
26         final Button view = (Button) this.activity.findViewById(buttonweather);
27         assertNotNull("Button Weather not allowed to be null", view);
28
29         view.performClick();
30
31         // TouchUtils cannot be used, only allowed in
32         // InstrumentationTestCase or ActivityInstrumentationTestCase2
33
34         // Check the intent which was started
35         final Intent triggeredIntent = this.getStartedActivityIntent();
36         assertNotNull("Intent was null", triggeredIntent);
37         final String data = triggeredIntent.getDataString();
38
39         assertEquals("Incorrect data passed via the intent",
40                 "http://gumartinm.name", data);
41     }
42 }