@@ -3,6 +3,7 @@ package de.joshuagleitze.stringnotation
33import ch.tutteli.atrium.api.fluent.en_GB.feature
44import ch.tutteli.atrium.api.fluent.en_GB.toBe
55import ch.tutteli.atrium.api.verbs.expect
6+ import org.junit.jupiter.api.Assumptions.assumeTrue
67import org.junit.jupiter.api.TestInstance
78import org.junit.jupiter.params.ParameterizedTest
89import org.junit.jupiter.params.provider.Arguments
@@ -11,29 +12,32 @@ import org.junit.jupiter.params.provider.MethodSource
1112@TestInstance(TestInstance .Lifecycle .PER_CLASS )
1213abstract class BaseNotationTest (
1314 private val notation : StringNotation ,
14- private val unchangedWords : List <Pair < String , Word > >,
15- private val parseOnlyWords : List <Pair < String , Word > > = emptyList(),
16- private val printOnlyWords : List <Pair < Word , String > > = emptyList()
15+ private val unchangedWords : List <NotationTestData >,
16+ private val parseOnlyWords : List <NotationTestData > = emptyList(),
17+ private val printOnlyWords : List <NotationTestData > = emptyList()
1718) {
18- @ParameterizedTest(name = " \" {0 }\" -> {1 }" )
19+ @ParameterizedTest(name = " \" {1 }\" -> {2 }" )
1920 @MethodSource(" parseWords" )
20- fun `parses words correctly` (input : String , expectedWord : Word ) {
21+ fun `parses words correctly` (minimumJavaVersion : Int , input : String , expectedWord : Word ) {
22+ assumeTrue(currentJavaVersion >= minimumJavaVersion, " Requires at least Java $minimumJavaVersion " )
2123 expect(input.fromNotation(notation)) {
2224 feature(Word ::partsList).toBe(expectedWord.partsList)
2325 }
2426 }
2527
26- @ParameterizedTest(name = " {1 } -> \" {0 }\" " )
28+ @ParameterizedTest(name = " {2 } -> \" {1 }\" " )
2729 @MethodSource(" printWords" )
28- fun `prints words correctly` (sourceWord : Word , expectedResult : String ) {
30+ fun `prints words correctly` (minimumJavaVersion : Int , expectedResult : String , sourceWord : Word ) {
31+ assumeTrue(currentJavaVersion >= minimumJavaVersion, " Requires at least Java $minimumJavaVersion " )
2932 expect(sourceWord) {
3033 feature(Word ::toNotation, notation).toBe(expectedResult)
3134 }
3235 }
3336
34- @ParameterizedTest(name = " \" {0 }\" " )
37+ @ParameterizedTest(name = " \" {1 }\" " )
3538 @MethodSource(" unchangedWords" )
36- fun `parsing and printing a word written in this notation does not change the word` (word : String ) {
39+ fun `parsing and printing a word written in this notation does not change the word` (minimumJavaVersion : Int , word : String ) {
40+ assumeTrue(currentJavaVersion >= minimumJavaVersion, " Requires at least Java $minimumJavaVersion " )
3741 expect(word) {
3842 feature(String ::fromNotation, notation) {
3943 feature(Word ::toNotation, notation).toBe(word)
@@ -42,15 +46,27 @@ abstract class BaseNotationTest(
4246 }
4347
4448 private fun parseWords () = asArguments(unchangedWords + parseOnlyWords)
45- private fun printWords () = asArguments(unchangedWords.map { it.swap() } + printOnlyWords)
49+ private fun printWords () = asArguments(unchangedWords + printOnlyWords)
4650 private fun unchangedWords () = asArguments(unchangedWords)
4751
48- private fun asArguments (pairs : List <Pair < * , * > >) = pairs.map {
52+ private fun asArguments (pairs : List <NotationTestData >) = pairs.map {
4953 Arguments .arguments(
50- it.first,
51- it.second
54+ it.minimumJavaVersion,
55+ it.string,
56+ it.word
5257 )
5358 }
59+ }
60+
61+ data class NotationTestData (val word : Word , val string : String , var minimumJavaVersion : Int = 0 )
62+
63+ infix fun Word.to (string : String ) = NotationTestData (this , string)
64+ infix fun String.to (word : Word ) = NotationTestData (word, this )
65+ infix fun NotationTestData.ifJvmVersionIsAtLeast (minimumJavaVersion : Int ) = this .apply { this .minimumJavaVersion = minimumJavaVersion }
5466
55- private fun <First , Second > Pair <First , Second >.swap () = Pair (this .second, this .first)
67+ val currentJavaVersion by lazy {
68+ System .getProperty(" java.runtime.version" )
69+ .split(" ." )
70+ .let { if (it[0 ] == " 1" ) it.drop(1 ) else it }[0 ]
71+ .toInt()
5672}
0 commit comments