forked from upstream-mirrors/OpenTracks
Add test case for SendRequest.
Add test case for UploadServiceChooserActivity. Change some code in UploadServiceChooserActivity to make it testable.
This commit is contained in:
+19
-4
@@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.SystemUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
@@ -48,6 +49,7 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
private static final int SERVICE_PICKER_DIALOG = 1;
|
||||
|
||||
private SendRequest sendRequest;
|
||||
private Dialog dialog;
|
||||
|
||||
private TableRow mapsTableRow;
|
||||
private TableRow fusionTablesTableRow;
|
||||
@@ -80,7 +82,7 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
switch (id) {
|
||||
case SERVICE_PICKER_DIALOG:
|
||||
final Dialog dialog = new Dialog(this);
|
||||
dialog = new Dialog(this);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(R.layout.upload_service_chooser);
|
||||
dialog.setCancelable(true);
|
||||
@@ -146,7 +148,8 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
/**
|
||||
* Initializes the UI state based on the shared preferences.
|
||||
*/
|
||||
private void initState() {
|
||||
@VisibleForTesting
|
||||
void initState() {
|
||||
SharedPreferences prefs = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
boolean pickExistingMap = prefs.getBoolean(getString(R.string.pick_existing_map_key), false);
|
||||
|
||||
@@ -188,7 +191,8 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
/**
|
||||
* Saves the UI state to the shared preferences.
|
||||
*/
|
||||
private void saveState() {
|
||||
@VisibleForTesting
|
||||
void saveState() {
|
||||
SharedPreferences prefs = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(
|
||||
@@ -225,7 +229,8 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
/**
|
||||
* Starts the next activity, {@link AccountChooserActivity}.
|
||||
*/
|
||||
private void startNextActivity() {
|
||||
@VisibleForTesting
|
||||
protected void startNextActivity() {
|
||||
sendStats();
|
||||
sendRequest.setSendMaps(sendMaps());
|
||||
sendRequest.setSendFusionTables(sendFusionTables());
|
||||
@@ -256,4 +261,14 @@ public class UploadServiceChooserActivity extends Activity {
|
||||
tracker.dispatch();
|
||||
tracker.stop();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Dialog getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
SendRequest getSendRequest() {
|
||||
return sendRequest;
|
||||
}
|
||||
}
|
||||
|
||||
+333
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* 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.google.android.apps.mytracks.io.sendtogoogle;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link SendRequest}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class SendRequestTest extends AndroidTestCase {
|
||||
private SendRequest sendRequest;
|
||||
|
||||
final static private String ACCOUNTNAME = "testAccount1";
|
||||
final static private String ACCOUNTYPE = "testType1";
|
||||
final static private String MAPID = "mapId1";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
sendRequest = new SendRequest(1, true, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#getTrackId()}. The value should be set
|
||||
* to 1 when it is initialed in setup method.
|
||||
*/
|
||||
public void testGetTrackId() {
|
||||
assertEquals(1, sendRequest.getTrackId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isShowMaps()}. The value should be set
|
||||
* to true when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsShowMaps() {
|
||||
assertEquals(true, sendRequest.isShowMaps());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isShowFusionTables()}. The value should
|
||||
* be set to true when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsShowFusionTables() {
|
||||
assertEquals(true, sendRequest.isShowFusionTables());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isShowDocs()}. The value should be set
|
||||
* to true when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsShowDocs() {
|
||||
assertEquals(true, sendRequest.isShowDocs());
|
||||
}
|
||||
|
||||
public void testIsShowAll() {
|
||||
assertEquals(true, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, false, true, true);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, true, false, true);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, true, true, false);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, false, true, false);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
sendRequest = new SendRequest(1, false, false, false);
|
||||
assertEquals(false, sendRequest.isShowAll());
|
||||
}
|
||||
|
||||
public void testIsSendMaps() {
|
||||
assertEquals(false, sendRequest.isSendMaps());
|
||||
sendRequest.setSendMaps(true);
|
||||
assertEquals(true, sendRequest.isSendMaps());
|
||||
}
|
||||
|
||||
public void testIsSendFusionTables() {
|
||||
assertEquals(false, sendRequest.isSendFusionTables());
|
||||
sendRequest.setSendFusionTables(true);
|
||||
assertEquals(true, sendRequest.isSendFusionTables());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isSendDocs()}. The value should be set
|
||||
* to false which is its default value when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsSendDocs() {
|
||||
assertEquals(false, sendRequest.isSendDocs());
|
||||
sendRequest.setSendDocs(true);
|
||||
assertEquals(true, sendRequest.isSendDocs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isNewMap()}. The value should be set to
|
||||
* false which is its default value when it is initialed in setup method.
|
||||
*/
|
||||
public void testIsNewMap() {
|
||||
assertEquals(false, sendRequest.isNewMap());
|
||||
sendRequest.setNewMap(true);
|
||||
assertEquals(true, sendRequest.isNewMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#getAccount()}. The value should be set
|
||||
* to null which is its default value when it is initialed in setup method.
|
||||
*/
|
||||
public void testGetAccount() {
|
||||
assertEquals(null, sendRequest.getAccount());
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
sendRequest.setAccount(account);
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#getMapId()}. The value should be set to
|
||||
* null which is its default value when it is initialed in setup method.
|
||||
*/
|
||||
public void testGetMapId() {
|
||||
assertEquals(null, sendRequest.getMapId());
|
||||
sendRequest.setMapId("1");
|
||||
assertEquals("1", "1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isMapsSuccess()}. The value should be
|
||||
* set to false which is its default value when it is initialed in setup
|
||||
* method.
|
||||
*/
|
||||
public void testIsMapsSuccess() {
|
||||
assertEquals(false, sendRequest.isMapsSuccess());
|
||||
sendRequest.setMapsSuccess(true);
|
||||
assertEquals(true, sendRequest.isMapsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isFusionTablesSuccess()}. The value
|
||||
* should be set to false which is its default value when it is initialed in
|
||||
* setup method.
|
||||
*/
|
||||
public void testIsFusionTablesSuccess() {
|
||||
assertEquals(false, sendRequest.isFusionTablesSuccess());
|
||||
sendRequest.setFusionTablesSuccess(true);
|
||||
assertEquals(true, sendRequest.isFusionTablesSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isDocsSuccess()}. The value should be
|
||||
* set to false which is its default value when it is initialed in setup
|
||||
* method.
|
||||
*/
|
||||
public void testIsDocsSuccess() {
|
||||
assertEquals(false, sendRequest.isDocsSuccess());
|
||||
sendRequest.setDocsSuccess(true);
|
||||
assertEquals(true, sendRequest.isDocsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#SendRequest(Parcel in)} when all values are true.
|
||||
*/
|
||||
public void testCreateFromParcel_true() {
|
||||
Parcel sourceParcel = Parcel.obtain();
|
||||
sourceParcel.setDataPosition(0);
|
||||
sourceParcel.writeLong(2);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
sourceParcel.writeParcelable(account, 0);
|
||||
sourceParcel.writeString(MAPID);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.writeByte((byte) 1);
|
||||
sourceParcel.setDataPosition(0);
|
||||
sendRequest = SendRequest.CREATOR.createFromParcel(sourceParcel);
|
||||
assertEquals(2, sendRequest.getTrackId());
|
||||
assertEquals(true, sendRequest.isShowMaps());
|
||||
assertEquals(true, sendRequest.isShowFusionTables());
|
||||
assertEquals(true, sendRequest.isShowDocs());
|
||||
assertEquals(true, sendRequest.isSendMaps());
|
||||
assertEquals(true, sendRequest.isSendFusionTables());
|
||||
assertEquals(true, sendRequest.isSendDocs());
|
||||
assertEquals(true, sendRequest.isNewMap());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertEquals(MAPID, sendRequest.getMapId());
|
||||
assertEquals(true, sendRequest.isMapsSuccess());
|
||||
assertEquals(true, sendRequest.isFusionTablesSuccess());
|
||||
assertEquals(true, sendRequest.isDocsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#SendRequest(Parcel in)} when all values are false.
|
||||
*/
|
||||
public void testCreateFromParcel_false() {
|
||||
Parcel sourceParcel = Parcel.obtain();
|
||||
sourceParcel.setDataPosition(0);
|
||||
sourceParcel.writeLong(4);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
sourceParcel.writeParcelable(account, 0);
|
||||
sourceParcel.writeString(MAPID);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.writeByte((byte) 0);
|
||||
sourceParcel.setDataPosition(0);
|
||||
sendRequest = SendRequest.CREATOR.createFromParcel(sourceParcel);
|
||||
assertEquals(4, sendRequest.getTrackId());
|
||||
assertEquals(false, sendRequest.isShowMaps());
|
||||
assertEquals(false, sendRequest.isShowFusionTables());
|
||||
assertEquals(false, sendRequest.isShowDocs());
|
||||
assertEquals(false, sendRequest.isSendMaps());
|
||||
assertEquals(false, sendRequest.isSendFusionTables());
|
||||
assertEquals(false, sendRequest.isSendDocs());
|
||||
assertEquals(false, sendRequest.isNewMap());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertEquals(MAPID, sendRequest.getMapId());
|
||||
assertEquals(false, sendRequest.isMapsSuccess());
|
||||
assertEquals(false, sendRequest.isFusionTablesSuccess());
|
||||
assertEquals(false, sendRequest.isDocsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#writeToParcel(Parcel in)} when all input values
|
||||
* are true or affirmative.
|
||||
*/
|
||||
public void testWriteToParcel_allTrue() {
|
||||
sendRequest = new SendRequest(1, false, false, false);
|
||||
Parcel parcelWrite1st = Parcel.obtain();
|
||||
parcelWrite1st.setDataPosition(0);
|
||||
sendRequest.writeToParcel(parcelWrite1st, 1);
|
||||
parcelWrite1st.setDataPosition(0);
|
||||
long trackId = parcelWrite1st.readLong();
|
||||
boolean showMaps = parcelWrite1st.readByte() == 1;
|
||||
boolean showFusionTables = parcelWrite1st.readByte() == 1;
|
||||
boolean showDocs = parcelWrite1st.readByte() == 1;
|
||||
boolean sendMaps = parcelWrite1st.readByte() == 1;
|
||||
boolean sendFusionTables = parcelWrite1st.readByte() == 1;
|
||||
boolean sendDocs = parcelWrite1st.readByte() == 1;
|
||||
boolean newMap = parcelWrite1st.readByte() == 1;
|
||||
Parcelable account = parcelWrite1st.readParcelable(null);
|
||||
String mapId = parcelWrite1st.readString();
|
||||
boolean mapsSuccess = parcelWrite1st.readByte() == 1;
|
||||
boolean fusionTablesSuccess = parcelWrite1st.readByte() == 1;
|
||||
boolean docsSuccess = parcelWrite1st.readByte() == 1;
|
||||
assertEquals(1, trackId);
|
||||
assertEquals(false, showMaps);
|
||||
assertEquals(false, showFusionTables);
|
||||
assertEquals(false, showDocs);
|
||||
assertEquals(false, sendMaps);
|
||||
assertEquals(false, sendFusionTables);
|
||||
assertEquals(false, sendDocs);
|
||||
assertEquals(false, newMap);
|
||||
assertEquals(null, account);
|
||||
assertEquals(null, mapId);
|
||||
assertEquals(false, mapsSuccess);
|
||||
assertEquals(false, fusionTablesSuccess);
|
||||
assertEquals(false, docsSuccess);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#writeToParcel(Parcel in)} when all input values
|
||||
* are false or negative.
|
||||
*/
|
||||
public void testWriteToParcel_allFalse() {
|
||||
sendRequest = new SendRequest(4, true, true, true);
|
||||
sendRequest.setSendMaps(true);
|
||||
sendRequest.setSendFusionTables(true);
|
||||
sendRequest.setSendDocs(true);
|
||||
sendRequest.setNewMap(true);
|
||||
Account accountNew = new Account(ACCOUNTNAME + "2", ACCOUNTYPE + "2");
|
||||
sendRequest.setAccount(accountNew);
|
||||
sendRequest.setMapId(MAPID);
|
||||
sendRequest.setMapsSuccess(true);
|
||||
sendRequest.setFusionTablesSuccess(true);
|
||||
sendRequest.setDocsSuccess(true);
|
||||
Parcel parcelWrite2nd = Parcel.obtain();
|
||||
parcelWrite2nd.setDataPosition(0);
|
||||
sendRequest.writeToParcel(parcelWrite2nd, 1);
|
||||
parcelWrite2nd.setDataPosition(0);
|
||||
long trackId = parcelWrite2nd.readLong();
|
||||
boolean showMaps = parcelWrite2nd.readByte() == 1;
|
||||
boolean showFusionTables = parcelWrite2nd.readByte() == 1;
|
||||
boolean showDocs = parcelWrite2nd.readByte() == 1;
|
||||
boolean sendMaps = parcelWrite2nd.readByte() == 1;
|
||||
boolean sendFusionTables = parcelWrite2nd.readByte() == 1;
|
||||
boolean sendDocs = parcelWrite2nd.readByte() == 1;
|
||||
boolean newMap = parcelWrite2nd.readByte() == 1;
|
||||
Parcelable account = parcelWrite2nd.readParcelable(null);
|
||||
String mapId = parcelWrite2nd.readString();
|
||||
boolean mapsSuccess = parcelWrite2nd.readByte() == 1;
|
||||
boolean fusionTablesSuccess = parcelWrite2nd.readByte() == 1;
|
||||
boolean docsSuccess = parcelWrite2nd.readByte() == 1;
|
||||
assertEquals(4, trackId);
|
||||
assertEquals(true, showMaps);
|
||||
assertEquals(true, showFusionTables);
|
||||
assertEquals(true, showDocs);
|
||||
assertEquals(true, sendMaps);
|
||||
assertEquals(true, sendFusionTables);
|
||||
assertEquals(true, sendDocs);
|
||||
assertEquals(true, newMap);
|
||||
assertEquals(accountNew, account);
|
||||
assertEquals(MAPID, mapId);
|
||||
assertEquals(true, mapsSuccess);
|
||||
assertEquals(true, fusionTablesSuccess);
|
||||
assertEquals(true, docsSuccess);
|
||||
}
|
||||
|
||||
}
|
||||
+309
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* 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.google.android.apps.mytracks.io.sendtogoogle;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
/**
|
||||
* Tests the {@link UploadServiceChooserActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class UploadServiceChooserActivityTest extends
|
||||
ActivityInstrumentationTestCase2<UploadServiceChooserActivity> {
|
||||
|
||||
private Instrumentation instrumentation;
|
||||
private UploadServiceChooserActivity uploadServiceChooserActivity;
|
||||
|
||||
public UploadServiceChooserActivityTest() {
|
||||
super(UploadServiceChooserActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
instrumentation = getInstrumentation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to control display all send options. This test cover code
|
||||
* in method {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#updateStateBySendRequest()} and
|
||||
* {@link UploadServiceChooserActivity#updateStateBySelection()}.
|
||||
*/
|
||||
public void testOnCreateDialog_displayAll() {
|
||||
// Initials activity to display all send items.
|
||||
initialActivity(true, true, true);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getFusionTablesCheckBox().isShown());
|
||||
assertTrue(getDocsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
// Clicks to disable all send items.
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (getMapsCheckBox().isChecked()) {
|
||||
getMapsCheckBox().performClick();
|
||||
}
|
||||
if (getFusionTablesCheckBox().isChecked()) {
|
||||
getFusionTablesCheckBox().performClick();
|
||||
}
|
||||
if (getDocsCheckBox().isChecked()) {
|
||||
getDocsCheckBox().performClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getFusionTablesCheckBox().isShown());
|
||||
assertTrue(getDocsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
assertFalse(getNewMapRadioButton().isShown());
|
||||
assertFalse(getExistingMapRadioButton().isShown());
|
||||
assertFalse(getSendButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to check the send to Google Maps option. This test cover
|
||||
* code in method {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#updateStateBySendRequest()} and
|
||||
* {@link UploadServiceChooserActivity#updateStateBySelection()}.
|
||||
*/
|
||||
public void testOnCreateDialog_displayOne() {
|
||||
// Initials activity to display all send items.
|
||||
initialActivity(true, false, false);
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
|
||||
// Clicks to enable this items.
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (!getMapsCheckBox().isChecked()) {
|
||||
getMapsCheckBox().performClick();
|
||||
}
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isShown());
|
||||
assertTrue(getNewMapRadioButton().isShown());
|
||||
assertTrue(getExistingMapRadioButton().isShown());
|
||||
assertTrue(getSendButton().isEnabled());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to control display none. This test cover code in method
|
||||
* {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#updateStateBySendRequest()} and
|
||||
* {@link UploadServiceChooserActivity#updateStateBySelection()}.
|
||||
*/
|
||||
public void testOnCreateDialog_displayNone() {
|
||||
initialActivity(false, false, false);
|
||||
assertFalse(getMapsCheckBox().isShown());
|
||||
assertFalse(getFusionTablesCheckBox().isShown());
|
||||
assertFalse(getDocsCheckBox().isShown());
|
||||
assertFalse(getSendButton().isEnabled());
|
||||
assertTrue(getCancelButton().isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to initial state of check box to unchecked. This test cover
|
||||
* code in method {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#initState()}.
|
||||
*/
|
||||
public void testOnCreateDialog_initStateUnchecked() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to false in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), false);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
false);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), false);
|
||||
editor.commit();
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertFalse(getMapsCheckBox().isChecked());
|
||||
assertFalse(getFusionTablesCheckBox().isChecked());
|
||||
assertFalse(getDocsCheckBox().isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic to initial state of check box to checked. This test cover
|
||||
* code in method {@link UploadServiceChooserActivity#onCreateDialog()},
|
||||
* {@link UploadServiceChooserActivity#initState()}.
|
||||
*/
|
||||
public void testOnCreateDialog_initStateChecked() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.pick_existing_map_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.commit();
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertTrue(getMapsCheckBox().isChecked());
|
||||
assertTrue(getFusionTablesCheckBox().isChecked());
|
||||
assertTrue(getDocsCheckBox().isChecked());
|
||||
assertTrue(getExistingMapRadioButton().isChecked());
|
||||
|
||||
assertFalse(getNewMapRadioButton().isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic of saveState when click send button. This test cover code
|
||||
* in method {@link UploadServiceChooserActivity#saveState()},
|
||||
* {@link UploadServiceChooserActivity#initState()} ,
|
||||
* {@link UploadServiceChooserActivity#sendMaps()},
|
||||
* {@link UploadServiceChooserActivity#sendFusionTables()}, and
|
||||
* {@link UploadServiceChooserActivity#sendDocs()}.
|
||||
*/
|
||||
public void testOnCreateDialog_saveState() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.commit();
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
uploadServiceChooserActivity.saveState();
|
||||
// All values in SharedPreferences must be changed.
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the logic of startNextActivity when click send button. This test
|
||||
* cover code in method
|
||||
* {@link UploadServiceChooserActivity#startNextActivity()} ,
|
||||
* {@link UploadServiceChooserActivity#initState()} ,
|
||||
* {@link UploadServiceChooserActivity#sendMaps()},
|
||||
* {@link UploadServiceChooserActivity#sendFusionTables()}, and
|
||||
* {@link UploadServiceChooserActivity#sendDocs()}.
|
||||
*/
|
||||
public void testOnCreateDialog_startNextActivity() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true or false in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
false);
|
||||
editor.commit();
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
uploadServiceChooserActivity.startNextActivity();
|
||||
// All values in SendRequest must be same as set above.
|
||||
assertTrue(uploadServiceChooserActivity.getSendRequest().isSendMaps());
|
||||
assertTrue(uploadServiceChooserActivity.getSendRequest().isSendDocs());
|
||||
|
||||
assertFalse(uploadServiceChooserActivity.getSendRequest().isSendFusionTables());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initials a activity to be tested.
|
||||
*
|
||||
* @param showMaps
|
||||
* @param showFusionTables
|
||||
* @param showDocs
|
||||
*/
|
||||
private void initialActivity(boolean showMaps, boolean showFusionTables, boolean showDocs) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(SendRequest.SEND_REQUEST_KEY, new SendRequest(1L, showMaps, showFusionTables,
|
||||
showDocs));
|
||||
setActivityIntent(intent);
|
||||
uploadServiceChooserActivity = this.getActivity();
|
||||
}
|
||||
|
||||
private Button getSendButton() {
|
||||
return (Button) uploadServiceChooserActivity.getDialog()
|
||||
.findViewById(R.id.send_google_send_now);
|
||||
}
|
||||
|
||||
Button getCancelButton() {
|
||||
return (Button) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_cancel);
|
||||
}
|
||||
|
||||
private CheckBox getMapsCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_maps);
|
||||
}
|
||||
|
||||
private CheckBox getFusionTablesCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
R.id.send_google_fusion_tables);
|
||||
}
|
||||
|
||||
private CheckBox getDocsCheckBox() {
|
||||
return (CheckBox) uploadServiceChooserActivity.getDialog().findViewById(R.id.send_google_docs);
|
||||
}
|
||||
|
||||
private RadioButton getNewMapRadioButton() {
|
||||
return (RadioButton) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
R.id.send_google_new_map);
|
||||
}
|
||||
|
||||
private RadioButton getExistingMapRadioButton() {
|
||||
return (RadioButton) uploadServiceChooserActivity.getDialog().findViewById(
|
||||
R.id.send_google_existing_map);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user