-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from tradingticket/gd/account_capabilities/153…
…521995 Gd/account capabilities/153521995
- Loading branch information
Showing
14 changed files
with
346 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Thu Apr 06 19:53:47 EDT 2017 | ||
#Fri Dec 08 15:52:06 EST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...src/androidTest/java/it/trade/android/sdk/model/TradeItOrderCapabilityParcelableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package it.trade.android.sdk.model; | ||
|
||
import android.os.Parcel; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.test.suitebuilder.annotation.SmallTest; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import it.trade.model.reponse.DisplayLabelValue; | ||
import it.trade.model.reponse.Instrument; | ||
import it.trade.model.reponse.OrderCapability; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertThat; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@SmallTest | ||
public class TradeItOrderCapabilityParcelableTest { | ||
|
||
private TradeItOrderCapabilityParcelable orderCapabilityParcelable; | ||
private DisplayLabelValue action; | ||
private DisplayLabelValue priceType; | ||
private DisplayLabelValue expirationType; | ||
|
||
@Before | ||
public void createTradeItOrderCapabilityParcelable() { | ||
OrderCapability orderCapability = new OrderCapability(); | ||
action = new DisplayLabelValue("Buy", "buy"); | ||
priceType = new DisplayLabelValue("Market", "market"); | ||
expirationType = new DisplayLabelValue("Good for day", "day"); | ||
orderCapability.setInstrument(Instrument.EQUITIES); | ||
orderCapability.actions = Arrays.asList(action); | ||
orderCapability.priceTypes = Arrays.asList(priceType); | ||
orderCapability.expirationTypes = Arrays.asList(expirationType); | ||
orderCapabilityParcelable = new TradeItOrderCapabilityParcelable(orderCapability); | ||
} | ||
|
||
@Test | ||
public void orderCapabilities_ParcelableWriteRead() { | ||
|
||
|
||
// Write the data. | ||
Parcel parcel = Parcel.obtain(); | ||
orderCapabilityParcelable.writeToParcel(parcel, orderCapabilityParcelable.describeContents()); | ||
|
||
// After you're done with writing, you need to reset the parcel for reading. | ||
parcel.setDataPosition(0); | ||
|
||
// Read the data. | ||
TradeItOrderCapabilityParcelable createdFromParcel = TradeItOrderCapabilityParcelable.CREATOR.createFromParcel(parcel); | ||
Instrument instrument = createdFromParcel.getInstrument(); | ||
List<DisplayLabelValueParcelable> actions = createdFromParcel.getActions(); | ||
List<DisplayLabelValueParcelable> expirationTypes = createdFromParcel.getExpirationTypes(); | ||
List<DisplayLabelValueParcelable> priceTypes = createdFromParcel.getPriceTypes(); | ||
|
||
// Verify that the received data is correct. | ||
assertThat(instrument, is(Instrument.EQUITIES)); | ||
assertFalse(actions.isEmpty()); | ||
assertThat(actions.get(0).getValue(), is(action.value)); | ||
assertThat(actions.get(0).getDisplayLabel(), is(action.displayLabel)); | ||
assertFalse(expirationTypes.isEmpty()); | ||
assertThat(expirationTypes.get(0).getValue(), is(expirationType.value)); | ||
assertThat(expirationTypes.get(0).getDisplayLabel(), is(expirationType.displayLabel)); | ||
assertFalse(priceTypes.isEmpty()); | ||
assertThat(priceTypes.get(0).getValue(), is(priceType.value)); | ||
assertThat(priceTypes.get(0).getDisplayLabel(), is(priceType.displayLabel)); | ||
|
||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...eit-android-sdk/src/main/java/it/trade/android/sdk/model/DisplayLabelValueParcelable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package it.trade.android.sdk.model; | ||
|
||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import it.trade.model.reponse.DisplayLabelValue; | ||
|
||
public class DisplayLabelValueParcelable implements Parcelable { | ||
|
||
private String displayLabel; | ||
private String value; | ||
|
||
|
||
public DisplayLabelValueParcelable(DisplayLabelValue displayLabelValue) { | ||
this.displayLabel = displayLabelValue.displayLabel; | ||
this.value = displayLabelValue.value; | ||
} | ||
|
||
public static List<DisplayLabelValueParcelable> mapDisplayLabelValuesToDisplayLabelValueParcelables(List<DisplayLabelValue> displayLabelValues) { | ||
List<DisplayLabelValueParcelable> displayLabelValueParcelables = new ArrayList<>(); | ||
if (displayLabelValues != null) { | ||
for (DisplayLabelValue displayLabelValue: displayLabelValues) { | ||
displayLabelValueParcelables.add(new DisplayLabelValueParcelable(displayLabelValue)); | ||
} | ||
} | ||
return displayLabelValueParcelables; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DisplayLabelValueParcelable{" + | ||
"displayLabel='" + displayLabel + '\'' + | ||
", value='" + value + '\'' + | ||
'}'; | ||
} | ||
|
||
public String getDisplayLabel() { | ||
return displayLabel; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
DisplayLabelValueParcelable that = (DisplayLabelValueParcelable) o; | ||
|
||
if (displayLabel != null ? !displayLabel.equals(that.displayLabel) : that.displayLabel != null) | ||
return false; | ||
return value != null ? value.equals(that.value) : that.value == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = displayLabel != null ? displayLabel.hashCode() : 0; | ||
result = 31 * result + (value != null ? value.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel dest, int flags) { | ||
dest.writeString(this.displayLabel); | ||
dest.writeString(this.value); | ||
} | ||
|
||
protected DisplayLabelValueParcelable(Parcel in) { | ||
this.displayLabel = in.readString(); | ||
this.value = in.readString(); | ||
} | ||
|
||
public static final Parcelable.Creator<DisplayLabelValueParcelable> CREATOR = new Parcelable.Creator<DisplayLabelValueParcelable>() { | ||
@Override | ||
public DisplayLabelValueParcelable createFromParcel(Parcel source) { | ||
return new DisplayLabelValueParcelable(source); | ||
} | ||
|
||
@Override | ||
public DisplayLabelValueParcelable[] newArray(int size) { | ||
return new DisplayLabelValueParcelable[size]; | ||
} | ||
}; | ||
} |
Oops, something went wrong.