2 * Copyright 2014 Gustavo Martin Morcuende
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package name.gumartinm.weather.information.test;
18 import android.content.Intent;
19 import android.widget.Button;
21 public class WeatherInformationActivityUnitTest extends
22 ActivityUnitTestCase<WeatherInformationActivity> {
24 private WeatherInformationActivity activity;
26 public WeatherInformationActivityUnitTest() {
27 super(WeatherInformationActivity.class);
31 protected void setUp() throws Exception {
33 final Intent intent = new Intent(this.getInstrumentation().getTargetContext(),
34 WeatherInformationActivity.class);
35 this.startActivity(intent, null, null);
36 this.activity = this.getActivity();
39 public void testIntentTriggerViaOnClick() {
40 final int buttonweather = name.gumartinm.weather.information.R.id.buttonweather;
41 final Button view = (Button) this.activity.findViewById(buttonweather);
42 assertNotNull("Button Weather not allowed to be null", view);
46 // TouchUtils cannot be used, only allowed in
47 // InstrumentationTestCase or ActivityInstrumentationTestCase2
49 // Check the intent which was started
50 final Intent triggeredIntent = this.getStartedActivityIntent();
51 assertNotNull("Intent was null", triggeredIntent);
52 final String data = triggeredIntent.getDataString();
54 assertEquals("Incorrect data passed via the intent",
55 "http://gumartinm.name", data);