Home | History | Annotate | Download | only in widget
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      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
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     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.
     15  */
     16 
     17 package android.widget;
     18 
     19 import com.android.frameworks.coretests.R;
     20 
     21 import android.test.ActivityInstrumentationTestCase2;
     22 import android.test.TouchUtils;
     23 import android.test.suitebuilder.annotation.LargeTest;
     24 import android.test.suitebuilder.annotation.MediumTest;
     25 
     26 /**
     27  * Exercises {@link android.widget.RadioGroup}'s check feature.
     28  */
     29 public class RadioGroupPreCheckedTest extends ActivityInstrumentationTestCase2<RadioGroupActivity> {
     30     public RadioGroupPreCheckedTest() {
     31         super(RadioGroupActivity.class);
     32     }
     33 
     34     @MediumTest
     35     public void testRadioButtonPreChecked() throws Exception {
     36         final RadioGroupActivity activity = getActivity();
     37 
     38         RadioButton radio = (RadioButton) activity.findViewById(R.id.value_one);
     39         assertTrue("The first radio button should be checked", radio.isChecked());
     40 
     41         RadioGroup group = (RadioGroup) activity.findViewById(R.id.group);
     42         assertEquals("The first radio button should be checked", R.id.value_one,
     43                 group.getCheckedRadioButtonId());
     44     }
     45 
     46     @LargeTest
     47     public void testRadioButtonChangePreChecked() throws Exception {
     48         final RadioGroupActivity activity = getActivity();
     49 
     50         RadioButton radio = (RadioButton) activity.findViewById(R.id.value_two);
     51         TouchUtils.clickView(this, radio);
     52 
     53         RadioButton old = (RadioButton) activity.findViewById(R.id.value_one);
     54 
     55         assertFalse("The first radio button should not be checked", old.isChecked());
     56         assertTrue("The second radio button should be checked", radio.isChecked());
     57 
     58         RadioGroup group = (RadioGroup) activity.findViewById(R.id.group);
     59         assertEquals("The second radio button should be checked", R.id.value_two,
     60                 group.getCheckedRadioButtonId());
     61     }
     62 }
     63