forked from upstream-mirrors/OpenTracks
Merge with head.
This commit is contained in:
Executable → Regular
BIN
Binary file not shown.
Executable → Regular
BIN
Binary file not shown.
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010 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
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendDialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
@@ -66,15 +67,7 @@ public class DialogManagerTest
|
||||
Dialog d =
|
||||
getActivity().onCreateDialog(DialogManager.DIALOG_SEND_TO_GOOGLE, null);
|
||||
assertNotNull(d);
|
||||
assertTrue(d instanceof SendToGoogleDialog);
|
||||
}
|
||||
|
||||
public void test_onCreateSendToGoogleResult() {
|
||||
Dialog d =
|
||||
getActivity().onCreateDialog(
|
||||
DialogManager.DIALOG_SEND_TO_GOOGLE_RESULT, null);
|
||||
assertNotNull(d);
|
||||
assertTrue(d instanceof AlertDialog);
|
||||
assertTrue(d instanceof SendDialog);
|
||||
}
|
||||
|
||||
public void test_onCreateWriteProgress() {
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
// Copyright 2010 Google Inc. All Rights Reserved.
|
||||
package com.google.android.apps.mytracks.io;
|
||||
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,21 +4,32 @@ package com.google.android.apps.mytracks.io;
|
||||
import com.google.android.apps.mytracks.content.MyTracksLocation;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests for the GPX track exporter.
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
||||
private DateFormat timestampFormatter;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
timestampFormatter = new SimpleDateFormat(TcxTrackWriter.TIMESTAMP_FORMAT);
|
||||
timestampFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
|
||||
public void testXmlOutput() throws Exception {
|
||||
TrackFormatWriter writer = new TcxTrackWriter();
|
||||
TrackFormatWriter writer = new TcxTrackWriter(getContext());
|
||||
String result = writeTrack(writer);
|
||||
Document doc = parseXmlDocument(result);
|
||||
|
||||
@@ -58,8 +69,8 @@ public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
||||
getChildTextValue(posTag, "LatitudeDegrees"));
|
||||
assertEquals(Double.toString(loc.getLongitude()),
|
||||
getChildTextValue(posTag, "LongitudeDegrees"));
|
||||
assertEquals(
|
||||
TcxTrackWriter.TIMESTAMP_FORMAT.format(new Date(loc.getTime())),
|
||||
|
||||
assertEquals(timestampFormatter.format(loc.getTime()),
|
||||
getChildTextValue(tag, "Time"));
|
||||
assertEquals(Double.toString(loc.getAltitude()),
|
||||
getChildTextValue(tag, "AltitudeMeters"));
|
||||
|
||||
+25
-24
@@ -18,31 +18,31 @@ package com.google.android.apps.mytracks.io.docs;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.io.AuthManager;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.android.testing.mocking.AndroidMock;
|
||||
import com.google.android.testing.mocking.UsesMocks;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.test.mock.MockContext;
|
||||
import android.test.mock.MockResources;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link DocsHelper#addTrackRow}
|
||||
*
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||
private static final long TIME = 1288721514000L;
|
||||
|
||||
|
||||
private static class StringWritingDocsHelper extends DocsHelper {
|
||||
String writtenSheetUri = null;
|
||||
String writtenData = null;
|
||||
|
||||
|
||||
@Override
|
||||
protected void writeRowData(AuthManager trixAuth, String worksheetUri,
|
||||
String postText) {
|
||||
@@ -54,7 +54,7 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||
public void testAddTrackRow_imperial() throws Exception {
|
||||
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper();
|
||||
addTrackRow(docsHelper, false);
|
||||
|
||||
|
||||
String expectedData =
|
||||
"<entry xmlns='http://www.w3.org/2005/Atom' "
|
||||
+ "xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>"
|
||||
@@ -81,11 +81,11 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||
+ "</entry>";
|
||||
|
||||
assertEquals(
|
||||
"http://spreadsheets.google.com/feeds/list/ssid/wsid/private/full",
|
||||
"http://spreadsheets.google.com/feeds/list/ssid/wsid/private/full",
|
||||
docsHelper.writtenSheetUri);
|
||||
assertEquals(expectedData, docsHelper.writtenData);
|
||||
}
|
||||
|
||||
|
||||
public void testAddTrackRow_metric() throws Exception {
|
||||
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper();
|
||||
addTrackRow(docsHelper, true);
|
||||
@@ -100,18 +100,17 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||
"<gsx:speedunit><![CDATA[kph]]></gsx:speedunit>"));
|
||||
assertTrue(docsHelper.writtenData.contains(
|
||||
"<gsx:elevationunit><![CDATA[meter]]></gsx:elevationunit>"));
|
||||
|
||||
|
||||
assertTrue(docsHelper.writtenData.contains(
|
||||
"<gsx:distance><![CDATA[20.00]]></gsx:distance>"));
|
||||
}
|
||||
|
||||
@UsesMocks({AuthManager.class, MockContext.class, MockResources.class,
|
||||
Track.class})
|
||||
/** Adds a row to the spreadsheet, using the provided helper. */
|
||||
private void addTrackRow(DocsHelper docsHelper, boolean useMetric)
|
||||
@UsesMocks({AuthManager.class, MockResources.class, Track.class})
|
||||
private void addTrackRow(DocsHelper docsHelper, boolean useMetric)
|
||||
throws IOException {
|
||||
Resources mockResources = AndroidMock.createMock(MockResources.class);
|
||||
|
||||
final Resources mockResources = AndroidMock.createMock(MockResources.class);
|
||||
|
||||
if (useMetric) {
|
||||
AndroidMock.expect(mockResources.getString(R.string.kilometer))
|
||||
.andReturn("km");
|
||||
@@ -128,15 +127,17 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||
.andReturn("feet");
|
||||
}
|
||||
AndroidMock.replay(mockResources);
|
||||
|
||||
Context mockContext = AndroidMock.createMock(MockContext.class);
|
||||
AndroidMock.expect(mockContext.getResources())
|
||||
.andReturn(mockResources).anyTimes();
|
||||
AndroidMock.replay(mockContext);
|
||||
|
||||
Context mockContext = new MockContext() {
|
||||
@Override
|
||||
public Resources getResources() {
|
||||
return mockResources;
|
||||
}
|
||||
};
|
||||
|
||||
AuthManager mockAuthManager = AndroidMock.createMock(AuthManager.class);
|
||||
AndroidMock.replay(mockAuthManager);
|
||||
|
||||
|
||||
TripStatistics stats = new TripStatistics();
|
||||
stats.setStartTime(TIME);
|
||||
stats.setTotalTime(5000);
|
||||
@@ -146,14 +147,14 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||
stats.setTotalElevationGain(6000);
|
||||
stats.setMinElevation(-500);
|
||||
stats.setMaxElevation(550);
|
||||
|
||||
|
||||
Track track = new Track();
|
||||
track.setName("trackName");
|
||||
track.setDescription("trackDescription");
|
||||
track.setMapId("trackMapId");
|
||||
track.setStatistics(stats);
|
||||
|
||||
docsHelper.addTrackRow(mockContext, mockAuthManager, "ssid", "wsid",
|
||||
|
||||
docsHelper.addTrackRow(mockContext, mockAuthManager, "ssid", "wsid",
|
||||
track, useMetric);
|
||||
}
|
||||
}
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright 2011 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.MyTracks;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests {@link ResultDialogFactory}.
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class ResultDialogFactoryTest extends ActivityInstrumentationTestCase2<MyTracks> {
|
||||
public ResultDialogFactoryTest() {
|
||||
super(MyTracks.class);
|
||||
}
|
||||
|
||||
private List<SendResult> makeResults(SendResult... results) {
|
||||
List<SendResult> resultsList = new ArrayList<SendResult>();
|
||||
for (SendResult result : results) {
|
||||
resultsList.add(result);
|
||||
}
|
||||
return resultsList;
|
||||
}
|
||||
|
||||
private DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {}
|
||||
};
|
||||
|
||||
public void testSuccess_noShare() {
|
||||
List<SendResult> results = makeResults(new SendResult(SendType.MYMAPS, true),
|
||||
new SendResult(SendType.DOCS, true));
|
||||
|
||||
AlertDialog dialog = ResultDialogFactory.makeDialog(getActivity(), results, clickListener, null);
|
||||
dialog.show();
|
||||
|
||||
ListView listView = (ListView) dialog.findViewById(R.id.send_to_google_result_list);
|
||||
ListAdapter listAdapter = listView.getAdapter();
|
||||
assertEquals(2, listAdapter.getCount());
|
||||
|
||||
assertEquals(SendType.MYMAPS, ((SendResult) listAdapter.getItem(0)).getType());
|
||||
assertEquals(SendType.DOCS, ((SendResult) listAdapter.getItem(1)).getType());
|
||||
|
||||
// Checking the return code of Dialog#getButton doesn't appear to be
|
||||
// sufficient, as a Button will be returned even if it doesn't appear in
|
||||
// the rendered dialog.
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
|
||||
assertEquals(View.GONE, dialog.getButton(AlertDialog.BUTTON_NEUTRAL).getVisibility());
|
||||
|
||||
assertEquals(View.VISIBLE,
|
||||
dialog.findViewById(R.id.send_to_google_result_comment).getVisibility());
|
||||
assertEquals(View.GONE,
|
||||
dialog.findViewById(R.id.send_to_google_result_error).getVisibility());
|
||||
|
||||
// TODO: Test correct listener invocation. Neither TouchUtils#clickView
|
||||
// nor Button#performClick appear to cause listener invocation. This
|
||||
// might be Android bug
|
||||
// http://code.google.com/p/android/issues/detail?id=6564
|
||||
}
|
||||
|
||||
public void testSuccess_share() {
|
||||
List<SendResult> results = makeResults(new SendResult(SendType.MYMAPS, true),
|
||||
new SendResult(SendType.DOCS, true));
|
||||
|
||||
AlertDialog dialog = ResultDialogFactory.makeDialog(getActivity(), results,
|
||||
clickListener, clickListener);
|
||||
dialog.show();
|
||||
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_NEUTRAL).getVisibility());
|
||||
}
|
||||
|
||||
public void testFailure_noShare() {
|
||||
List<SendResult> results = makeResults(new SendResult(SendType.MYMAPS, true),
|
||||
new SendResult(SendType.DOCS, false));
|
||||
|
||||
AlertDialog dialog = ResultDialogFactory.makeDialog(getActivity(), results, clickListener, null);
|
||||
dialog.show();
|
||||
|
||||
assertEquals(View.GONE,
|
||||
dialog.findViewById(R.id.send_to_google_result_comment).getVisibility());
|
||||
assertEquals(View.VISIBLE,
|
||||
dialog.findViewById(R.id.send_to_google_result_error).getVisibility());
|
||||
}
|
||||
|
||||
public void testFailure_share() {
|
||||
List<SendResult> results = makeResults(new SendResult(SendType.MYMAPS, true),
|
||||
new SendResult(SendType.DOCS, false));
|
||||
|
||||
AlertDialog dialog = ResultDialogFactory.makeDialog(getActivity(), results,
|
||||
clickListener, clickListener);
|
||||
dialog.show();
|
||||
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_POSITIVE).getVisibility());
|
||||
assertEquals(View.VISIBLE, dialog.getButton(AlertDialog.BUTTON_NEUTRAL).getVisibility());
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2011 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.Context;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests {@link ResultListAdapter}.
|
||||
*
|
||||
* @author Matthew Simmons
|
||||
*/
|
||||
public class ResultListAdapterTest extends AndroidTestCase {
|
||||
private static class TestResultListAdapter extends ResultListAdapter {
|
||||
public View contentView;
|
||||
public int drawableId;
|
||||
public int nameId;
|
||||
public int urlId;
|
||||
|
||||
public TestResultListAdapter(Context context, List<SendResult> results) {
|
||||
super(context, 0, results);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setImage(View content, int drawableId) {
|
||||
saveContentView(content);
|
||||
this.drawableId = drawableId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setName(View content, int nameId) {
|
||||
saveContentView(content);
|
||||
this.nameId = nameId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUrl(View content, int urlId) {
|
||||
saveContentView(content);
|
||||
this.urlId = urlId;
|
||||
}
|
||||
|
||||
private void saveContentView(View contentView) {
|
||||
if (this.contentView == null) {
|
||||
this.contentView = contentView;
|
||||
} else {
|
||||
AndroidTestCase.assertEquals(this.contentView, contentView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final SendType sendType = SendType.MYMAPS;
|
||||
|
||||
private View inflateContentView(int viewId) {
|
||||
LayoutInflater layoutInflater
|
||||
= (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
return layoutInflater.inflate(viewId, null);
|
||||
}
|
||||
|
||||
private List<SendResult> makeResult(SendType type, boolean success) {
|
||||
List<SendResult> results = new ArrayList<SendResult>();
|
||||
results.add(new SendResult(type, success));
|
||||
return results;
|
||||
}
|
||||
|
||||
public void testSuccess_createsNewView() {
|
||||
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
|
||||
makeResult(sendType, true));
|
||||
adapter.getView(0, null, null);
|
||||
|
||||
assertEquals(R.drawable.success, adapter.drawableId);
|
||||
assertEquals(sendType.getServiceName(), adapter.nameId);
|
||||
assertEquals(sendType.getServiceUrl(), adapter.urlId);
|
||||
}
|
||||
|
||||
public void testSuccess_reusesView() {
|
||||
View contentView = inflateContentView(R.layout.send_to_google_result_list_item);
|
||||
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
|
||||
makeResult(sendType, true));
|
||||
adapter.getView(0, contentView, null);
|
||||
|
||||
assertEquals(contentView, adapter.contentView);
|
||||
assertEquals(R.drawable.success, adapter.drawableId);
|
||||
assertEquals(sendType.getServiceName(), adapter.nameId);
|
||||
assertEquals(sendType.getServiceUrl(), adapter.urlId);
|
||||
}
|
||||
|
||||
public void testFailure() {
|
||||
TestResultListAdapter adapter = new TestResultListAdapter(getContext(),
|
||||
makeResult(sendType, false));
|
||||
adapter.getView(0, null, null);
|
||||
|
||||
assertEquals(R.drawable.failure, adapter.drawableId);
|
||||
assertEquals(sendType.getServiceName(), adapter.nameId);
|
||||
assertEquals(sendType.getServiceUrl(), adapter.urlId);
|
||||
}
|
||||
}
|
||||
+21
-40
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010 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
|
||||
@@ -255,7 +255,6 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
@UsesMocks({
|
||||
StatusAnnouncerTask.class,
|
||||
StringUtils.class,
|
||||
TrackRecordingService.class,
|
||||
})
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -390,9 +389,6 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
public void testRun() throws Exception {
|
||||
// Expect service data calls
|
||||
TripStatistics stats = new TripStatistics();
|
||||
TrackRecordingService service =
|
||||
AndroidMock.createMock(TrackRecordingService.class);
|
||||
expect(service.getTripStatistics()).andStubReturn(stats);
|
||||
|
||||
// Expect announcement building call
|
||||
expect(mockTask.getAnnouncement(same(stats))).andStubReturn(ANNOUNCEMENT);
|
||||
@@ -407,75 +403,63 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
.andReturn(TextToSpeech.SUCCESS);
|
||||
|
||||
// Run the announcement
|
||||
AndroidMock.replay(tts, stringUtils, service);
|
||||
task.run(service);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils, service);
|
||||
AndroidMock.replay(tts, stringUtils);
|
||||
task.runWithStatistics(stats);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
||||
}
|
||||
|
||||
public void testRun_notReady() throws Exception {
|
||||
TrackRecordingService service =
|
||||
AndroidMock.createMock(TrackRecordingService.class);
|
||||
|
||||
// Put task in "not ready" state
|
||||
startTask(TextToSpeech.ERROR);
|
||||
|
||||
// Run the announcement
|
||||
AndroidMock.replay(tts, stringUtils, service);
|
||||
task.run(service);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils, service);
|
||||
AndroidMock.replay(tts, stringUtils);
|
||||
task.runWithStatistics(null);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
||||
}
|
||||
|
||||
public void testRun_duringCall() throws Exception {
|
||||
TrackRecordingService service =
|
||||
AndroidMock.createMock(TrackRecordingService.class);
|
||||
|
||||
startTask(TextToSpeech.SUCCESS);
|
||||
|
||||
expect(tts.isSpeaking()).andStubReturn(false);
|
||||
|
||||
// Run the announcement
|
||||
AndroidMock.replay(tts, stringUtils, service);
|
||||
AndroidMock.replay(tts, stringUtils);
|
||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
||||
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, null);
|
||||
task.run(service);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils, service);
|
||||
task.runWithStatistics(null);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
||||
}
|
||||
|
||||
public void testRun_ringWhileSpeaking() throws Exception {
|
||||
TrackRecordingService service =
|
||||
AndroidMock.createMock(TrackRecordingService.class);
|
||||
|
||||
startTask(TextToSpeech.SUCCESS);
|
||||
|
||||
expect(tts.isSpeaking()).andStubReturn(true);
|
||||
expect(tts.stop()).andReturn(TextToSpeech.SUCCESS);
|
||||
|
||||
AndroidMock.replay(tts, stringUtils, service);
|
||||
AndroidMock.replay(tts, stringUtils);
|
||||
|
||||
// Update the state to ringing - this should stop the current announcement.
|
||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
||||
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
|
||||
|
||||
// Run the announcement - this should do nothing.
|
||||
task.run(service);
|
||||
task.runWithStatistics(null);
|
||||
|
||||
AndroidMock.verify(mockTask, tts, stringUtils, service);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
||||
}
|
||||
|
||||
public void testRun_whileRinging() throws Exception {
|
||||
TrackRecordingService service =
|
||||
AndroidMock.createMock(TrackRecordingService.class);
|
||||
|
||||
startTask(TextToSpeech.SUCCESS);
|
||||
|
||||
expect(tts.isSpeaking()).andStubReturn(false);
|
||||
|
||||
// Run the announcement
|
||||
AndroidMock.replay(tts, stringUtils, service);
|
||||
AndroidMock.replay(tts, stringUtils);
|
||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
||||
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
|
||||
task.run(service);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils, service);
|
||||
task.runWithStatistics(null);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
||||
}
|
||||
|
||||
public void testRun_noService() throws Exception {
|
||||
@@ -489,16 +473,13 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
|
||||
public void testRun_noStats() throws Exception {
|
||||
// Expect service data calls
|
||||
TrackRecordingService service =
|
||||
AndroidMock.createMock(TrackRecordingService.class);
|
||||
expect(service.getTripStatistics()).andStubReturn(null);
|
||||
|
||||
startTask(TextToSpeech.SUCCESS);
|
||||
|
||||
// Run the announcement
|
||||
AndroidMock.replay(tts, stringUtils, service);
|
||||
task.run(service);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils, service);
|
||||
AndroidMock.replay(tts, stringUtils);
|
||||
task.runWithStatistics(null);
|
||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
||||
}
|
||||
|
||||
private void startTask(int state) {
|
||||
|
||||
Reference in New Issue
Block a user