forked from upstream-mirrors/OpenTracks
Address comments + add more tests.
This commit is contained in:
+8
-21
@@ -40,13 +40,12 @@ public class WaypointCreationRequest implements Parcelable {
|
|||||||
public final static WaypointCreationRequest DEFAULT_STATISTICS =
|
public final static WaypointCreationRequest DEFAULT_STATISTICS =
|
||||||
new WaypointCreationRequest(WaypointType.STATISTICS);
|
new WaypointCreationRequest(WaypointType.STATISTICS);
|
||||||
|
|
||||||
public WaypointCreationRequest(WaypointType type) {
|
private WaypointCreationRequest(WaypointType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaypointCreationRequest(WaypointType type, String name,
|
public WaypointCreationRequest(WaypointType type, String name,
|
||||||
String description, String iconUrl) {
|
String description, String iconUrl) {
|
||||||
super();
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@@ -55,23 +54,19 @@ public class WaypointCreationRequest implements Parcelable {
|
|||||||
|
|
||||||
public static class Creator implements Parcelable.Creator<WaypointCreationRequest> {
|
public static class Creator implements Parcelable.Creator<WaypointCreationRequest> {
|
||||||
|
|
||||||
|
@Override
|
||||||
public WaypointCreationRequest createFromParcel(Parcel source) {
|
public WaypointCreationRequest createFromParcel(Parcel source) {
|
||||||
int i = source.readInt();
|
int i = source.readInt();
|
||||||
if (i > WaypointType.values().length) {
|
if (i > WaypointType.values().length) {
|
||||||
throw new IllegalArgumentException("Could not find waypoint type: " + i);
|
throw new IllegalArgumentException("Could not find waypoint type: " + i);
|
||||||
}
|
}
|
||||||
WaypointCreationRequest request = new WaypointCreationRequest(WaypointType.values()[i]);
|
WaypointCreationRequest request = new WaypointCreationRequest(WaypointType.values()[i]);
|
||||||
request.description = maybeReadStringToParcel(source);
|
request.description = source.readString();
|
||||||
request.iconUrl = maybeReadStringToParcel(source);
|
request.iconUrl = source.readString();
|
||||||
request.name = maybeReadStringToParcel(source);
|
request.name = source.readString();
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String maybeReadStringToParcel(Parcel parcel) {
|
|
||||||
return parcel.readByte() > 0 ? parcel.readString() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public WaypointCreationRequest[] newArray(int size) {
|
public WaypointCreationRequest[] newArray(int size) {
|
||||||
return new WaypointCreationRequest[size];
|
return new WaypointCreationRequest[size];
|
||||||
}
|
}
|
||||||
@@ -87,19 +82,11 @@ public class WaypointCreationRequest implements Parcelable {
|
|||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel parcel, int arg1) {
|
public void writeToParcel(Parcel parcel, int arg1) {
|
||||||
parcel.writeInt(type.ordinal());
|
parcel.writeInt(type.ordinal());
|
||||||
// TODO: Pack all of available bits into one byte.
|
parcel.writeString(description);
|
||||||
maybeWriteStringToParcel(parcel, description);
|
parcel.writeString(iconUrl);
|
||||||
maybeWriteStringToParcel(parcel, iconUrl);
|
parcel.writeString(name);
|
||||||
maybeWriteStringToParcel(parcel, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeWriteStringToParcel(Parcel parcel, String s) {
|
|
||||||
parcel.writeByte(s == null ? (byte) 0 : (byte) 1);
|
|
||||||
if (s != null) {
|
|
||||||
parcel.writeString(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public WaypointType getType() {
|
public WaypointType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.apps.mytracks.content;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for the WaypointCreationRequest class.
|
||||||
|
*
|
||||||
|
* @author Sandor Dornbush
|
||||||
|
*/
|
||||||
|
public class WaypointCreationRequestTest extends AndroidTestCase {
|
||||||
|
|
||||||
|
public void testTypeParceling() {
|
||||||
|
WaypointCreationRequest original = WaypointCreationRequest.DEFAULT_MARKER;
|
||||||
|
Parcel p = Parcel.obtain();
|
||||||
|
original.writeToParcel(p, 0);
|
||||||
|
p.setDataPosition(0);
|
||||||
|
WaypointCreationRequest copy =
|
||||||
|
WaypointCreationRequest.CREATOR.createFromParcel(p);
|
||||||
|
assertEquals(original.getType(), copy.getType());
|
||||||
|
assertNull(copy.getName());
|
||||||
|
assertNull(copy.getDescription());
|
||||||
|
assertNull(copy.getIconUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllAttributesParceling() {
|
||||||
|
WaypointCreationRequest original =
|
||||||
|
new WaypointCreationRequest(WaypointType.MARKER, "name", "description", "img.png");
|
||||||
|
Parcel p = Parcel.obtain();
|
||||||
|
original.writeToParcel(p, 0);
|
||||||
|
p.setDataPosition(0);
|
||||||
|
WaypointCreationRequest copy =
|
||||||
|
WaypointCreationRequest.CREATOR.createFromParcel(p);
|
||||||
|
assertEquals(original.getType(), copy.getType());
|
||||||
|
assertEquals("name", copy.getName());
|
||||||
|
assertEquals("description", copy.getDescription());
|
||||||
|
assertEquals("img.png", copy.getIconUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user