Skip to content

Commit a1c17c3

Browse files
committed
add a test to check that return type of getAllGameResults is explicitly specified
1 parent 084ede9 commit a1c17c3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

wordsGeneratorServer/wordsGeneratorServerFinishGame/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ the `jetbrains.kotlin.course.words.generator.results` package. Note, this class
1111
- Implement the `saveGameResults` method, which adds `result` to `gameHistory`.
1212
Before adding `result`, you need to check for two requirements and throw an error if they are broken: 1) `result` must
1313
not be empty; 2) all team ids in `result` must be present in `TeamService.teamsStorage`.
14-
- Implement the `getAllGameResults` method, which returns the reversed `gameHistory` list.
14+
- Implement the `getAllGameResults` method, which returns the reversed `gameHistory` list. Its return type should be specified explicitly.
1515

1616

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

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

2323

wordsGeneratorServer/wordsGeneratorServerFinishGame/test/Tests.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import commonTests.team.*
22
import jetbrains.kotlin.course.words.generator.util.words
3+
import org.jetbrains.academy.test.system.findMethod
34
import org.jetbrains.academy.test.system.models.classes.ConstructorGetter
45
import org.jetbrains.academy.test.system.models.classes.findClass
56
import org.jetbrains.academy.test.system.models.method.TestMethodInvokeData
7+
import org.junit.jupiter.api.Assertions
68
import org.junit.jupiter.api.Test
79
import org.junit.jupiter.params.ParameterizedTest
810
import org.junit.jupiter.params.provider.Arguments
911
import org.junit.jupiter.params.provider.MethodSource
1012
import java.lang.reflect.Field
13+
import kotlin.reflect.jvm.kotlinFunction
1114

1215
class Test {
1316
companion object {
@@ -33,6 +36,14 @@ class Test {
3336
ConstructorGetter(),
3437
)
3538
)
39+
40+
val methodKFunction = clazz.methods.findMethod(getAllGameResultsMethod).kotlinFunction
41+
val methodReturnType = (methodKFunction ?: error("Method getAllGameResults doesn't exist")).returnType
42+
Assertions.assertTrue(methodReturnType.arguments.size == 1,
43+
"Return type of method getAllGameResults should have 1 type argument")
44+
Assertions.assertTrue((methodReturnType.arguments.first().type?.toString() ?: "").contains("GameResult"),
45+
"Return type of method getAllGameResults should be specified explicitly as List<GameResult>")
46+
3647
gameResultsServiceTestClass.checkDeclaredMethods(clazz)
3748
}
3849

@@ -233,4 +244,4 @@ class Test {
233244
getIdFromTeamMethod
234245
) { constructor.newInstance() }
235246
}
236-
}
247+
}

0 commit comments

Comments
 (0)