Source:
<code>public void shouldQueryIndex_withCompoundAttributeQuery() { final ItemId itemId = new ItemId(randomId()); final ItemConfiguration itemConfiguration = new ItemConfiguration(StubWithGlobalSecondaryIndexItem.class, tableName); itemConfiguration.registerIndexes((Arrays.asList(new CompoundIndexDefinition("gsi", "gsiSupportingValue")))); final Collection<ItemConfiguration> itemConfigurations = Arrays.asList(itemConfiguration); when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations); final Table mockTable = mock(Table.class); when(mockDynamoDBClient.getTable(any(String.class))).thenReturn(mockTable); final DynamoDocumentStoreTemplate dynamoDocumentStoreTemplate = new DynamoDocumentStoreTemplate( mockDatabaseSchemaHolder); dynamoDocumentStoreTemplate.initialize(mockAmazonDynamoDbClient); final Index mockIndex = mock(Index.class); when(mockTable.getIndex(anyString())).thenReturn(mockIndex); final ItemCollection<QueryOutcome> outcome = mock(ItemCollection.class); when(mockIndex.query(any(QuerySpec.class))).thenReturn(outcome); <START> dynamoDocumentStoreTemplate.fetch( <END> new CompoundAttributeQuery("gsi", new Condition(Operators.EQUALS, itemId.value()), "gsiSupportingValue", new Condition(Operators.EQUALS, String.valueOf(randomInt(10)))), StubWithGlobalSecondaryIndexItem.class); final ArgumentCaptor<QuerySpec> querySpecCaptor = ArgumentCaptor.forClass(QuerySpec.class); verify(mockIndex).query(querySpecCaptor.capture()); assertNotNull(querySpecCaptor.getValue().getRangeKeyCondition()); }</code><technical_language>Surely need "fetch" call</technical_language>

Target:
public void shouldQueryIndex_withCompoundAttributeQuery() { final ItemId itemId = new ItemId(randomId()); final ItemConfiguration itemConfiguration = new ItemConfiguration(StubWithGlobalSecondaryIndexItem.class, tableName); itemConfiguration.registerIndexes((Arrays.asList(new CompoundIndexDefinition("gsi", "gsiSupportingValue")))); final Collection<ItemConfiguration> itemConfigurations = Arrays.asList(itemConfiguration); when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations); final Table mockTable = mock(Table.class); when(mockDynamoDBClient.getTable(any(String.class))).thenReturn(mockTable); final DynamoDocumentStoreTemplate dynamoDocumentStoreTemplate = new DynamoDocumentStoreTemplate( mockDatabaseSchemaHolder); dynamoDocumentStoreTemplate.initialize(mockAmazonDynamoDbClient); final Index mockIndex = mock(Index.class); when(mockTable.getIndex(anyString())).thenReturn(mockIndex); final ItemCollection<QueryOutcome> mockOutcome = mock(ItemCollection.class); when(mockIndex.query(any(QuerySpec.class))).thenReturn(mockOutcome); final IteratorSupport<Item, QueryOutcome> mockIterator = mock(IteratorSupport.class); final Item mockItem = new Item(); mockItem.withString(randomString(), randomString()); when(mockOutcome.iterator()).thenReturn(mockIterator); when(mockIterator.hasNext()).thenReturn(true, false); when(mockIterator.next()).thenReturn(mockItem); final Collection<StubWithGlobalSecondaryIndexItem> stubWithGlobalSecondaryIndexItemCollection = dynamoDocumentStoreTemplate .fetch(new CompoundAttributeQuery("gsi", new Condition(Operators.EQUALS, itemId.value()), "gsiSupportingValue", new Condition(Operators.EQUALS, String.valueOf(randomInt(10)))), StubWithGlobalSecondaryIndexItem.class); assertTrue(stubWithGlobalSecondaryIndexItemCollection.size() == 1); final ArgumentCaptor<QuerySpec> querySpecCaptor = ArgumentCaptor.forClass(QuerySpec.class); verify(mockIndex).query(querySpecCaptor.capture()); assertNotNull(querySpecCaptor.getValue().getRangeKeyCondition()); }