Program: 11302
Project: 11302
Buggy source:
@Test public void shouldFetch_withAttributeQueryOnIndex() throws Exception {
  final AttributeQuery query=mock(AttributeQuery.class);
  final Condition mockCondition=mock(Condition.class);
  when(mockCondition.getComparisonOperator()).thenReturn(Operators.EQUALS);
  final String itemId=randomId();
  final String stringProperty=randomString(10);
  final Set<String> stringPropertyValues=new HashSet<>(Arrays.asList(stringProperty));
  when(mockCondition.getValues()).thenReturn(stringPropertyValues);
  when(mockCondition.containsNonNullOrEmptyValues()).thenReturn(true);
  when(query.getAttributeName()).thenReturn("String_Node_Str");
  when(query.getCondition()).thenReturn(mockCondition);
  final ItemConfiguration itemConfiguration=new ItemConfiguration(StubItem.class,tableName);
  itemConfiguration.registerIndexes(Arrays.asList(new IndexDefinition("String_Node_Str")));
  final Collection<ItemConfiguration> itemConfigurations=Arrays.asList(itemConfiguration);
  when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations);
  final DynamoDbTemplate dynamoDbTemplate=new DynamoDbTemplate(mockDatabaseSchemaHolder);
  final QueryResult mockQueryResult=mock(QueryResult.class);
  final Map<String,AttributeValue> mockItem=new HashMap<>();
  mockItem.put("String_Node_Str",new AttributeValue(itemId));
  mockItem.put("String_Node_Str",new AttributeValue(stringProperty));
  final List<Map<String,AttributeValue>> mockItems=Arrays.asList(mockItem);
  when(mockQueryResult.getItems()).thenReturn(mockItems);
  when(mockQueryResult.getLastEvaluatedKey()).thenReturn(null);
  when(mockAmazonDynamoDbClient.query(any(QueryRequest.class))).thenReturn(mockQueryResult);
  dynamoDbTemplate.initialize(mockAmazonDynamoDbClient);
  final Collection<StubItem> returnedItems=dynamoDbTemplate.fetch(query,StubItem.class);
  final ArgumentCaptor<QueryRequest> queryRequestArgumentCaptor=ArgumentCaptor.forClass(QueryRequest.class);
  verify(mockAmazonDynamoDbClient).query(queryRequestArgumentCaptor.capture());
  final QueryRequest queryRequest=queryRequestArgumentCaptor.getValue();
  assertEquals(schemaName + "String_Node_Str" + tableName,queryRequest.getTableName());
  assertEquals("String_Node_Str",queryRequest.getIndexName());
  assertEquals(1,queryRequest.getKeyConditions().size());
  assertEquals("String_Node_Str",queryRequest.getKeyConditions().get("String_Node_Str").getComparisonOperator());
  assertEquals(1,queryRequest.getKeyConditions().get("String_Node_Str").getAttributeValueList().size());
  assertEquals(new AttributeValue(stringProperty),queryRequest.getKeyConditions().get("String_Node_Str").getAttributeValueList().get(0));
  assertNotNull(returnedItems);
  assertEquals(1,returnedItems.size());
}

Fixed version (ground truth):
@Test public void shouldFetch_withAttributeQueryOnIndex() throws Exception {
  final AttributeQuery query=mock(AttributeQuery.class);
  final Condition mockCondition=mock(Condition.class);
  when(mockCondition.getComparisonOperator()).thenReturn(Operators.EQUALS);
  final String itemId=randomId();
  final String stringProperty=randomString(10);
  final Set<String> stringPropertyValues=new HashSet<>(Arrays.asList(stringProperty));
  when(mockCondition.getValues()).thenReturn(stringPropertyValues);
  when(mockCondition.containsRequiredComparisonValues()).thenReturn(true);
  when(query.getAttributeName()).thenReturn("String_Node_Str");
  when(query.getCondition()).thenReturn(mockCondition);
  final ItemConfiguration itemConfiguration=new ItemConfiguration(StubItem.class,tableName);
  itemConfiguration.registerIndexes(Arrays.asList(new IndexDefinition("String_Node_Str")));
  final Collection<ItemConfiguration> itemConfigurations=Arrays.asList(itemConfiguration);
  when(mockDatabaseSchemaHolder.itemConfigurations()).thenReturn(itemConfigurations);
  final DynamoDbTemplate dynamoDbTemplate=new DynamoDbTemplate(mockDatabaseSchemaHolder);
  final QueryResult mockQueryResult=mock(QueryResult.class);
  final Map<String,AttributeValue> mockItem=new HashMap<>();
  mockItem.put("String_Node_Str",new AttributeValue(itemId));
  mockItem.put("String_Node_Str",new AttributeValue(stringProperty));
  final List<Map<String,AttributeValue>> mockItems=Arrays.asList(mockItem);
  when(mockQueryResult.getItems()).thenReturn(mockItems);
  when(mockQueryResult.getLastEvaluatedKey()).thenReturn(null);
  when(mockAmazonDynamoDbClient.query(any(QueryRequest.class))).thenReturn(mockQueryResult);
  dynamoDbTemplate.initialize(mockAmazonDynamoDbClient);
  final Collection<StubItem> returnedItems=dynamoDbTemplate.fetch(query,StubItem.class);
  final ArgumentCaptor<QueryRequest> queryRequestArgumentCaptor=ArgumentCaptor.forClass(QueryRequest.class);
  verify(mockAmazonDynamoDbClient).query(queryRequestArgumentCaptor.capture());
  final QueryRequest queryRequest=queryRequestArgumentCaptor.getValue();
  assertEquals(schemaName + "String_Node_Str" + tableName,queryRequest.getTableName());
  assertEquals("String_Node_Str",queryRequest.getIndexName());
  assertEquals(1,queryRequest.getKeyConditions().size());
  assertEquals("String_Node_Str",queryRequest.getKeyConditions().get("String_Node_Str").getComparisonOperator());
  assertEquals(1,queryRequest.getKeyConditions().get("String_Node_Str").getAttributeValueList().size());
  assertEquals(new AttributeValue(stringProperty),queryRequest.getKeyConditions().get("String_Node_Str").getAttributeValueList().get(0));
  assertNotNull(returnedItems);
  assertEquals(1,returnedItems.size());
}