2929import org .junit .jupiter .api .Test ;
3030import org .junit .jupiter .api .condition .EnabledIfEnvironmentVariable ;
3131import org .junit .jupiter .api .condition .EnabledIfEnvironmentVariables ;
32+ import org .junit .jupiter .params .ParameterizedTest ;
33+ import org .junit .jupiter .params .provider .EnumSource ;
34+ import org .junit .jupiter .params .provider .NullSource ;
3235import org .slf4j .Logger ;
3336import org .slf4j .LoggerFactory ;
3437import software .amazon .awssdk .services .kms .KmsClient ;
@@ -80,14 +83,12 @@ public void testKeyWrapping() {
8083 }
8184 }
8285
83- @ Test
84- public void testKeyGeneration () {
85- testKeyGenerationWithDataKeySpec (null );
86- testKeyGenerationWithDataKeySpec (DataKeySpec .AES_128 );
87- testKeyGenerationWithDataKeySpec (DataKeySpec .AES_256 );
88- }
89-
90- private void testKeyGenerationWithDataKeySpec (DataKeySpec dataKeySpec ) {
86+ @ ParameterizedTest
87+ @ NullSource
88+ @ EnumSource (
89+ value = DataKeySpec .class ,
90+ names = {"AES_128" , "AES_256" })
91+ public void testKeyGeneration (DataKeySpec dataKeySpec ) {
9192 AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient ();
9293 try {
9394 Map <String , String > properties =
@@ -98,13 +99,20 @@ private void testKeyGenerationWithDataKeySpec(DataKeySpec dataKeySpec) {
9899 KeyManagementClient .KeyGenerationResult result = keyManagementClient .generateKey (keyId );
99100
100101 assertThat (keyManagementClient .unwrapKey (result .wrappedKey (), keyId )).isEqualTo (result .key ());
101- assertThat (result .key ().limit ())
102- .isEqualTo (DataKeySpec .AES_128 .equals (dataKeySpec ) ? 128 / 8 : 256 / 8 );
102+ assertThat (result .key ().limit ()).isEqualTo (expectedLength (dataKeySpec ));
103103 } finally {
104104 keyManagementClient .close ();
105105 }
106106 }
107107
108+ private static int expectedLength (DataKeySpec spec ) {
109+ if (DataKeySpec .AES_128 .equals (spec )) {
110+ return 128 / 8 ;
111+ } else {
112+ return 256 / 8 ;
113+ }
114+ }
115+
108116 @ AfterAll
109117 public static void afterClass () {
110118 // AWS KMS doesn't allow instant deletion. Keys can be put to pendingDeletion state instead,
0 commit comments