Skip to content

Commit

Permalink
Update tests to stop using KClass.qualifiedName().
Browse files Browse the repository at this point in the history
  • Loading branch information
andersio committed Jul 25, 2020
1 parent 275dc15 commit ab46dd8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
Expand Up @@ -170,7 +170,7 @@ class SimpleResponseReaderTest {
}

override fun className(): String {
return Map::class.qualifiedName!!
return "kotlin.collections.Map"
}
}
val successField = ResponseField.forCustomType("successFieldResponseName", "successFieldName", null,
Expand Down Expand Up @@ -205,7 +205,7 @@ class SimpleResponseReaderTest {
}

override fun className(): String {
return List::class.qualifiedName!!
return "kotlin.collections.List"
}
}
val successField = ResponseField.forCustomType("successFieldResponseName", "successFieldName", null,
Expand All @@ -224,19 +224,19 @@ class SimpleResponseReaderTest {
@Test
fun readCustomWithDefaultAdapter() {
val stringField = ResponseField.forCustomType("stringField", "stringField", null, false,
scalarTypeFor(String::class), noConditions)
scalarTypeFor(String::class, "kotlin.String"), noConditions)
val booleanField = ResponseField.forCustomType("booleanField", "booleanField", null, false,
scalarTypeFor(Boolean::class), noConditions)
scalarTypeFor(Boolean::class, "kotlin.Boolean"), noConditions)
val integerField = ResponseField.forCustomType("integerField", "integerField", null, false,
scalarTypeFor(Int::class), noConditions)
scalarTypeFor(Int::class, "kotlin.Int"), noConditions)
val longField = ResponseField.forCustomType("longField", "longField", null, false,
scalarTypeFor(Long::class), noConditions)
scalarTypeFor(Long::class, "kotlin.Long"), noConditions)
val floatField = ResponseField.forCustomType("floatField", "floatField", null, false,
scalarTypeFor(Float::class), noConditions)
scalarTypeFor(Float::class, "kotlin.Float"), noConditions)
val doubleField = ResponseField.forCustomType("doubleField", "doubleField", null, false,
scalarTypeFor(Double::class), noConditions)
scalarTypeFor(Double::class, "kotlin.Double"), noConditions)
val unsupportedField = ResponseField.forCustomType("unsupportedField", "unsupportedField", null, false,
scalarTypeFor(RuntimeException::class), noConditions)
scalarTypeFor(RuntimeException::class, "kotlin.RuntimeException"), noConditions)
val recordSet: MutableMap<String, Any> = HashMap()
recordSet[stringField.responseName] = "string"
recordSet[booleanField.responseName] = true
Expand Down Expand Up @@ -527,14 +527,14 @@ class SimpleResponseReaderTest {
return SimpleResponseReader(recordSet, EMPTY_OPERATION.variables(), ScalarTypeAdapters(customTypeAdapters))
}

private fun scalarTypeFor(clazz: KClass<*>): ScalarType {
private fun scalarTypeFor(clazz: KClass<*>, className: String): ScalarType {
return object : ScalarType {
override fun typeName(): String {
return clazz.simpleName!!
}

override fun className(): String {
return clazz.qualifiedName!!
return className
}
}
}
Expand All @@ -545,7 +545,7 @@ class SimpleResponseReaderTest {
}

override fun className(): String {
return String::class.qualifiedName!!
return "kotlin.String"
}
}
}
Expand Down
Expand Up @@ -7,6 +7,7 @@ import com.apollographql.apollo.api.ScalarType
import com.apollographql.apollo.api.ScalarTypeAdapters
import com.apollographql.apollo.api.internal.InputFieldMarshaller
import com.apollographql.apollo.api.internal.InputFieldWriter
import com.apollographql.apollo.api.toNumber
import okio.Buffer
import kotlin.reflect.KClass
import kotlin.test.Test
Expand Down Expand Up @@ -51,14 +52,15 @@ class InputFieldJsonWriterTest {
@Test
fun writeCustomNumber() {
val customTypeAdapters: MutableMap<ScalarType, CustomTypeAdapter<*>> = HashMap()
customTypeAdapters[MockCustomScalarType(CustomTypeValue.GraphQLNumber::class)] = object : MockCustomTypeAdapter() {
val scalarType = MockCustomScalarType(CustomTypeValue.GraphQLNumber::class, "com.apollographql.apollo.api.CustomTypeValue.GraphQLNumber")
customTypeAdapters[scalarType] = object : MockCustomTypeAdapter() {
override fun encode(value: Any?): CustomTypeValue<*> {
return CustomTypeValue.GraphQLNumber((value as BigDecimal).toDouble())
return CustomTypeValue.GraphQLNumber((value as BigDecimal).toNumber())
}
}
val inputFieldJsonWriter = InputFieldJsonWriter(jsonWriter, ScalarTypeAdapters(customTypeAdapters))
inputFieldJsonWriter.writeCustom("someField", MockCustomScalarType(CustomTypeValue.GraphQLNumber::class), BigDecimal("100.1"))
inputFieldJsonWriter.writeCustom("someNullField", MockCustomScalarType(CustomTypeValue.GraphQLNumber::class), null)
inputFieldJsonWriter.writeCustom("someField", scalarType, BigDecimal("100.1"))
inputFieldJsonWriter.writeCustom("someNullField", scalarType, null)
assertEquals("{\"someField\":100.1,\"someNullField\":null", jsonBuffer.readUtf8())
}

Expand Down Expand Up @@ -94,28 +96,30 @@ class InputFieldJsonWriterTest {
@Test
fun writeCustomBoolean() {
val customTypeAdapters: MutableMap<ScalarType, CustomTypeAdapter<*>> = HashMap()
customTypeAdapters[MockCustomScalarType(CustomTypeValue.GraphQLBoolean::class)] = object : MockCustomTypeAdapter() {
val scalarType = MockCustomScalarType(CustomTypeValue.GraphQLBoolean::class, "com.apollographql.apollo.api.CustomTypeValue.GraphQLBoolean")
customTypeAdapters[scalarType] = object : MockCustomTypeAdapter() {
override fun encode(value: Any?): CustomTypeValue<*> {
return CustomTypeValue.GraphQLBoolean((value as Boolean))
}
}
val inputFieldJsonWriter = InputFieldJsonWriter(jsonWriter, ScalarTypeAdapters(customTypeAdapters))
inputFieldJsonWriter.writeCustom("someField", MockCustomScalarType(CustomTypeValue.GraphQLBoolean::class), true)
inputFieldJsonWriter.writeCustom("someNullField", MockCustomScalarType(CustomTypeValue.GraphQLBoolean::class), null)
inputFieldJsonWriter.writeCustom("someField", scalarType, true)
inputFieldJsonWriter.writeCustom("someNullField", scalarType, null)
assertEquals("{\"someField\":true,\"someNullField\":null", jsonBuffer.readUtf8())
}

@Test
fun writeCustomString() {
val customTypeAdapters: MutableMap<ScalarType, CustomTypeAdapter<*>> = HashMap()
customTypeAdapters[MockCustomScalarType(CustomTypeValue.GraphQLString::class)] = object : MockCustomTypeAdapter() {
val scalarType = MockCustomScalarType(CustomTypeValue.GraphQLString::class, "com.apollographql.apollo.api.CustomTypeValue.GraphQLString")
customTypeAdapters[scalarType] = object : MockCustomTypeAdapter() {
override fun encode(value: Any?): CustomTypeValue<*> {
return CustomTypeValue.GraphQLString((value as String))
}
}
val inputFieldJsonWriter = InputFieldJsonWriter(jsonWriter, ScalarTypeAdapters(customTypeAdapters))
inputFieldJsonWriter.writeCustom("someField", MockCustomScalarType(CustomTypeValue.GraphQLString::class), "someValue")
inputFieldJsonWriter.writeCustom("someNullField", MockCustomScalarType(CustomTypeValue.GraphQLString::class), null)
inputFieldJsonWriter.writeCustom("someField", scalarType, "someValue")
inputFieldJsonWriter.writeCustom("someNullField", scalarType, null)
assertEquals("{\"someField\":\"someValue\",\"someNullField\":null", jsonBuffer.readUtf8())
}

Expand Down Expand Up @@ -143,8 +147,9 @@ class InputFieldJsonWriterTest {
"listField" to listOf(1, 2, 3)
)
)
inputFieldJsonWriter.writeCustom("someField", MockCustomScalarType(Map::class), value)
inputFieldJsonWriter.writeCustom("someNullField", MockCustomScalarType(Map::class), null)
val scalarType = MockCustomScalarType(Map::class, "kotlin.collections.Map")
inputFieldJsonWriter.writeCustom("someField", scalarType, value)
inputFieldJsonWriter.writeCustom("someNullField", scalarType, null)
assertEquals("{\"someField\":{\"stringField\":\"string\",\"booleanField\":true,\"numberField\":100,\"listField\":[\"string\",true,100,{\"stringField\":\"string\",\"numberField\":100,\"booleanField\":true,\"listField\":[1,2,3]}],\"objectField\":{\"stringField\":\"string\",\"numberField\":100,\"booleanField\":true,\"listField\":[1,2,3]}},\"someNullField\":null", jsonBuffer.readUtf8())
}

Expand All @@ -161,8 +166,9 @@ class InputFieldJsonWriterTest {
"listField" to listOf(1, 2, 3)
)
)
inputFieldJsonWriter.writeCustom("someField", MockCustomScalarType(List::class), value)
inputFieldJsonWriter.writeCustom("someNullField", MockCustomScalarType(List::class), null)
val scalarType = MockCustomScalarType(List::class, "kotlin.collections.List")
inputFieldJsonWriter.writeCustom("someField", scalarType, value)
inputFieldJsonWriter.writeCustom("someNullField", scalarType, null)
assertEquals("{\"someField\":[\"string\",true,100,{\"stringField\":\"string\",\"numberField\":100,\"booleanField\":true,\"listField\":[1,2,3]}],\"someNullField\":null", jsonBuffer.readUtf8())
}

Expand All @@ -183,13 +189,13 @@ class InputFieldJsonWriterTest {
}


data class MockCustomScalarType internal constructor(val clazz: KClass<*>) : ScalarType {
data class MockCustomScalarType internal constructor(val clazz: KClass<*>, val className: String) : ScalarType {
override fun typeName(): String {
return clazz.simpleName!!
}

override fun kotlinClass(): KClass<*> {
return clazz
override fun className(): String {
return className
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Expand Up @@ -2,7 +2,7 @@ def versions = [
minAndroidPlugin : '3.4.2',
androidPlugin : '3.6.2',
androidxSqlite : '2.1.0',
apollo : '2.2.3-SNAPSHOT', // This should only be used by apollo-gradle-plugin-incubating:test to get the artifacts locally
apollo : '3.0.0-alpha01', // This should only be used by apollo-gradle-plugin-incubating:test to get the artifacts locally
antlr4 : '4.5.3',
cache : '2.0.2',
compiletesting : '0.15',
Expand Down

0 comments on commit ab46dd8

Please sign in to comment.