Skip to content

Commit

Permalink
add a test to check that return type of getAllGameResults is explicit…
Browse files Browse the repository at this point in the history
…ly specified
  • Loading branch information
Daoortor committed Aug 16, 2024
1 parent 084ede9 commit a1c17c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions wordsGeneratorServer/wordsGeneratorServerFinishGame/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ the `jetbrains.kotlin.course.words.generator.results` package. Note, this class
- Implement the `saveGameResults` method, which adds `result` to `gameHistory`.
Before adding `result`, you need to check for two requirements and throw an error if they are broken: 1) `result` must
not be empty; 2) all team ids in `result` must be present in `TeamService.teamsStorage`.
- Implement the `getAllGameResults` method, which returns the reversed `gameHistory` list.
- Implement the `getAllGameResults` method, which returns the reversed `gameHistory` list. Its return type should be specified explicitly.


<div class="hint" title="Click me if you pressed Check and found a compilation error">

If you have a compilation error and you have not solved this step yet, please solve the task and try again.
It is expected behavior, since the code requires the type alia `GameResult`, but it does not exist.
It is expected behavior, since the code requires the type alias `GameResult`, but it does not exist.
</div>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import commonTests.team.*
import jetbrains.kotlin.course.words.generator.util.words
import org.jetbrains.academy.test.system.findMethod
import org.jetbrains.academy.test.system.models.classes.ConstructorGetter
import org.jetbrains.academy.test.system.models.classes.findClass
import org.jetbrains.academy.test.system.models.method.TestMethodInvokeData
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import java.lang.reflect.Field
import kotlin.reflect.jvm.kotlinFunction

class Test {
companion object {
Expand All @@ -33,6 +36,14 @@ class Test {
ConstructorGetter(),
)
)

val methodKFunction = clazz.methods.findMethod(getAllGameResultsMethod).kotlinFunction
val methodReturnType = (methodKFunction ?: error("Method getAllGameResults doesn't exist")).returnType
Assertions.assertTrue(methodReturnType.arguments.size == 1,
"Return type of method getAllGameResults should have 1 type argument")
Assertions.assertTrue((methodReturnType.arguments.first().type?.toString() ?: "").contains("GameResult"),
"Return type of method getAllGameResults should be specified explicitly as List<GameResult>")

gameResultsServiceTestClass.checkDeclaredMethods(clazz)
}

Expand Down Expand Up @@ -233,4 +244,4 @@ class Test {
getIdFromTeamMethod
) { constructor.newInstance() }
}
}
}

0 comments on commit a1c17c3

Please sign in to comment.