15
15
package com .amazonaws .services .dynamodbv2 .datamodeling .encryption ;
16
16
17
17
import static com .amazonaws .services .dynamodbv2 .datamodeling .encryption .utils .EncryptionContextOperators .overrideEncryptionContextTableName ;
18
+ import static org .hamcrest .Matchers .not ;
19
+ import static org .hamcrest .Matchers .equalTo ;
18
20
import static org .junit .Assert .assertArrayEquals ;
19
21
import static org .junit .Assert .assertEquals ;
20
- import static org .junit .Assert .assertNotEquals ;
21
22
import static org .junit .Assert .assertNotNull ;
22
23
import static org .junit .Assert .assertNull ;
23
24
import static org .junit .Assert .assertThat ;
@@ -69,7 +70,8 @@ public class DynamoDBEncryptorTest {
69
70
private DynamoDBEncryptor encryptor ;
70
71
private Map <String , AttributeValue > attribs ;
71
72
private EncryptionContext context ;
72
-
73
+ private static final String OVERRIDDEN_TABLE_NAME = "TheBestTableName" ;
74
+
73
75
@ BeforeClass
74
76
public static void setUpClass () throws Exception {
75
77
KeyGenerator aesGen = KeyGenerator .getInstance ("AES" );
@@ -316,9 +318,9 @@ public void testNullEncryptionContextOperator() throws GeneralSecurityException
316
318
@ Test
317
319
public void testTableNameOverriddenEncryptionContextOperator () throws GeneralSecurityException {
318
320
// Ensure that the table name is different from what we override the table to.
319
- assertNotEquals (context .getTableName (), "TheBestTableName" );
321
+ assertThat (context .getTableName (), not ( equalTo ( OVERRIDDEN_TABLE_NAME )) );
320
322
DynamoDBEncryptor encryptor = DynamoDBEncryptor .getInstance (prov );
321
- encryptor .setEncryptionContextOverrideOperator (overrideEncryptionContextTableName (context .getTableName (), "TheBestTableName" ));
323
+ encryptor .setEncryptionContextOverrideOperator (overrideEncryptionContextTableName (context .getTableName (), OVERRIDDEN_TABLE_NAME ));
322
324
Map <String , AttributeValue > encryptedItems = encryptor .encryptAllFieldsExcept (attribs , context , Collections .emptyList ());
323
325
Map <String , AttributeValue > decryptedItems = encryptor .decryptAllFieldsExcept (encryptedItems , context , Collections .emptyList ());
324
326
assertThat (decryptedItems , AttrMatcher .match (attribs ));
@@ -332,10 +334,10 @@ public void testTableNameOverriddenEncryptionContextOperator() throws GeneralSec
332
334
@ Test
333
335
public void testTableNameOverriddenEncryptionContextOperatorWithSecondEncryptor () throws GeneralSecurityException {
334
336
// Ensure that the table name is different from what we override the table to.
335
- assertNotEquals (context .getTableName (), "TheBestTableName" );
337
+ assertThat (context .getTableName (), not ( equalTo ( OVERRIDDEN_TABLE_NAME )) );
336
338
DynamoDBEncryptor encryptor = DynamoDBEncryptor .getInstance (prov );
337
339
DynamoDBEncryptor encryptorWithoutOverride = DynamoDBEncryptor .getInstance (prov );
338
- encryptor .setEncryptionContextOverrideOperator (overrideEncryptionContextTableName (context .getTableName (), "TheBestTableName" ));
340
+ encryptor .setEncryptionContextOverrideOperator (overrideEncryptionContextTableName (context .getTableName (), OVERRIDDEN_TABLE_NAME ));
339
341
Map <String , AttributeValue > encryptedItems = encryptor .encryptAllFieldsExcept (attribs , context , Collections .emptyList ());
340
342
341
343
EncryptionContext expectedOverriddenContext = new EncryptionContext .Builder (context ).withTableName ("TheBestTableName" ).build ();
@@ -351,10 +353,10 @@ public void testTableNameOverriddenEncryptionContextOperatorWithSecondEncryptor(
351
353
@ Test (expected = SignatureException .class )
352
354
public void testTableNameOverriddenEncryptionContextOperatorWithSecondEncryptorButTheOriginalEncryptionContext () throws GeneralSecurityException {
353
355
// Ensure that the table name is different from what we override the table to.
354
- assertNotEquals (context .getTableName (), "TheBestTableName" );
356
+ assertThat (context .getTableName (), not ( equalTo ( OVERRIDDEN_TABLE_NAME )) );
355
357
DynamoDBEncryptor encryptor = DynamoDBEncryptor .getInstance (prov );
356
358
DynamoDBEncryptor encryptorWithoutOverride = DynamoDBEncryptor .getInstance (prov );
357
- encryptor .setEncryptionContextOverrideOperator (overrideEncryptionContextTableName (context .getTableName (), "TheBestTableName" ));
359
+ encryptor .setEncryptionContextOverrideOperator (overrideEncryptionContextTableName (context .getTableName (), OVERRIDDEN_TABLE_NAME ));
358
360
Map <String , AttributeValue > encryptedItems = encryptor .encryptAllFieldsExcept (attribs , context , Collections .emptyList ());
359
361
360
362
// Use the original encryption context, and expect a signature failure
0 commit comments