/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.email.activity.setup; import com.android.email.Account; import com.android.email.R; import android.content.Intent; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.MediumTest; import android.widget.Button; /** * Tests of basic UI logic in the AccountSetupNamesTest screen. */ @MediumTest public class AccountSetupNamesTests extends ActivityInstrumentationTestCase2<AccountSetupNames> { private AccountSetupNames mActivity; private Button mDoneButton; public AccountSetupNamesTests() { super("com.android.email", AccountSetupNames.class); } /** * Test a "good" account name (enables the button) */ public void testGoodAccountName() { Intent i = getTestIntent("GoodName"); this.setActivityIntent(i); getActivityAndFields(); assertTrue(mDoneButton.isEnabled()); } /** * Test a "bad" account name (disables the button) */ public void testBadAccountName() { Intent i = getTestIntent(""); this.setActivityIntent(i); getActivityAndFields(); assertFalse(mDoneButton.isEnabled()); } /** * Get the activity (which causes it to be started, using our intent) and get the UI fields */ private void getActivityAndFields() { mActivity = getActivity(); mDoneButton = (Button) mActivity.findViewById(R.id.done); } /** * Create an intent with the Account in it */ private Intent getTestIntent(String name) { Account account = new Account(this.getInstrumentation().getTargetContext()); account.setName(name); Intent i = new Intent(Intent.ACTION_MAIN); i.putExtra("account", account); // AccountSetupNames.EXTRA_ACCOUNT == "account" return i; } }