diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..17dd9a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# IntelliJ + +.idea/ +*.iml + +# MacOS + +.DS_Store + +# Build + +build/ +.gradle/ +out/ \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..af71d55 --- /dev/null +++ b/build.gradle @@ -0,0 +1,53 @@ +group 'io.magicthegathering' +version '0.0.1' + +buildscript { + ext.kotlin_version = '1.0.6' + + repositories { + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' + +repositories { + mavenCentral() +} + +def rxkotlin_version = '0.60.0' +def okhttp3_version = '3.4.1' +def retrofit2_version = '2.1.0' +def junit_version = '4.12' +def joda_time_version = '2.9.7' + +dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + // Rx + compile "io.reactivex:rxkotlin:$rxkotlin_version" + + // Retrofit + compile "com.squareup.okhttp3:okhttp:$okhttp3_version" + compile "com.squareup.okhttp3:logging-interceptor:$okhttp3_version" + compile "com.squareup.retrofit2:adapter-rxjava:$retrofit2_version" + compile("com.squareup.retrofit2:retrofit:$retrofit2_version") { + exclude module: "okhttp" + } + compile "com.squareup.retrofit2:converter-gson:$retrofit2_version" + + // Joda Time + compile "joda-time:joda-time:$joda_time_version" + + // Test + testCompile "junit:junit:$junit_version" + testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" +} + +sourceSets { + main.java.srcDirs += 'src' + test.java.srcDirs += 'test' +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..ca78035 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..274d10b --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Jan 17 16:42:09 CET 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..27309d9 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f6d5974 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..2ba1661 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'kotlinsdk' + diff --git a/src/io/magicthegathering/kotlinsdk/api/ApiClientBuilder.kt b/src/io/magicthegathering/kotlinsdk/api/ApiClientBuilder.kt new file mode 100644 index 0000000..281cdf0 --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/api/ApiClientBuilder.kt @@ -0,0 +1,32 @@ +package io.magicthegathering.kotlinsdk.api + +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import io.magicthegathering.kotlinsdk.api.deserializer.MtgCardDeserializer +import io.magicthegathering.kotlinsdk.model.card.MtgCard +import okhttp3.OkHttpClient +import retrofit2.Retrofit +import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory +import retrofit2.converter.gson.GsonConverterFactory + +class ApiClientBuilder private constructor() { + + private object Holder { + val gson: Gson = GsonBuilder() + .registerTypeAdapter(MtgCard::class.java, MtgCardDeserializer()) + .create() + + val okHttpClient: OkHttpClient = OkHttpClient().newBuilder().build() + + val INSTANCE: Retrofit = Retrofit.Builder() + .baseUrl("https://api.magicthegathering.io/v1/") + .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) + .client(okHttpClient) + .build() + } + + companion object { + val instance: Retrofit by lazy { Holder.INSTANCE } + } +} \ No newline at end of file diff --git a/src/io/magicthegathering/kotlinsdk/api/MtgCardApiClient.kt b/src/io/magicthegathering/kotlinsdk/api/MtgCardApiClient.kt new file mode 100644 index 0000000..0e0183b --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/api/MtgCardApiClient.kt @@ -0,0 +1,23 @@ +package io.magicthegathering.kotlinsdk.api + +import io.magicthegathering.kotlinsdk.model.card.MtgCard +import retrofit2.http.GET +import retrofit2.http.Path +import rx.Observable + +class MtgCardApiClient private constructor() { + + private object Holder { + val INSTANCE: MtgCardApi = ApiClientBuilder.instance.create(MtgCardApi::class.java) + } + + companion object { + val instance: MtgCardApi by lazy { Holder.INSTANCE } + } + + interface MtgCardApi { + + @GET("cards/{multiverseId}") + fun getCard(@Path("multiverseId") multiverseId: Int): Observable + } +} \ No newline at end of file diff --git a/src/io/magicthegathering/kotlinsdk/api/deserializer/MtgCardDeserializer.kt b/src/io/magicthegathering/kotlinsdk/api/deserializer/MtgCardDeserializer.kt new file mode 100644 index 0000000..4d1f74f --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/api/deserializer/MtgCardDeserializer.kt @@ -0,0 +1,25 @@ +package io.magicthegathering.kotlinsdk.api.deserializer + +import com.google.gson.* +import io.magicthegathering.kotlinsdk.model.card.MtgCard +import io.magicthegathering.kotlinsdk.model.card.MtgCardRuling +import java.lang.reflect.Type + +class MtgCardDeserializer : JsonDeserializer { + + override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): MtgCard? { + val gson: Gson = GsonBuilder() + .registerTypeAdapter(MtgCardRuling::class.java, MtgCardRulingDeserializer()) + .create() + + val jsonObject = json?.asJsonObject + var card: MtgCard? = null + + if (jsonObject != null && !jsonObject.isJsonNull) { + val cardJsonObject: JsonObject = jsonObject.get("card").asJsonObject + card = gson.fromJson(cardJsonObject, MtgCard::class.java) + } + + return card + } +} \ No newline at end of file diff --git a/src/io/magicthegathering/kotlinsdk/api/deserializer/MtgCardRulingDeserializer.kt b/src/io/magicthegathering/kotlinsdk/api/deserializer/MtgCardRulingDeserializer.kt new file mode 100644 index 0000000..d5fd378 --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/api/deserializer/MtgCardRulingDeserializer.kt @@ -0,0 +1,24 @@ +package io.magicthegathering.kotlinsdk.api.deserializer + +import com.google.gson.JsonDeserializationContext +import com.google.gson.JsonDeserializer +import com.google.gson.JsonElement +import io.magicthegathering.kotlinsdk.api.util.DateTimeFormatterSingleton +import io.magicthegathering.kotlinsdk.model.card.MtgCardRuling +import org.joda.time.DateTime +import java.lang.reflect.Type + +class MtgCardRulingDeserializer : JsonDeserializer { + + override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): MtgCardRuling? { + val jsonObject = json?.asJsonObject + var ruling: MtgCardRuling? = null + + if (jsonObject != null && !jsonObject.isJsonNull) { + val date: DateTime = DateTime.parse(jsonObject.get("date").asString, DateTimeFormatterSingleton.instance) + ruling = MtgCardRuling(date, jsonObject.get("text").asString) + } + + return ruling + } +} \ No newline at end of file diff --git a/src/io/magicthegathering/kotlinsdk/api/util/DateTimeFormatterSingleton.kt b/src/io/magicthegathering/kotlinsdk/api/util/DateTimeFormatterSingleton.kt new file mode 100644 index 0000000..54ae22c --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/api/util/DateTimeFormatterSingleton.kt @@ -0,0 +1,21 @@ +package io.magicthegathering.kotlinsdk.api.util + +import org.joda.time.format.DateTimeFormatter +import org.joda.time.format.DateTimeFormatterBuilder + +class DateTimeFormatterSingleton private constructor() { + + private object Holder { + val INSTANCE: DateTimeFormatter = DateTimeFormatterBuilder() + .appendYear(4, 4) + .appendLiteral('-') + .appendMonthOfYear(2) + .appendLiteral('-') + .appendDayOfMonth(2) + .toFormatter() + } + + companion object { + val instance: DateTimeFormatter by lazy { Holder.INSTANCE } + } +} \ No newline at end of file diff --git a/src/io/magicthegathering/kotlinsdk/model/card/MtgCard.kt b/src/io/magicthegathering/kotlinsdk/model/card/MtgCard.kt new file mode 100644 index 0000000..38b2808 --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/model/card/MtgCard.kt @@ -0,0 +1,28 @@ +package io.magicthegathering.kotlinsdk.model.card + +class MtgCard(val id: String?, + val name: String, + val names: List?, + val manaCost: String, + val cmc: Int?, + val colors: List?, + val colorIdentity: List?, + val type: String, + val supertypes: List?, + val types: List, + val subtypes: List?, + val rarity: String, + val set: String, + val setName: String, + val text: String?, + val artist: String, + val number: String?, + val power: String?, + val toughness: String?, + val loyalty: Int?, + val multiverseid: Int?, + val imageUrl: String, + val layout: String, + val legalities: List?, + val rulings: List?, + val foreignNames: List?) \ No newline at end of file diff --git a/src/io/magicthegathering/kotlinsdk/model/card/MtgCardForeignName.kt b/src/io/magicthegathering/kotlinsdk/model/card/MtgCardForeignName.kt new file mode 100644 index 0000000..f19786d --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/model/card/MtgCardForeignName.kt @@ -0,0 +1,3 @@ +package io.magicthegathering.kotlinsdk.model.card + +class MtgCardForeignName(val name: String, val imageUrl: String, val language: String, val multiverseid: Int) \ No newline at end of file diff --git a/src/io/magicthegathering/kotlinsdk/model/card/MtgCardLegality.kt b/src/io/magicthegathering/kotlinsdk/model/card/MtgCardLegality.kt new file mode 100644 index 0000000..a96be97 --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/model/card/MtgCardLegality.kt @@ -0,0 +1,3 @@ +package io.magicthegathering.kotlinsdk.model.card + +class MtgCardLegality(val format: String, val legality: String) \ No newline at end of file diff --git a/src/io/magicthegathering/kotlinsdk/model/card/MtgCardRuling.kt b/src/io/magicthegathering/kotlinsdk/model/card/MtgCardRuling.kt new file mode 100644 index 0000000..cbf739d --- /dev/null +++ b/src/io/magicthegathering/kotlinsdk/model/card/MtgCardRuling.kt @@ -0,0 +1,5 @@ +package io.magicthegathering.kotlinsdk.model.card + +import org.joda.time.DateTime + +class MtgCardRuling(val date: DateTime, val text: String) \ No newline at end of file diff --git a/test/io/magicthegathering/kotlinsdk/api/MtgCardApiClientGetSingleCardByMultiverseIdForDifferentLayoutsTests.kt b/test/io/magicthegathering/kotlinsdk/api/MtgCardApiClientGetSingleCardByMultiverseIdForDifferentLayoutsTests.kt new file mode 100644 index 0000000..35acc05 --- /dev/null +++ b/test/io/magicthegathering/kotlinsdk/api/MtgCardApiClientGetSingleCardByMultiverseIdForDifferentLayoutsTests.kt @@ -0,0 +1,558 @@ +package io.magicthegathering.kotlinsdk.api + +import io.magicthegathering.kotlinsdk.api.util.DateTimeFormatterSingleton +import io.magicthegathering.kotlinsdk.model.card.MtgCard +import io.magicthegathering.kotlinsdk.model.card.MtgCardForeignName +import io.magicthegathering.kotlinsdk.model.card.MtgCardLegality +import io.magicthegathering.kotlinsdk.model.card.MtgCardRuling +import org.joda.time.DateTime +import org.junit.Assert +import org.junit.Test + +class MtgCardApiClientGetSingleCardByMultiverseIdForDifferentLayoutsTests { + + @Test + fun getNormalCard() { + MtgCardApiClient.instance.getCard(1).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Ankh of Mishra") + Assert.assertNull(card.names) + Assert.assertEquals(card.manaCost, "{2}") + Assert.assertEquals(card.cmc, 2) + Assert.assertNull(card.colors) + Assert.assertNull(card.colorIdentity) + Assert.assertEquals(card.type, "Artifact") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Artifact") + Assert.assertNull(card.subtypes) + Assert.assertEquals(card.rarity, "Rare") + Assert.assertEquals(card.set, "LEA") + Assert.assertEquals(card.setName, "Limited Edition Alpha") + Assert.assertEquals(card.text, "Whenever a land enters the battlefield, Ankh of Mishra deals 2 damage to that land's controller.") + Assert.assertEquals(card.artist, "Amy Weber") + Assert.assertNull(card.number) + Assert.assertNull(card.power) + Assert.assertNull(card.toughness) + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 1) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=1&type=card") + Assert.assertEquals(card.layout, "normal") + + val legalities: List = arrayListOf( + MtgCardLegality("Commander", "Legal"), + MtgCardLegality("Legacy", "Legal"), + MtgCardLegality("Vintage", "Legal") + ) + + card.legalities!!.forEachIndexed { index, mtgCardLegalitylegality -> + Assert.assertEquals(mtgCardLegalitylegality.format, legalities[index].format) + Assert.assertEquals(mtgCardLegalitylegality.legality, legalities[index].legality) + } + + val date: DateTime = DateTime.parse("2004-10-04", DateTimeFormatterSingleton.instance) + + val rulings: List = arrayListOf( + MtgCardRuling(date, "This triggers on any land entering the battlefield. This includes playing a land or putting a land onto the battlefield using a spell or ability."), + MtgCardRuling(date, "It determines the land's controller at the time the ability resolves. If the land leaves the battlefield before the ability resolves, the land's last controller before it left is used.") + ) + + card.rulings!!.forEachIndexed { index, mtgCardRuling -> + Assert.assertEquals(mtgCardRuling.date, rulings[index].date) + Assert.assertEquals(mtgCardRuling.text, rulings[index].text) + } + + Assert.assertNull(card.foreignNames) + } + } + + @Test + fun getFlipCard() { + MtgCardApiClient.instance.getCard(78691).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Student of Elements") + Assert.assertEquals(card.names!![0], "Student of Elements") + Assert.assertEquals(card.names!![1], "Tobita, Master of Winds") + Assert.assertEquals(card.manaCost, "{1}{U}") + Assert.assertEquals(card.cmc, 2) + Assert.assertEquals(card.colors!![0], "Blue") + Assert.assertEquals(card.colorIdentity!![0], "U") + Assert.assertEquals(card.type, "Creature — Human Wizard") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Creature") + Assert.assertEquals(card.subtypes!![0], "Human") + Assert.assertEquals(card.subtypes!![1], "Wizard") + Assert.assertEquals(card.rarity, "Uncommon") + Assert.assertEquals(card.set, "CHK") + Assert.assertEquals(card.setName, "Champions of Kamigawa") + Assert.assertEquals(card.text, "When Student of Elements has flying, flip it.") + Assert.assertEquals(card.artist, "Ittoku") + Assert.assertEquals(card.number, "93a") + Assert.assertEquals(card.power, "1") + Assert.assertEquals(card.toughness, "1") + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 78691) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=78691&type=card") + Assert.assertEquals(card.layout, "flip") + + val legalities: List = arrayListOf( + MtgCardLegality("Commander", "Legal"), + MtgCardLegality("Kamigawa Block", "Legal"), + MtgCardLegality("Legacy", "Legal"), + MtgCardLegality("Modern", "Legal"), + MtgCardLegality("Vintage", "Legal") + ) + + card.legalities!!.forEachIndexed { index, mtgCardLegalitylegality -> + Assert.assertEquals(mtgCardLegalitylegality.format, legalities[index].format) + Assert.assertEquals(mtgCardLegalitylegality.legality, legalities[index].legality) + } + + Assert.assertNull(card.rulings) + + val foreignNames: List = arrayListOf( + MtgCardForeignName("Student of Elements", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=85443&type=card", "Chinese Simplified", 85443), + MtgCardForeignName("Student of Elements", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=85750&type=card", "French", 85750), + MtgCardForeignName("Student of Elements", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=86057&type=card", "German", 86057), + MtgCardForeignName("Student of Elements", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=86364&type=card", "Italian", 86364), + MtgCardForeignName("Student of Elements", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=86671&type=card", "Japanese", 86671), + MtgCardForeignName("Student of Elements", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=86978&type=card", "Portuguese (Brazil)", 86978), + MtgCardForeignName("Student of Elements", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=87285&type=card", "Spanish", 87285) + ) + + card.foreignNames!!.forEachIndexed { index, mtgCardForeignInfo -> + Assert.assertEquals(mtgCardForeignInfo.name, foreignNames[index].name) + Assert.assertEquals(mtgCardForeignInfo.imageUrl, foreignNames[index].imageUrl) + Assert.assertEquals(mtgCardForeignInfo.language, foreignNames[index].language) + Assert.assertEquals(mtgCardForeignInfo.multiverseid, foreignNames[index].multiverseid) + } + } + } + + @Test + fun getDoubleFacedCard() { + MtgCardApiClient.instance.getCard(409741).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Archangel Avacyn") + Assert.assertEquals(card.names!![0], "Archangel Avacyn") + Assert.assertEquals(card.names!![1], "Avacyn, the Purifier") + Assert.assertEquals(card.manaCost, "{3}{W}{W}") + Assert.assertEquals(card.cmc, 5) + Assert.assertEquals(card.colors!![0], "White") + Assert.assertEquals(card.colorIdentity!![0], "W") + Assert.assertEquals(card.type, "Legendary Creature — Angel") + Assert.assertEquals(card.supertypes!![0], "Legendary") + Assert.assertEquals(card.types[0], "Creature") + Assert.assertEquals(card.subtypes!![0], "Angel") + Assert.assertEquals(card.rarity, "Mythic Rare") + Assert.assertEquals(card.set, "SOI") + Assert.assertEquals(card.setName, "Shadows over Innistrad") + Assert.assertEquals(card.text, "Flash\nFlying, vigilance\nWhen Archangel Avacyn enters the battlefield, creatures you control gain indestructible until end of turn.\nWhen a non-Angel creature you control dies, transform Archangel Avacyn at the beginning of the next upkeep.") + Assert.assertEquals(card.artist, "James Ryman") + Assert.assertEquals(card.number, "5a") + Assert.assertEquals(card.power, "4") + Assert.assertEquals(card.toughness, "4") + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 409741) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=409741&type=card") + Assert.assertEquals(card.layout, "double-faced") + + val legalities: List = mutableListOf( + MtgCardLegality("Commander", "Legal"), + MtgCardLegality("Legacy", "Legal"), + MtgCardLegality("Modern", "Legal"), + MtgCardLegality("Shadows over Innistrad Block", "Legal"), + MtgCardLegality("Standard", "Legal"), + MtgCardLegality("Vintage", "Legal") + ) + + card.legalities!!.forEachIndexed { index, mtgCardLegalitylegality -> + Assert.assertEquals(mtgCardLegalitylegality.format, legalities[index].format) + Assert.assertEquals(mtgCardLegalitylegality.legality, legalities[index].legality) + } + + val date1: DateTime = DateTime.parse("2016-04-08", DateTimeFormatterSingleton.instance) + val date2: DateTime = DateTime.parse("2016-07-13", DateTimeFormatterSingleton.instance) + + val rulings: List = arrayListOf( + MtgCardRuling(date1, "Archangel Avacyn's delayed triggered ability triggers at the beginning of the next upkeep regardless of whose turn it is."), + MtgCardRuling(date1, "Archangel Avacyn's delayed triggered ability won't cause it to transform back into Archangel Avacyn if it has already transformed into Avacyn, the Purifier, perhaps because several creatures died in one turn."), + MtgCardRuling(date2, "For more information on double-faced cards, see the Shadows over Innistrad mechanics article (http://magic.wizards.com/en/articles/archive/feature/shadows-over-innistrad-mechanics).") + ) + + card.rulings!!.forEachIndexed { index, mtgCardRuling -> + Assert.assertEquals(mtgCardRuling.date, rulings[index].date) + Assert.assertEquals(mtgCardRuling.text, rulings[index].text) + } + + val foreignNames: List = arrayListOf( + MtgCardForeignName("大天使艾维欣", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=410071&type=card", "Chinese Simplified", 410071), + MtgCardForeignName("大天使艾維欣", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=410401&type=card", "Chinese Traditional", 410401), + MtgCardForeignName("Archange Avacyn", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=411061&type=card", "French", 411061), + MtgCardForeignName("Erzengel Avacyn", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=410731&type=card", "German", 410731), + MtgCardForeignName("Arcangelo Avacyn", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=411391&type=card", "Italian", 411391), + MtgCardForeignName("大天使アヴァシン", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=411721&type=card", "Japanese", 411721), + MtgCardForeignName("대천사 아바신", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=412051&type=card", "Korean", 412051), + MtgCardForeignName("Arcanjo Avacyn", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=412381&type=card", "Portuguese (Brazil)", 412381), + MtgCardForeignName("Архангел Авацина", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=412711&type=card", "Russian", 412711), + MtgCardForeignName("Arcángel Avacyn", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=413041&type=card", "Spanish", 413041) + ) + + card.foreignNames!!.forEachIndexed { index, mtgCardForeignInfo -> + Assert.assertEquals(mtgCardForeignInfo.name, foreignNames[index].name) + Assert.assertEquals(mtgCardForeignInfo.imageUrl, foreignNames[index].imageUrl) + Assert.assertEquals(mtgCardForeignInfo.language, foreignNames[index].language) + Assert.assertEquals(mtgCardForeignInfo.multiverseid, foreignNames[index].multiverseid) + } + } + } + + @Test + fun getSplitCard() { + MtgCardApiClient.instance.getCard(20578).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Pain") + Assert.assertEquals(card.names!![0], "Pain") + Assert.assertEquals(card.names!![1], "Suffering") + Assert.assertEquals(card.manaCost, "{B}") + Assert.assertEquals(card.cmc, 1) + Assert.assertEquals(card.colors!![0], "Black") + Assert.assertEquals(card.colorIdentity!![0], "R") + Assert.assertEquals(card.colorIdentity!![1], "B") + Assert.assertEquals(card.type, "Sorcery") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Sorcery") + Assert.assertNull(card.subtypes) + Assert.assertEquals(card.rarity, "Uncommon") + Assert.assertEquals(card.set, "INV") + Assert.assertEquals(card.setName, "Invasion") + Assert.assertEquals(card.text, "Target player discards a card.") + Assert.assertEquals(card.artist, "David Martin") + Assert.assertEquals(card.number, "294a") + Assert.assertNull(card.power) + Assert.assertNull(card.toughness) + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 20578) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=20578&type=card") + Assert.assertEquals(card.layout, "split") + + val legalities: List = arrayListOf( + MtgCardLegality("Commander", "Legal"), + MtgCardLegality("Invasion Block", "Legal"), + MtgCardLegality("Legacy", "Legal"), + MtgCardLegality("Vintage", "Legal") + ) + + card.legalities!!.forEachIndexed { index, mtgCardLegalitylegality -> + Assert.assertEquals(mtgCardLegalitylegality.format, legalities[index].format) + Assert.assertEquals(mtgCardLegalitylegality.legality, legalities[index].legality) + } + + Assert.assertNull(card.rulings) + + val foreignNames: List = arrayListOf( + MtgCardForeignName("Pain", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=185588&type=card", "French", 185588), + MtgCardForeignName("Pain", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=185589&type=card", "French", 185589), + MtgCardForeignName("Pain", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=183714&type=card", "German", 183714), + MtgCardForeignName("Pain", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=183715&type=card", "German", 183715) + ) + + card.foreignNames!!.forEachIndexed { index, mtgCardForeignInfo -> + Assert.assertEquals(mtgCardForeignInfo.name, foreignNames[index].name) + Assert.assertEquals(mtgCardForeignInfo.imageUrl, foreignNames[index].imageUrl) + Assert.assertEquals(mtgCardForeignInfo.language, foreignNames[index].language) + Assert.assertEquals(mtgCardForeignInfo.multiverseid, foreignNames[index].multiverseid) + } + } + } + + @Test + fun getTokenCard() { + MtgCardApiClient.instance.getCard(159048).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Elemental") + Assert.assertNull(card.names) + Assert.assertNull(card.manaCost) + Assert.assertNull(card.cmc) + Assert.assertNull(card.colors) + Assert.assertNull(card.colorIdentity) + Assert.assertEquals(card.type, "Creature — Elemental") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Creature") + Assert.assertEquals(card.subtypes!![0], "Elemental") + Assert.assertEquals(card.rarity, "Common") + Assert.assertEquals(card.set, "EVG") + Assert.assertEquals(card.setName, "Duel Decks: Elves vs. Goblins") + Assert.assertEquals(card.text, "Trample") + Assert.assertEquals(card.artist, "Anthony S. Waters") + Assert.assertEquals(card.number, "T1") + Assert.assertEquals(card.power, "7") + Assert.assertEquals(card.toughness, "7") + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 159048) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=159048&type=card") + Assert.assertEquals(card.layout, "token") + Assert.assertNull(card.legalities) + Assert.assertNull(card.rulings) + Assert.assertNull(card.foreignNames) + } + } + + @Test + fun getPlaneCard() { + MtgCardApiClient.instance.getCard(198073).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Academy at Tolaria West") + Assert.assertNull(card.names) + Assert.assertNull(card.manaCost) + Assert.assertNull(card.cmc) + Assert.assertNull(card.colors) + Assert.assertNull(card.colorIdentity) + Assert.assertEquals(card.type, "Plane — Dominaria") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Plane") + Assert.assertEquals(card.subtypes!![0], "Dominaria") + Assert.assertEquals(card.rarity, "Common") + Assert.assertEquals(card.set, "HOP") + Assert.assertEquals(card.setName, "Planechase") + Assert.assertEquals(card.text, "At the beginning of your end step, if you have no cards in hand, draw seven cards.\nWhenever you roll CHAOS, discard your hand.") + Assert.assertEquals(card.artist, "James Paick") + Assert.assertEquals(card.number, "1") + Assert.assertNull(card.power) + Assert.assertNull(card.toughness) + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 198073) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=198073&type=card") + Assert.assertEquals(card.layout, "plane") + Assert.assertNull(card.legalities) + + val date: DateTime = DateTime.parse("2009-10-01", DateTimeFormatterSingleton.instance) + + val rulings: List = arrayListOf( + MtgCardRuling(date, "A plane card is treated as if its text box included \"When you roll {PW}, put this card on the bottom of its owner's planar deck face down, then move the top card of your planar deck off that planar deck and turn it face up.\" This is called the \"planeswalking ability.\""), + MtgCardRuling(date, "A face-up plane card that's turned face down becomes a new object with no relation to its previous existence. In particular, it loses all counters it may have had."), + MtgCardRuling(date, "The controller of a face-up plane card is the player designated as the \"planar controller.\" Normally, the planar controller is whoever the active player is. However, if the current planar controller would leave the game, instead the next player in turn order that wouldn't leave the game becomes the planar controller, then the old planar controller leaves the game. The new planar controller retains that designation until he or she leaves the game or a different player becomes the active player, whichever comes first."), + MtgCardRuling(date, "If an ability of a plane refers to \"you,\" it's referring to whoever the plane's controller is at the time, not to the player that started the game with that plane card in his or her deck. Many abilities of plane cards affect all players, while many others affect only the planar controller, so read each ability carefully."), + MtgCardRuling(date, "Academy at Tolaria West's first ability has an \"intervening 'if' clause.\" That means (1) the ability won't trigger at all unless you have no cards in hand as your end step begins, and (2) the ability will do nothing unless you have no cards in hand by the time it resolves."), + MtgCardRuling(date, "If you discard your hand as a result of rolling {CHAOS}, Academy at Tolaria West's first ability will then trigger at the beginning of your end step (unless you planeswalk or somehow put a card in your hand before then).") + ) + + card.rulings!!.forEachIndexed { index, mtgCardRuling -> + Assert.assertEquals(mtgCardRuling.date, rulings[index].date) + Assert.assertEquals(mtgCardRuling.text, rulings[index].text) + } + + val foreignNames: List = arrayListOf( + MtgCardForeignName("Académie de l'Ouest de Tolaria", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=211853&type=card", "French", 211853), + MtgCardForeignName("Akademie von West-Tolaria", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=211763&type=card", "German", 211763), + MtgCardForeignName("Accademia di Tolaria Occidentale", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=211808&type=card", "Italian", 211808), + MtgCardForeignName("トレイリア西部のアカデミー", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=211943&type=card", "Japanese", 211943), + MtgCardForeignName("Academia en Tolaria Oeste", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=211898&type=card", "Spanish", 211898) + ) + + card.foreignNames!!.forEachIndexed { index, mtgCardForeignInfo -> + Assert.assertEquals(mtgCardForeignInfo.name, foreignNames[index].name) + Assert.assertEquals(mtgCardForeignInfo.imageUrl, foreignNames[index].imageUrl) + Assert.assertEquals(mtgCardForeignInfo.language, foreignNames[index].language) + Assert.assertEquals(mtgCardForeignInfo.multiverseid, foreignNames[index].multiverseid) + } + } + } + + @Test + fun getSchemeCard() { + MtgCardApiClient.instance.getCard(212648).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "All in Good Time") + Assert.assertNull(card.names) + Assert.assertNull(card.manaCost) + Assert.assertNull(card.cmc) + Assert.assertNull(card.colors) + Assert.assertNull(card.colorIdentity) + Assert.assertEquals(card.type, "Scheme") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Scheme") + Assert.assertNull(card.subtypes) + Assert.assertEquals(card.rarity, "Common") + Assert.assertEquals(card.set, "ARC") + Assert.assertEquals(card.setName, "Archenemy") + Assert.assertEquals(card.text, "When you set this scheme in motion, take an extra turn after this one. Schemes can't be set in motion that turn.") + Assert.assertEquals(card.artist, "Nic Klein") + Assert.assertEquals(card.number, "1") + Assert.assertNull(card.power) + Assert.assertNull(card.toughness) + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 212648) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=212648&type=card") + Assert.assertEquals(card.layout, "scheme") + Assert.assertNull(card.legalities) + Assert.assertNull(card.rulings) + + val foreignNames: List = arrayListOf( + MtgCardForeignName("Toute chose en son temps", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=235062&type=card", "French", 235062), + MtgCardForeignName("Alles zu seiner Zeit", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=234912&type=card", "German", 234912), + MtgCardForeignName("Tutto a Suo Tempo", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=234862&type=card", "Italian", 234862), + MtgCardForeignName("全ては成されるべきもの", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=234962&type=card", "Japanese", 234962), + MtgCardForeignName("Cada cosa a su tiempo", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=235012&type=card", "Spanish", 235012) + ) + + card.foreignNames!!.forEachIndexed { index, mtgCardForeignInfo -> + Assert.assertEquals(mtgCardForeignInfo.name, foreignNames[index].name) + Assert.assertEquals(mtgCardForeignInfo.imageUrl, foreignNames[index].imageUrl) + Assert.assertEquals(mtgCardForeignInfo.language, foreignNames[index].language) + Assert.assertEquals(mtgCardForeignInfo.multiverseid, foreignNames[index].multiverseid) + } + } + } + + @Test + fun getPhenomenonCard() { + MtgCardApiClient.instance.getCard(226509).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Chaotic Aether") + Assert.assertNull(card.names) + Assert.assertNull(card.manaCost) + Assert.assertNull(card.cmc) + Assert.assertNull(card.colors) + Assert.assertNull(card.colorIdentity) + Assert.assertEquals(card.type, "Phenomenon") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Phenomenon") + Assert.assertNull(card.subtypes) + Assert.assertEquals(card.rarity, "Common") + Assert.assertEquals(card.set, "PC2") + Assert.assertEquals(card.setName, "Planechase 2012 Edition") + Assert.assertEquals(card.text, "When you encounter Chaotic Aether, each blank roll of the planar die is a CHAOS roll until a player planeswalks away from a plane. (Then planeswalk away from this phenomenon.)") + Assert.assertEquals(card.artist, "Dan Scott") + Assert.assertEquals(card.number, "1") + Assert.assertNull(card.power) + Assert.assertNull(card.toughness) + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 226509) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=226509&type=card") + Assert.assertEquals(card.layout, "phenomenon") + Assert.assertNull(card.legalities) + + val date: DateTime = DateTime.parse("2012-06-01", DateTimeFormatterSingleton.instance) + + val rulings: List = arrayListOf( + MtgCardRuling(date, "While Chaotic Aether's effect applies, rolling any blank face of the planar die will cause chaos abilities to trigger."), + MtgCardRuling(date, "Planeswalking away from a phenomenon (as you do when resolving Chaotic Aether's ability) doesn't cause Chaotic Aether's effect to expire.") + ) + + card.rulings!!.forEachIndexed { index, mtgCardRuling -> + Assert.assertEquals(mtgCardRuling.date, rulings[index].date) + Assert.assertEquals(mtgCardRuling.text, rulings[index].text) + } + + val foreignNames: List = arrayListOf( + MtgCardForeignName("Æther chaotique", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=288474&type=card", "French", 288474), + MtgCardForeignName("Chaotischer Äther", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=288515&type=card", "German", 288515), + MtgCardForeignName("Etere Caotico", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=288597&type=card", "Italian", 288597), + MtgCardForeignName("混沌の霊気", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=288638&type=card", "Japanese", 288638), + MtgCardForeignName("Éter caótico", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=288556&type=card", "Spanish", 288556) + ) + + card.foreignNames!!.forEachIndexed { index, mtgCardForeignInfo -> + Assert.assertEquals(mtgCardForeignInfo.name, foreignNames[index].name) + Assert.assertEquals(mtgCardForeignInfo.imageUrl, foreignNames[index].imageUrl) + Assert.assertEquals(mtgCardForeignInfo.language, foreignNames[index].language) + Assert.assertEquals(mtgCardForeignInfo.multiverseid, foreignNames[index].multiverseid) + } + } + } + + @Test + fun getLevelerCard() { + MtgCardApiClient.instance.getCard(194918).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Caravan Escort") + Assert.assertNull(card.names) + Assert.assertEquals(card.manaCost, "{W}") + Assert.assertEquals(card.cmc, 1) + Assert.assertEquals(card.colors!![0], "White") + Assert.assertEquals(card.colorIdentity!![0], "W") + Assert.assertEquals(card.type, "Creature — Human Knight") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Creature") + Assert.assertEquals(card.subtypes!![0], "Human") + Assert.assertEquals(card.subtypes!![1], "Knight") + Assert.assertEquals(card.rarity, "Common") + Assert.assertEquals(card.set, "ROE") + Assert.assertEquals(card.setName, "Rise of the Eldrazi") + Assert.assertEquals(card.text, "Level up {2} ({2}: Put a level counter on this. Level up only as a sorcery.)\nLEVEL 1-4\n2/2\nLEVEL 5+\n5/5\nFirst strike") + Assert.assertEquals(card.artist, "Goran Josic") + Assert.assertEquals(card.number, "15") + Assert.assertEquals(card.power, "1") + Assert.assertEquals(card.toughness, "1") + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 194918) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=194918&type=card") + Assert.assertEquals(card.layout, "leveler") + + val legalities: List = arrayListOf( + MtgCardLegality("Commander", "Legal"), + MtgCardLegality("Legacy", "Legal"), + MtgCardLegality("Modern", "Legal"), + MtgCardLegality("Vintage", "Legal"), + MtgCardLegality("Zendikar Block", "Legal") + ) + + card.legalities!!.forEachIndexed { index, mtgCardLegalitylegality -> + Assert.assertEquals(mtgCardLegalitylegality.format, legalities[index].format) + Assert.assertEquals(mtgCardLegalitylegality.legality, legalities[index].legality) + } + + val date: DateTime = DateTime.parse("2010-06-15", DateTimeFormatterSingleton.instance) + + val rulings: List = arrayListOf( + MtgCardRuling(date, "The abilities a leveler grants to itself don't overwrite any other abilities it may have. In particular, they don't overwrite the creature's level up ability; it always has that."), + MtgCardRuling(date, "Effects that set a leveler's power or toughness to a specific value, including the effects from a level symbol's ability, apply in timestamp order. The timestamp of each level symbol's ability is the same as the timestamp of the leveler itself, regardless of when the most recent level counter was put on it."), + MtgCardRuling(date, "Effects that modify a leveler's power or toughness, such as the effects of Giant Growth or Glorious Anthem, will apply to it no matter when they started to take effect. The same is true for counters that change the creature's power or toughness (such as +1/+1 counters) and effects that switch its power and toughness."), + MtgCardRuling(date, "If another creature becomes a copy of a leveler, all of the leveler's printed abilities -- including those represented by level symbols -- are copied. The current characteristics of the leveler, and the number of level counters on it, are not. The abilities, power, and toughness of the copy will be determined based on how many level counters are on the copy."), + MtgCardRuling(date, "A creature's level is based on how many level counters it has on it, not how many times its level up ability has been activated or has resolved. If a leveler gets level counters due to some other effect (such as Clockspinning) or loses level counters for some reason (such as Vampire Hexmage), its level is changed accordingly.") + ) + + card.rulings!!.forEachIndexed { index, mtgCardRuling -> + Assert.assertEquals(mtgCardRuling.date, rulings[index].date) + Assert.assertEquals(mtgCardRuling.text, rulings[index].text) + } + + val foreignNames: List = arrayListOf( + MtgCardForeignName("商队卫士", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=216227&type=card", "Chinese Simplified", 216227), + MtgCardForeignName("Escorte de caravane", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=215731&type=card", "French", 215731), + MtgCardForeignName("Karawaneneskorte", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=217467&type=card", "German", 217467), + MtgCardForeignName("Scorta della Carovana", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=216475&type=card", "Italian", 216475), + MtgCardForeignName("隊商の随員", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=216723&type=card", "Japanese", 216723), + MtgCardForeignName("Escolta de Caravana", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=216971&type=card", "Portuguese (Brazil)", 216971), + MtgCardForeignName("Сопроводитель Каравана", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=215979&type=card", "Russian", 215979), + MtgCardForeignName("Escolta de caravana", "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=217219&type=card", "Spanish", 217219) + ) + + card.foreignNames!!.forEachIndexed { index, mtgCardForeignInfo -> + Assert.assertEquals(mtgCardForeignInfo.name, foreignNames[index].name) + Assert.assertEquals(mtgCardForeignInfo.imageUrl, foreignNames[index].imageUrl) + Assert.assertEquals(mtgCardForeignInfo.language, foreignNames[index].language) + Assert.assertEquals(mtgCardForeignInfo.multiverseid, foreignNames[index].multiverseid) + } + } + } + + @Test + fun getVanguardCard() { + MtgCardApiClient.instance.getCard(12329).subscribe { card: MtgCard -> + Assert.assertEquals(card.name, "Ashnod") + Assert.assertNull(card.names) + Assert.assertNull(card.manaCost) + Assert.assertNull(card.cmc) + Assert.assertNull(card.colors) + Assert.assertNull(card.colorIdentity) + Assert.assertEquals(card.type, "Vanguard") + Assert.assertNull(card.supertypes) + Assert.assertEquals(card.types[0], "Vanguard") + Assert.assertNull(card.subtypes) + Assert.assertEquals(card.rarity, "Special") + Assert.assertEquals(card.set, "VAN") + Assert.assertEquals(card.setName, "Vanguard") + Assert.assertEquals(card.text, "Whenever a creature deals damage to you, destroy it.") + Assert.assertEquals(card.artist, "Ron Spencer") + Assert.assertNull(card.number) + Assert.assertNull(card.power) + Assert.assertNull(card.toughness) + Assert.assertNull(card.loyalty) + Assert.assertEquals(card.multiverseid, 12329) + Assert.assertEquals(card.imageUrl, "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=12329&type=card") + Assert.assertEquals(card.layout, "vanguard") + } + } +} \ No newline at end of file