forked from upstream-mirrors/OpenTracks
Fix test error.
This commit is contained in:
+347
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
private static final String MAPS_SHARE_PACKAGE_NAME = "package";
|
||||
private static final String MAPS_SHARE_CLASS_NAME = "class";
|
||||
private final static String ACCOUNTNAME = "testAccount1";
|
||||
private final static String ACCOUNTYPE = "testType1";
|
||||
private final static String MAPS_EXISTING_MAP_ID = "mapId1";
|
||||
private final static String DRIVE_SHARE_EMAILS = "foo@foo.com";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
sendRequest = new SendRequest(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
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#isSendSpreadsheets()}. The value should
|
||||
* be set to false which is its default value when it is initialed in setup
|
||||
* method.
|
||||
*/
|
||||
public void testIsSendSpreadsheets() {
|
||||
assertEquals(false, sendRequest.isSendSpreadsheets());
|
||||
sendRequest.setSendSpreadsheets(true);
|
||||
assertEquals(true, sendRequest.isSendSpreadsheets());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link SendRequest#isMapsExistingMap()}. 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.isMapsExistingMap());
|
||||
sendRequest.setMapsExistingMap(true);
|
||||
assertEquals(true, sendRequest.isMapsExistingMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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#getMapsExistingMapId()}. The value
|
||||
* should be set to null which is its default value when it is initialed in
|
||||
* setup method.
|
||||
*/
|
||||
public void testGetMapsExistingMapId() {
|
||||
assertEquals(null, sendRequest.getMapsExistingMapId());
|
||||
sendRequest.setMapsExistingMapId("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#isSpreadsheetsSuccess()}. The value
|
||||
* should be set to false which is its default value when it is initialed in
|
||||
* setup method.
|
||||
*/
|
||||
public void testIsSpreadsheetsSuccess() {
|
||||
assertEquals(false, sendRequest.isSpreadsheetsSuccess());
|
||||
sendRequest.setSpreadsheetsSuccess(true);
|
||||
assertEquals(true, sendRequest.isSpreadsheetsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests SendRequest.CREATOR.createFromParcel when all values are true.
|
||||
*/
|
||||
public void testCreateFromParcel_true() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.setDataPosition(0);
|
||||
parcel.writeLong(2);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString(DRIVE_SHARE_EMAILS);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString("");
|
||||
parcel.writeString("");
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString(MAPS_EXISTING_MAP_ID);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
parcel.writeParcelable(account, 0);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.setDataPosition(0);
|
||||
sendRequest = SendRequest.CREATOR.createFromParcel(parcel);
|
||||
assertEquals(2, sendRequest.getTrackId());
|
||||
assertTrue(sendRequest.isSendDrive());
|
||||
assertTrue(sendRequest.isSendMaps());
|
||||
assertTrue(sendRequest.isSendFusionTables());
|
||||
assertTrue(sendRequest.isSendSpreadsheets());
|
||||
assertTrue(sendRequest.isDriveEnableSync());
|
||||
assertTrue(sendRequest.isDriveShare());
|
||||
assertEquals(DRIVE_SHARE_EMAILS, sendRequest.getDriveShareEmails());
|
||||
assertTrue(sendRequest.isMapsShare());
|
||||
assertEquals("", sendRequest.getMapsSharePackageName());
|
||||
assertEquals("", sendRequest.getMapsShareClassName());
|
||||
assertTrue(sendRequest.isMapsExistingMap());
|
||||
assertEquals(MAPS_EXISTING_MAP_ID, sendRequest.getMapsExistingMapId());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertTrue(sendRequest.isDriveSuccess());
|
||||
assertTrue(sendRequest.isMapsSuccess());
|
||||
assertTrue(sendRequest.isFusionTablesSuccess());
|
||||
assertTrue(sendRequest.isSpreadsheetsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests SendRequest.CREATOR.createFromParcel when all values are false.
|
||||
*/
|
||||
public void testCreateFromParcel_false() {
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.setDataPosition(0);
|
||||
parcel.writeLong(4);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(null);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(null);
|
||||
parcel.writeString(null);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(MAPS_EXISTING_MAP_ID);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
parcel.writeParcelable(account, 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.setDataPosition(0);
|
||||
sendRequest = SendRequest.CREATOR.createFromParcel(parcel);
|
||||
assertEquals(4, sendRequest.getTrackId());
|
||||
assertFalse(sendRequest.isSendDrive());
|
||||
assertFalse(sendRequest.isSendMaps());
|
||||
assertFalse(sendRequest.isSendFusionTables());
|
||||
assertFalse(sendRequest.isSendSpreadsheets());
|
||||
assertFalse(sendRequest.isDriveEnableSync());
|
||||
assertFalse(sendRequest.isDriveShare());
|
||||
assertNull(sendRequest.getDriveShareEmails());
|
||||
assertFalse(sendRequest.isMapsShare());
|
||||
assertNull(sendRequest.getMapsSharePackageName());
|
||||
assertNull(sendRequest.getMapsShareClassName());
|
||||
assertFalse(sendRequest.isMapsExistingMap());
|
||||
assertEquals(MAPS_EXISTING_MAP_ID, sendRequest.getMapsExistingMapId());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertFalse(sendRequest.isDriveSuccess());
|
||||
assertFalse(sendRequest.isMapsSuccess());
|
||||
assertFalse(sendRequest.isFusionTablesSuccess());
|
||||
assertFalse(sendRequest.isSpreadsheetsSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#writeToParcel(Parcel, int)} with default values.
|
||||
*/
|
||||
public void testWriteToParcel_default() {
|
||||
sendRequest = new SendRequest(1);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.setDataPosition(0);
|
||||
sendRequest.writeToParcel(parcel, 1);
|
||||
parcel.setDataPosition(0);
|
||||
long trackId = parcel.readLong();
|
||||
boolean sendDrive = parcel.readByte() == 1;
|
||||
boolean sendMaps = parcel.readByte() == 1;
|
||||
boolean sendFusionTables = parcel.readByte() == 1;
|
||||
boolean sendSpreadsheets = parcel.readByte() == 1;
|
||||
boolean driveEnableSync = parcel.readByte() == 1;
|
||||
boolean driveShare = parcel.readByte() == 1;
|
||||
String dirveShareEmails = parcel.readString();
|
||||
boolean mapsShare = parcel.readByte() == 1;
|
||||
String mapsSharePackageName = parcel.readString();
|
||||
String mapsShareClassName = parcel.readString();
|
||||
boolean mapsExistingMap = parcel.readByte() == 1;
|
||||
String mapsExistingMapId = parcel.readString();
|
||||
Parcelable account = parcel.readParcelable(null);
|
||||
boolean driveSuccess = parcel.readByte() == 1;
|
||||
boolean mapsSuccess = parcel.readByte() == 1;
|
||||
boolean fusionTablesSuccess = parcel.readByte() == 1;
|
||||
boolean spreadsheetsSuccess = parcel.readByte() == 1;
|
||||
assertEquals(1, trackId);
|
||||
assertFalse(sendDrive);
|
||||
assertFalse(sendMaps);
|
||||
assertFalse(sendFusionTables);
|
||||
assertFalse(sendSpreadsheets);
|
||||
assertFalse(driveEnableSync);
|
||||
assertFalse(driveShare);
|
||||
assertNull(dirveShareEmails);
|
||||
assertFalse(mapsShare);
|
||||
assertNull(mapsSharePackageName);
|
||||
assertNull(mapsShareClassName);
|
||||
assertFalse(mapsExistingMap);
|
||||
assertNull(mapsExistingMapId);
|
||||
assertNull(account);
|
||||
assertFalse(driveSuccess);
|
||||
assertFalse(mapsSuccess);
|
||||
assertFalse(fusionTablesSuccess);
|
||||
assertFalse(spreadsheetsSuccess);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link SendRequest#writeToParcel(Parcel, int)}.
|
||||
*/
|
||||
public void testWriteToParcel() {
|
||||
sendRequest = new SendRequest(4);
|
||||
sendRequest.setSendDrive(true);
|
||||
sendRequest.setSendMaps(true);
|
||||
sendRequest.setSendFusionTables(true);
|
||||
sendRequest.setSendSpreadsheets(true);
|
||||
sendRequest.setDriveEnableSync(true);
|
||||
sendRequest.setDriveShare(true);
|
||||
sendRequest.setDriveShareEmails(DRIVE_SHARE_EMAILS);
|
||||
sendRequest.setMapsShare(true);
|
||||
sendRequest.setMapsSharePackageName(MAPS_SHARE_PACKAGE_NAME);
|
||||
sendRequest.setMapsShareClassName(MAPS_SHARE_CLASS_NAME);
|
||||
sendRequest.setMapsExistingMap(true);
|
||||
sendRequest.setMapsExistingMapId(MAPS_EXISTING_MAP_ID);
|
||||
Account accountNew = new Account(ACCOUNTNAME + "2", ACCOUNTYPE + "2");
|
||||
sendRequest.setAccount(accountNew);
|
||||
sendRequest.setMapsSuccess(true);
|
||||
sendRequest.setDriveSuccess(true);
|
||||
sendRequest.setFusionTablesSuccess(true);
|
||||
sendRequest.setSpreadsheetsSuccess(true);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.setDataPosition(0);
|
||||
sendRequest.writeToParcel(parcel, 1);
|
||||
parcel.setDataPosition(0);
|
||||
long trackId = parcel.readLong();
|
||||
boolean sendDrive = parcel.readByte() == 1;
|
||||
boolean sendMaps = parcel.readByte() == 1;
|
||||
boolean sendFusionTables = parcel.readByte() == 1;
|
||||
boolean sendSpreadsheets = parcel.readByte() == 1;
|
||||
boolean driveEnableSync = parcel.readByte() == 1;
|
||||
boolean driveShare = parcel.readByte() == 1;
|
||||
String driveShareEmails = parcel.readString();
|
||||
boolean mapsShare = parcel.readByte() == 1;
|
||||
String mapsSharePackageName = parcel.readString();
|
||||
String mapsShareClassName = parcel.readString();
|
||||
boolean mapsExistingMap = parcel.readByte() == 1;
|
||||
String mapsExistingMapId = parcel.readString();
|
||||
Parcelable account = parcel.readParcelable(null);
|
||||
boolean driveSuccess = parcel.readByte() == 1;
|
||||
boolean mapsSuccess = parcel.readByte() == 1;
|
||||
boolean fusionTablesSuccess = parcel.readByte() == 1;
|
||||
boolean spreadsheetsSuccess = parcel.readByte() == 1;
|
||||
assertEquals(4, trackId);
|
||||
assertTrue(sendDrive);
|
||||
assertTrue(sendMaps);
|
||||
assertTrue(sendFusionTables);
|
||||
assertTrue(sendSpreadsheets);
|
||||
assertTrue(driveEnableSync);
|
||||
assertTrue(driveShare);
|
||||
assertEquals(DRIVE_SHARE_EMAILS, driveShareEmails);
|
||||
assertTrue(mapsShare);
|
||||
assertEquals(MAPS_SHARE_PACKAGE_NAME, mapsSharePackageName);
|
||||
assertEquals(MAPS_SHARE_CLASS_NAME, mapsShareClassName);
|
||||
assertTrue(mapsExistingMap);
|
||||
assertEquals(MAPS_EXISTING_MAP_ID, mapsExistingMapId);
|
||||
assertEquals(accountNew, account);
|
||||
assertTrue(driveSuccess);
|
||||
assertTrue(mapsSuccess);
|
||||
assertTrue(fusionTablesSuccess);
|
||||
assertTrue(spreadsheetsSuccess);
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Tests the {@link SendToGoogleUtils}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
import com.google.android.apps.mytracks.TrackStubUtils;
|
||||
import com.google.android.apps.mytracks.content.MyTracksLocation;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class SendToGoogleUtilsTest extends TestCase {
|
||||
|
||||
private final static long TRACK_ID = 1L;
|
||||
private final static String TRACK_CATEGORY = "trackCategory";
|
||||
private final static String TRACK_NAME = "trackName";
|
||||
private final static double DIFFERENCE = 0.02;
|
||||
private final static double INVALID_LATITUDE = 91;
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendToGoogleUtils#endSegment(Track, long, ArrayList)}
|
||||
* when there is only one location in a segment.
|
||||
*/
|
||||
public void testPrepareTrackSegment_onlyOneLocation() {
|
||||
Track segment = TrackStubUtils.createTrack(1);
|
||||
assertFalse(SendToGoogleUtils.endSegment(segment, -1L, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendToGoogleUtils#endSegment(Track, long, ArrayList)} when there
|
||||
* is no stop time.
|
||||
*/
|
||||
public void testPrepareTrackSegment_noStopTime() {
|
||||
Track segment = TrackStubUtils.createTrack(2);
|
||||
assertEquals(-1L, segment.getTripStatistics().getStopTime());
|
||||
|
||||
ArrayList<Track> tracksArray = new ArrayList<Track>();
|
||||
assertTrue(SendToGoogleUtils.endSegment(
|
||||
segment, segment.getLocations().get(1).getTime(), tracksArray));
|
||||
assertEquals(segment, tracksArray.get(0));
|
||||
// The stop time should be the time of last location
|
||||
assertEquals(
|
||||
segment.getLocations().get(1).getTime(), segment.getTripStatistics().getStopTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link SendToGoogleUtils#prepareLocations(Track, java.util.List)} .
|
||||
*/
|
||||
public void testPrepareLocations() {
|
||||
Track trackStub = TrackStubUtils.createTrack(2);
|
||||
trackStub.setId(TRACK_ID);
|
||||
trackStub.setName(TRACK_NAME);
|
||||
trackStub.setCategory(TRACK_CATEGORY);
|
||||
|
||||
List<Location> locationsArray = new ArrayList<Location>();
|
||||
// Adds 100 location to List.
|
||||
for (int i = 0; i < 100; i++) {
|
||||
// Use this variable as a flag to make all points in the track can be kept
|
||||
// after run the LocationUtils#decimate(Track, double) with
|
||||
// Ramer–Douglas–Peucker algorithm.
|
||||
double latitude = TrackStubUtils.INITIAL_LATITUDE;
|
||||
if (i % 2 == 0) {
|
||||
latitude -= DIFFERENCE * (i % 10);
|
||||
}
|
||||
// Inserts 9 points which have wrong latitude, so would have 10 segments.
|
||||
if (i % 10 == 0 && i > 0) {
|
||||
MyTracksLocation location = TrackStubUtils.createMyTracksLocation();
|
||||
location.setLatitude(INVALID_LATITUDE);
|
||||
locationsArray.add(location);
|
||||
} else {
|
||||
locationsArray.add(TrackStubUtils.createMyTracksLocation(latitude,
|
||||
TrackStubUtils.INITIAL_LONGITUDE + DIFFERENCE * (i % 10),
|
||||
TrackStubUtils.INITIAL_ALTITUDE + DIFFERENCE * (i % 10)));
|
||||
}
|
||||
}
|
||||
ArrayList<Track> result = SendToGoogleUtils.prepareLocations(trackStub, locationsArray);
|
||||
assertEquals(10, result.size());
|
||||
// Checks all segments.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Track segmentOne = result.get(i);
|
||||
assertEquals(TRACK_ID, segmentOne.getId());
|
||||
assertEquals(TRACK_NAME, segmentOne.getName());
|
||||
assertEquals(TRACK_CATEGORY, segmentOne.getCategory());
|
||||
}
|
||||
// Checks all locations in the first segment.
|
||||
for (int j = 0; j < 9; j++) {
|
||||
double latitude = TrackStubUtils.INITIAL_LATITUDE;
|
||||
if (j % 2 == 0) {
|
||||
latitude -= DIFFERENCE * (j % 10);
|
||||
}
|
||||
Location oneLocation = result.get(0).getLocations().get(j);
|
||||
assertEquals(TrackStubUtils.createMyTracksLocation().getAltitude() + DIFFERENCE * (j % 10),
|
||||
oneLocation.getAltitude());
|
||||
assertEquals(latitude, oneLocation.getLatitude());
|
||||
assertEquals(TrackStubUtils.createMyTracksLocation().getLongitude() + DIFFERENCE * (j % 10),
|
||||
oneLocation.getLongitude());
|
||||
}
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* 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.maps.mytracks.R;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Tests the {@link UploadResultActivity}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class UploadResultActivityTest extends
|
||||
ActivityInstrumentationTestCase2<UploadResultActivity> {
|
||||
|
||||
private UploadResultActivity uploadResultActivity;
|
||||
private TextView errorFooter;
|
||||
private TextView successFooter;
|
||||
private LinearLayout mapsResult;
|
||||
private LinearLayout fusionTablesResult;
|
||||
private LinearLayout spreadsheetsResult;
|
||||
private ImageView mapsResultIcon;
|
||||
private ImageView fusionTablesResultIcon;
|
||||
private ImageView spreadsheetsResultIcon;
|
||||
|
||||
private String successTitle;
|
||||
private String errorTitle;
|
||||
|
||||
/**
|
||||
* This method is necessary for ActivityInstrumentationTestCase2.
|
||||
*/
|
||||
public UploadResultActivityTest() {
|
||||
super(UploadResultActivity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the display of dialog when send to all and all sends are successful.
|
||||
*/
|
||||
public void testAllSuccess() {
|
||||
initialActivity(true, true, true, true, true, true);
|
||||
createDialogAndGetViews();
|
||||
assertEquals(View.VISIBLE, successFooter.getVisibility());
|
||||
assertEquals(View.GONE, errorFooter.getVisibility());
|
||||
|
||||
assertEquals(View.VISIBLE, mapsResult.getVisibility());
|
||||
assertEquals(View.VISIBLE, fusionTablesResult.getVisibility());
|
||||
assertEquals(View.VISIBLE, spreadsheetsResult.getVisibility());
|
||||
|
||||
assertEquals(successTitle, mapsResultIcon.getContentDescription());
|
||||
assertEquals(successTitle, fusionTablesResultIcon.getContentDescription());
|
||||
assertEquals(successTitle, spreadsheetsResultIcon.getContentDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the display of dialog when send to all and all sends are failed.
|
||||
*/
|
||||
public void testAllFailed() {
|
||||
// Send all kinds but all failed.
|
||||
initialActivity(true, true, true, false, false, false);
|
||||
createDialogAndGetViews();
|
||||
assertEquals(View.GONE, successFooter.getVisibility());
|
||||
assertEquals(View.VISIBLE, errorFooter.getVisibility());
|
||||
|
||||
assertEquals(View.VISIBLE, mapsResult.getVisibility());
|
||||
assertEquals(View.VISIBLE, fusionTablesResult.getVisibility());
|
||||
assertEquals(View.VISIBLE, spreadsheetsResult.getVisibility());
|
||||
|
||||
assertEquals(errorTitle, mapsResultIcon.getContentDescription());
|
||||
assertEquals(errorTitle, fusionTablesResultIcon.getContentDescription());
|
||||
assertEquals(errorTitle, spreadsheetsResultIcon.getContentDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the display of dialog when match following items:
|
||||
* <ul>
|
||||
* <li>Only send to Maps and Spreadsheets.</li>
|
||||
* <li>Send to Maps successful.</li>
|
||||
* <li>Send to Spreadsheets failed.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public void testPartialSuccess() {
|
||||
initialActivity(true, false, true, true, false, false);
|
||||
createDialogAndGetViews();
|
||||
assertEquals(View.VISIBLE, errorFooter.getVisibility());
|
||||
|
||||
assertEquals(View.VISIBLE, mapsResult.getVisibility());
|
||||
assertEquals(View.GONE, fusionTablesResult.getVisibility());
|
||||
assertEquals(View.VISIBLE, spreadsheetsResult.getVisibility());
|
||||
|
||||
assertEquals(successTitle, mapsResultIcon.getContentDescription());
|
||||
assertEquals(errorTitle, spreadsheetsResultIcon.getContentDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initials a {@link SendRequest} and then initials a activity to be tested.
|
||||
*
|
||||
* @param isSendMaps
|
||||
* @param isSendFusionTables
|
||||
* @param isSendSpreadsheets
|
||||
* @param isMapsSuccess
|
||||
* @param isFusionTablesSuccess
|
||||
* @param isSpreadsheetSuccess
|
||||
*/
|
||||
private void initialActivity(boolean isSendMaps, boolean isSendFusionTables, boolean isSendSpreadsheets,
|
||||
boolean isMapsSuccess, boolean isFusionTablesSuccess, boolean isSpreadsheetSuccess) {
|
||||
Intent intent = new Intent();
|
||||
SendRequest sendRequest = new SendRequest(1L);
|
||||
sendRequest.setSendMaps(isSendMaps);
|
||||
sendRequest.setSendFusionTables(isSendFusionTables);
|
||||
sendRequest.setSendSpreadsheets(isSendSpreadsheets);
|
||||
sendRequest.setMapsSuccess(isMapsSuccess);
|
||||
sendRequest.setFusionTablesSuccess(isFusionTablesSuccess);
|
||||
sendRequest.setSpreadsheetsSuccess(isSpreadsheetSuccess);
|
||||
intent.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
setActivityIntent(intent);
|
||||
uploadResultActivity = this.getActivity();
|
||||
successTitle = uploadResultActivity.getString(R.string.generic_success_title);
|
||||
errorTitle = uploadResultActivity.getString(R.string.generic_error_title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates result dialog and gets views in the dialog.
|
||||
*/
|
||||
private void createDialogAndGetViews() {
|
||||
uploadResultActivity.onCreateDialog(UploadResultActivity.DIALOG_RESULT_ID);
|
||||
View view = uploadResultActivity.view;
|
||||
errorFooter = (TextView) view.findViewById(R.id.upload_result_error_footer);
|
||||
successFooter = (TextView) view.findViewById(R.id.upload_result_success_footer);
|
||||
|
||||
mapsResult = (LinearLayout) view.findViewById(R.id.upload_result_maps_result);
|
||||
fusionTablesResult = (LinearLayout) view.findViewById(R.id.upload_result_fusion_tables_result);
|
||||
spreadsheetsResult = (LinearLayout) view.findViewById(R.id.upload_result_spreadsheets_result);
|
||||
|
||||
mapsResultIcon = (ImageView) view.findViewById(R.id.upload_result_maps_result_icon);
|
||||
fusionTablesResultIcon = (ImageView) view
|
||||
.findViewById(R.id.upload_result_fusion_tables_result_icon);
|
||||
spreadsheetsResultIcon = (ImageView) view.findViewById(R.id.upload_result_spreadsheets_result_icon);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user