Skip to content

Commit ed0112a

Browse files
authored
Merge pull request #66 from johnwalker/hamcrest
Refactor DynamoDBEncryptorTests to use hamcrest
2 parents 102cd23 + 244c417 commit ed0112a

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
<scope>test</scope>
6969
</dependency>
7070

71+
<dependency>
72+
<groupId>org.hamcrest</groupId>
73+
<artifactId>hamcrest-all</artifactId>
74+
<version>1.3</version>
75+
<scope>test</scope>
76+
</dependency>
77+
7178
<dependency>
7279
<groupId>org.bouncycastle</groupId>
7380
<artifactId>bcprov-ext-jdk15on</artifactId>

src/test/java/com/amazonaws/services/dynamodbv2/datamodeling/encryption/DynamoDBEncryptorTest.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
package com.amazonaws.services.dynamodbv2.datamodeling.encryption;
1616

1717
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;
1820
import static org.junit.Assert.assertArrayEquals;
1921
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotEquals;
2122
import static org.junit.Assert.assertNotNull;
2223
import static org.junit.Assert.assertNull;
2324
import static org.junit.Assert.assertThat;
@@ -69,7 +70,8 @@ public class DynamoDBEncryptorTest {
6970
private DynamoDBEncryptor encryptor;
7071
private Map<String, AttributeValue> attribs;
7172
private EncryptionContext context;
72-
73+
private static final String OVERRIDDEN_TABLE_NAME = "TheBestTableName";
74+
7375
@BeforeClass
7476
public static void setUpClass() throws Exception {
7577
KeyGenerator aesGen = KeyGenerator.getInstance("AES");
@@ -316,9 +318,9 @@ public void testNullEncryptionContextOperator() throws GeneralSecurityException
316318
@Test
317319
public void testTableNameOverriddenEncryptionContextOperator() throws GeneralSecurityException {
318320
// 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)));
320322
DynamoDBEncryptor encryptor = DynamoDBEncryptor.getInstance(prov);
321-
encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), "TheBestTableName"));
323+
encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), OVERRIDDEN_TABLE_NAME));
322324
Map<String, AttributeValue> encryptedItems = encryptor.encryptAllFieldsExcept(attribs, context, Collections.emptyList());
323325
Map<String, AttributeValue> decryptedItems = encryptor.decryptAllFieldsExcept(encryptedItems, context, Collections.emptyList());
324326
assertThat(decryptedItems, AttrMatcher.match(attribs));
@@ -332,10 +334,10 @@ public void testTableNameOverriddenEncryptionContextOperator() throws GeneralSec
332334
@Test
333335
public void testTableNameOverriddenEncryptionContextOperatorWithSecondEncryptor() throws GeneralSecurityException {
334336
// 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)));
336338
DynamoDBEncryptor encryptor = DynamoDBEncryptor.getInstance(prov);
337339
DynamoDBEncryptor encryptorWithoutOverride = DynamoDBEncryptor.getInstance(prov);
338-
encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), "TheBestTableName"));
340+
encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), OVERRIDDEN_TABLE_NAME));
339341
Map<String, AttributeValue> encryptedItems = encryptor.encryptAllFieldsExcept(attribs, context, Collections.emptyList());
340342

341343
EncryptionContext expectedOverriddenContext = new EncryptionContext.Builder(context).withTableName("TheBestTableName").build();
@@ -351,10 +353,10 @@ public void testTableNameOverriddenEncryptionContextOperatorWithSecondEncryptor(
351353
@Test(expected = SignatureException.class)
352354
public void testTableNameOverriddenEncryptionContextOperatorWithSecondEncryptorButTheOriginalEncryptionContext() throws GeneralSecurityException {
353355
// 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)));
355357
DynamoDBEncryptor encryptor = DynamoDBEncryptor.getInstance(prov);
356358
DynamoDBEncryptor encryptorWithoutOverride = DynamoDBEncryptor.getInstance(prov);
357-
encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), "TheBestTableName"));
359+
encryptor.setEncryptionContextOverrideOperator(overrideEncryptionContextTableName(context.getTableName(), OVERRIDDEN_TABLE_NAME));
358360
Map<String, AttributeValue> encryptedItems = encryptor.encryptAllFieldsExcept(attribs, context, Collections.emptyList());
359361

360362
// Use the original encryption context, and expect a signature failure

0 commit comments

Comments
 (0)