Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2015 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 com.example.android.nfcprovisioning.tests;
     18 
     19 import android.test.ActivityInstrumentationTestCase2;
     20 import android.text.TextUtils;
     21 import android.view.View;
     22 import android.widget.EditText;
     23 
     24 import com.example.android.nfcprovisioning.MainActivity;
     25 import com.example.android.nfcprovisioning.NfcProvisioningFragment;
     26 import com.example.android.nfcprovisioning.R;
     27 
     28 /**
     29  * Tests for NfcProvisioning sample.
     30  */
     31 public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> {
     32 
     33     private MainActivity mTestActivity;
     34     private NfcProvisioningFragment mTestFragment;
     35 
     36     public SampleTests() {
     37         super(MainActivity.class);
     38     }
     39 
     40     @Override
     41     protected void setUp() throws Exception {
     42         super.setUp();
     43 
     44         // Starts the activity under test using the default Intent with:
     45         // action = {@link Intent#ACTION_MAIN}
     46         // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK}
     47         // All other fields are null or empty.
     48         mTestActivity = getActivity();
     49         mTestFragment = (NfcProvisioningFragment)
     50                 mTestActivity.getSupportFragmentManager().getFragments().get(1);
     51     }
     52 
     53     /**
     54      * Test if the test fixture has been set up correctly.
     55      */
     56     public void testPreconditions() {
     57         //Try to add a message to add context to your assertions. These messages will be shown if
     58         //a tests fails and make it easy to understand why a test failed
     59         assertNotNull("mTestActivity is null", mTestActivity);
     60         assertNotNull("mTestFragment is null", mTestFragment);
     61     }
     62 
     63     public void testEditTexts() {
     64         View view = mTestFragment.getView();
     65         assertNotNull(view);
     66         // Check that we have all the EditTexts on the Fragment
     67         EditText locale = (EditText) view.findViewById(R.id.locale);
     68         assertNotNull(locale);
     69         EditText timezone = (EditText) view.findViewById(R.id.timezone);
     70         assertNotNull(timezone);
     71         EditText wifiSsid = (EditText) view.findViewById(R.id.wifi_ssid);
     72         assertNotNull(wifiSsid);
     73         EditText wifiPassword = (EditText) view.findViewById(R.id.wifi_password);
     74         assertNotNull(wifiPassword);
     75         // These EditTexts should be filled with some default values
     76         assertFalse(TextUtils.isEmpty(locale.getText().toString()));
     77         assertFalse(TextUtils.isEmpty(timezone.getText().toString()));
     78     }
     79 
     80 }
     81