24
24
import software .amazon .awssdk .codegen .poet .ClassSpec ;
25
25
import software .amazon .awssdk .codegen .poet .PoetUtils ;
26
26
27
-
28
27
public class VersionCompatibilityTestSpec implements ClassSpec {
29
28
private final IntermediateModel model ;
30
29
@@ -37,6 +36,7 @@ public TypeSpec poetSpec() {
37
36
return PoetUtils .createClassBuilder (className ())
38
37
.addModifiers (Modifier .PUBLIC )
39
38
.addMethod (compatibilityTest ())
39
+ .addMethod (isVersionCompatibleMethod ())
40
40
.build ();
41
41
}
42
42
@@ -58,11 +58,42 @@ private MethodSpec compatibilityTest() {
58
58
.addModifiers (Modifier .PUBLIC )
59
59
.addAnnotation (Test .class )
60
60
.returns (void .class )
61
- .addStatement ("$T.assertThat($T.SDK_VERSION).isEqualTo($T.VERSION)" ,
62
- assertions ,
63
- versionInfo ,
64
- serviceVersionInfo )
61
+ .addStatement ("String coreVersion = $T.SDK_VERSION" , versionInfo )
62
+ .addStatement ("String serviceVersion = $T.VERSION" , serviceVersionInfo )
63
+ .addStatement ("$T.assertThat(isVersionCompatible(coreVersion, serviceVersion))" +
64
+ ".withFailMessage(\" Core version %s must be equal to or newer than service version %s\" , " +
65
+ "coreVersion, serviceVersion).isTrue()" ,
66
+ assertions )
65
67
.build ();
66
68
}
67
69
70
+ private MethodSpec isVersionCompatibleMethod () {
71
+ return MethodSpec .methodBuilder ("isVersionCompatible" )
72
+ .addModifiers (Modifier .PRIVATE )
73
+ .returns (boolean .class )
74
+ .addParameter (String .class , "coreVersion" )
75
+ .addParameter (String .class , "serviceVersion" )
76
+ .addStatement ("String normalizedCore = coreVersion.replace(\" -SNAPSHOT\" , \" \" )" )
77
+ .addStatement ("String normalizedService = serviceVersion.replace(\" -SNAPSHOT\" , \" \" )" )
78
+ .addStatement ("String[] coreParts = normalizedCore.split(\" \\ \\ .\" )" )
79
+ .addStatement ("String[] serviceParts = normalizedService.split(\" \\ \\ .\" )" )
80
+ .addCode ("\n " )
81
+ .addStatement ("int coreMajor = Integer.parseInt(coreParts[0])" )
82
+ .addStatement ("int serviceMajor = Integer.parseInt(serviceParts[0])" )
83
+ .beginControlFlow ("if (coreMajor != serviceMajor)" )
84
+ .addStatement ("return coreMajor >= serviceMajor" )
85
+ .endControlFlow ()
86
+ .addCode ("\n " )
87
+ .addStatement ("int coreMinor = Integer.parseInt(coreParts[1])" )
88
+ .addStatement ("int serviceMinor = Integer.parseInt(serviceParts[1])" )
89
+ .beginControlFlow ("if (coreMinor != serviceMinor)" )
90
+ .addStatement ("return coreMinor >= serviceMinor" )
91
+ .endControlFlow ()
92
+ .addCode ("\n " )
93
+ .addStatement ("int corePatch = Integer.parseInt(coreParts[2])" )
94
+ .addStatement ("int servicePatch = Integer.parseInt(serviceParts[2])" )
95
+ .addStatement ("return corePatch >= servicePatch" )
96
+ .build ();
97
+ }
68
98
}
99
+
0 commit comments