Skip to content

Commit

Permalink
Fixed TestMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
anchouls committed Dec 20, 2023
1 parent 4b7ceea commit 2e3e3dd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "org.jetbrains.academy.test.system"
version = "2.1.1"
version = "2.1.2"

allprojects {
apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ fun Array<Method>.findMethod(method: TestMethod, customErrorMessage: String? = n
it.name == method.name
}
}
val returnTypeJava = (listOf(method.returnTypeJava)).map { it.lowercase() }
val returnTypeJava = (method.returnTypeJava?.let { listOf(it) } ?: listOfNotNull(method.returnType.type, *method.returnType.possibleBounds.toTypedArray())).map { it.lowercase() }
val filteredByType =
filteredByName.filterByCondition(customErrorMessage ?: "The method ${method.name} should have the return type ${method.returnType?.getTypePrettyString()}") {
filteredByName.filterByCondition(customErrorMessage ?: "The method ${method.name} should have the return type ${method.returnType.getTypePrettyString()}") {
it.returnType.name.getShortName().lowercase() in returnTypeJava
}
val filteredByArgumentsCount =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import kotlin.reflect.jvm.kotlinFunction
*/
data class TestMethod(
val name: String,
val returnTypeJava: String,
val returnType: TestKotlinType? = null,
val returnType: TestKotlinType,
val arguments: List<TestVariable> = emptyList(),
val returnTypeJava: String? = null,
val visibility: Visibility = Visibility.PUBLIC,
val hasGeneratedPartInName: Boolean = false,
) {
Expand All @@ -33,23 +33,21 @@ data class TestMethod(
visibility: Visibility
) : this(
name = name,
returnTypeJava = returnTypeJava,
returnType = null,
returnType = TestKotlinType(returnTypeJava),
arguments = arguments,
returnTypeJava = returnTypeJava,
visibility = visibility,
hasGeneratedPartInName = false
)

private fun getTypePrettyString() = returnType?.getTypePrettyString() ?: returnTypeJava

fun prettyString(withToDo: Boolean = true): String {
val args = arguments.joinToString(", ") { it.paramPrettyString() }
val body = if (withToDo) {
"TODO(\"Not implemented yet\")"
} else {
"// Some code"
}
return "${visibility.key} fun $name($args): ${getTypePrettyString()} = $body"
return "${visibility.key} fun $name($args): ${returnType.getTypePrettyString()} = $body"
}

private fun TestVariable.paramPrettyString() = "$name: $javaType"
Expand All @@ -64,6 +62,6 @@ data class TestMethod(
this.visibility.key,
"\"The visibility of the method $name must be ${this.visibility.key}\""
)
kotlinFunction.returnType.checkType(returnType, returnTypeJava, "the function $name")
kotlinFunction.returnType.checkType(returnType, returnTypeJava ?: returnType.type, "the function $name")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ val javaClassTestClass = TestClass(
TestMethod(
name = "publicMethod",
returnTypeJava = "void",
arguments = emptyList(),
visibility = Visibility.PUBLIC
),
TestMethod(
name = "privateMethod",
returnTypeJava = "void",
arguments = emptyList(),
visibility = Visibility.PRIVATE
),
TestMethod(
Expand Down

0 comments on commit 2e3e3dd

Please sign in to comment.