### Question:
DynamoDbEncryptor implements DynamoDbEncryptionClient { void setEncryptionContextOverrideOperator( Function<EncryptionContext, EncryptionContext> encryptionContextOverrideOperator) { this.encryptionContextOverrideOperator = encryptionContextOverrideOperator; } protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider, String descriptionBase); protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider); static Builder builder(); @Override Map<String, AttributeValue> encryptRecord(Map<String, AttributeValue> record,
                                                     DynamoDbEncryptionConfiguration configuration); @Override Map<String, AttributeValue> decryptRecord(Map<String, AttributeValue> record,
                                                     DynamoDbEncryptionConfiguration configuration);  }### Answer:
@Test public void testNullEncryptionContextOperator() { DynamoDbEncryptor encryptor = new DynamoDbEncryptor(prov); encryptor.setEncryptionContextOverrideOperator(null); EncryptionTestHelper.encryptAllFieldsExcept(encryptor, attribs, context, Collections.emptyList()); }
@Test public void testTableNameOverriddenEncryptionContextOperator() { assertThat(context.getTableName(), not(equalTo(OVERRIDDEN_TABLE_NAME))); DynamoDbEncryptor encryptor = new DynamoDbEncryptor(prov); encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), OVERRIDDEN_TABLE_NAME)); Map<String, AttributeValue> encryptedItems = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, attribs, context, Collections.emptyList()); Map<String, AttributeValue> decryptedItems = EncryptionTestHelper.decryptAllFieldsExcept(encryptor, encryptedItems, context, Collections.emptyList()); assertThat(decryptedItems, AttrMatcher.match(attribs)); }
@Test public void testTableNameOverriddenEncryptionContextOperatorWithSecondEncryptor() { assertThat(context.getTableName(), not(equalTo(OVERRIDDEN_TABLE_NAME))); DynamoDbEncryptor encryptor = new DynamoDbEncryptor(prov); DynamoDbEncryptor encryptorWithoutOverride = new DynamoDbEncryptor(prov); encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), OVERRIDDEN_TABLE_NAME)); Map<String, AttributeValue> encryptedItems = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, attribs, context, Collections.emptyList()); EncryptionContext expectedOverriddenContext = context.toBuilder().tableName("TheBestTableName").build(); Map<String, AttributeValue> decryptedItems = EncryptionTestHelper.decryptAllFieldsExcept(encryptorWithoutOverride, encryptedItems, expectedOverriddenContext, Collections.emptyList()); assertThat(decryptedItems, AttrMatcher.match(attribs)); }
@Test(expectedExceptions = DynamoDbEncryptionException.class) public void testTableNameOverriddenEncryptionContextOperatorWithSecondEncryptorButTheOriginalEncryptionContext() { assertThat(context.getTableName(), not(equalTo(OVERRIDDEN_TABLE_NAME))); DynamoDbEncryptor encryptor = new DynamoDbEncryptor(prov); DynamoDbEncryptor encryptorWithoutOverride = new DynamoDbEncryptor(prov); encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), OVERRIDDEN_TABLE_NAME)); Map<String, AttributeValue> encryptedItems = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, attribs, context, Collections.emptyList()); EncryptionTestHelper.decryptAllFieldsExcept(encryptorWithoutOverride, encryptedItems, context, Collections.emptyList()); }