Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JUnit Tests for the plugin classes #48

Merged
merged 4 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/")
cortinico marked this conversation as resolved.
Show resolved Hide resolved
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) =
cortinico marked this conversation as resolved.
Show resolved Hide resolved
"$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) {
cortinico marked this conversation as resolved.
Show resolved Hide resolved
// 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