Skip to content

Commit

Permalink
added test for transforming nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
dpnolte committed Nov 4, 2018
1 parent 9475575 commit 3a49336
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.laidpack.typescript.codegen

import com.laidpack.annotation.TypeScript
import com.laidpack.typescript.annotation.TypeScript
import com.laidpack.typescript.codegen.moshi.ITargetType
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.asTypeName
import me.eugeniomarletti.kotlin.metadata.*
import me.eugeniomarletti.kotlin.processing.KotlinAbstractProcessor
import java.io.File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,35 @@ internal class TypeScriptTypeTransformerTest {
}

@Test
fun `transformType - given int annotated with Test, return custom value transformed any`() {
fun `transformType - given int annotated with Test, return custom value transformed string`() {
// Assemble
Mockito.`when`(mockedBodyType.canonicalName).`it returns`(Int::class.java.canonicalName)
Mockito.`when`(mockedBodyType.isPrimitiveOrStringType).`it returns`(true)
Mockito.`when`(mockedBodyType.annotationNames).`it returns`(setOf("Test"))

// Act
val customValueTransformer = TypeTransformer({ t -> t.annotationNames.contains("Test")}, "string")
val customValueTransformer = TypeTransformer({ t -> t.annotationNames.contains("Test")}, "string", Nullability.NoTransform)
val transformer = TypeScriptTypeTransformer(listOf(customValueTransformer))
val result = transformer.transformType(mockedBodyType, setOf(), mapOf())

// Assert
result shouldEqual "string"
}

@Test
fun `transformType - given non-nullable int annotated with Test, return transformed nullability as null`() {
// Assemble
Mockito.`when`(mockedBodyType.canonicalName).`it returns`(Int::class.java.canonicalName)
Mockito.`when`(mockedBodyType.isPrimitiveOrStringType).`it returns`(true)
Mockito.`when`(mockedBodyType.annotationNames).`it returns`(setOf("Test"))

// Act
val customValueTransformer = TypeTransformer({ t -> t.annotationNames.contains("Test")}, "string", Nullability.Null)
val transformer = TypeScriptTypeTransformer(listOf(customValueTransformer))
val result = transformer.isNullable(mockedBodyType)

// Assert
result shouldEqual true
}

}

0 comments on commit 3a49336

Please sign in to comment.