Skip to content

Commit

Permalink
Merge pull request #48 from Yelp/add-junit-tests
Browse files Browse the repository at this point in the history
Add JUnit Tests for the plugin classes
  • Loading branch information
cortinico committed Jul 12, 2019
2 parents 55f6c88 + e298a23 commit a3da180
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 19 deletions.
2 changes: 1 addition & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pluginBundle {

detekt {
toolVersion = "1.0.0-RC16"
input = files("src/main")
input = files("src/")
config = files("./detekt-config.yml")
buildUponDefaultConfig = true
filters = ".*/resources/.*,.*/build/.*"
Expand Down
22 changes: 15 additions & 7 deletions plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package com.yelp.codegen

import com.google.common.annotations.VisibleForTesting
import com.yelp.codegen.utils.KotlinLangUtils
import com.yelp.codegen.utils.safeSuffix
import com.yelp.codegen.utils.sanitizeKotlinSpecificNames
Expand Down Expand Up @@ -62,7 +63,8 @@ class KotlinGenerator : SharedCodegen() {
* ABSTRACT FIELDS AND CONFIG FUNCTIONS
==================================================== */

override val platform = "android"
@VisibleForTesting
public override val platform = "android"

override fun getName() = "kotlin"

Expand Down Expand Up @@ -131,13 +133,16 @@ class KotlinGenerator : SharedCodegen() {
/** No testing files are needed on Kotlin Generator */
override val testingSupportFiles = listOf<SupportingFile>()

override fun listTypeWrapper(listType: String, innerType: String) =
@VisibleForTesting
public override fun listTypeWrapper(listType: String, innerType: String) =
"$listType<$innerType>"

override fun mapTypeWrapper(mapType: String, innerType: String) =
@VisibleForTesting
public override fun mapTypeWrapper(mapType: String, innerType: String) =
"$mapType<${typeMapping["string"]}, $innerType>"

override fun nullableTypeWrapper(baseType: String) =
@VisibleForTesting
public override fun nullableTypeWrapper(baseType: String) =
baseType.safeSuffix("?")

/*
Expand All @@ -151,7 +156,8 @@ class KotlinGenerator : SharedCodegen() {
specialCharReplacements.remove("_")
}

override fun isReservedWord(word: String?) = word in reservedWords
@VisibleForTesting
public override fun isReservedWord(word: String?) = word in reservedWords

// remove " to avoid code injection
override fun escapeQuotationMark(input: String) = input.replace("\"", "")
Expand All @@ -176,7 +182,8 @@ class KotlinGenerator : SharedCodegen() {
return codegenModel
}

private fun addRequiredImports(codegenModel: CodegenModel) {
@VisibleForTesting
internal fun addRequiredImports(codegenModel: CodegenModel) {
// If there are any vars, we will mark them with the @Json annotation so we have to make sure to import it
if (codegenModel.vars.isNotEmpty() || codegenModel.isEnum) {
codegenModel.imports.add("com.squareup.moshi.Json")
Expand Down Expand Up @@ -301,7 +308,8 @@ class KotlinGenerator : SharedCodegen() {
}
}

override fun addImport(model: CodegenModel, type: String?) {
@VisibleForTesting
public override fun addImport(model: CodegenModel, type: String?) {
if (type != null && needToImport(type) && type in importMapping) {
model.imports.add(type)
}
Expand Down
Loading

0 comments on commit a3da180

Please sign in to comment.