Skip to content

Commit a3da180

Browse files
authored
Merge pull request #48 from Yelp/add-junit-tests
Add JUnit Tests for the plugin classes
2 parents 55f6c88 + e298a23 commit a3da180

File tree

5 files changed

+440
-19
lines changed

5 files changed

+440
-19
lines changed

plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pluginBundle {
5050

5151
detekt {
5252
toolVersion = "1.0.0-RC16"
53-
input = files("src/main")
53+
input = files("src/")
5454
config = files("./detekt-config.yml")
5555
buildUponDefaultConfig = true
5656
filters = ".*/resources/.*,.*/build/.*"

plugin/src/main/java/com/yelp/codegen/KotlinGenerator.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package com.yelp.codegen
44

5+
import com.google.common.annotations.VisibleForTesting
56
import com.yelp.codegen.utils.KotlinLangUtils
67
import com.yelp.codegen.utils.safeSuffix
78
import com.yelp.codegen.utils.sanitizeKotlinSpecificNames
@@ -62,7 +63,8 @@ class KotlinGenerator : SharedCodegen() {
6263
* ABSTRACT FIELDS AND CONFIG FUNCTIONS
6364
==================================================== */
6465

65-
override val platform = "android"
66+
@VisibleForTesting
67+
public override val platform = "android"
6668

6769
override fun getName() = "kotlin"
6870

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

134-
override fun listTypeWrapper(listType: String, innerType: String) =
136+
@VisibleForTesting
137+
public override fun listTypeWrapper(listType: String, innerType: String) =
135138
"$listType<$innerType>"
136139

137-
override fun mapTypeWrapper(mapType: String, innerType: String) =
140+
@VisibleForTesting
141+
public override fun mapTypeWrapper(mapType: String, innerType: String) =
138142
"$mapType<${typeMapping["string"]}, $innerType>"
139143

140-
override fun nullableTypeWrapper(baseType: String) =
144+
@VisibleForTesting
145+
public override fun nullableTypeWrapper(baseType: String) =
141146
baseType.safeSuffix("?")
142147

143148
/*
@@ -151,7 +156,8 @@ class KotlinGenerator : SharedCodegen() {
151156
specialCharReplacements.remove("_")
152157
}
153158

154-
override fun isReservedWord(word: String?) = word in reservedWords
159+
@VisibleForTesting
160+
public override fun isReservedWord(word: String?) = word in reservedWords
155161

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

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

304-
override fun addImport(model: CodegenModel, type: String?) {
311+
@VisibleForTesting
312+
public override fun addImport(model: CodegenModel, type: String?) {
305313
if (type != null && needToImport(type) && type in importMapping) {
306314
model.imports.add(type)
307315
}

0 commit comments

Comments
 (0)