### Question:
QuerySpecBuilder { public static <T extends Item> QuerySpec build(final AttributeQuery attributeQuery, final Class<T> itemClass) { if (CompoundAttributeQuery.class.isAssignableFrom(attributeQuery.getClass())) { final CompoundAttributeQuery compoundAttributeQuery = (CompoundAttributeQuery) attributeQuery; return buildWithHashAndRangeKey(compoundAttributeQuery, itemClass); } return buildWithHashKey(attributeQuery); }  static QuerySpec build(final AttributeQuery attributeQuery, final Class<T> itemClass);  }### Answer:
@Test public void shouldBuild_withAttributeQuery() { final String attributeName = randomString(10); final Condition mockCondition = randomCondition(1); final String expectedValue = mockCondition.getValues().iterator().next(); final AttributeQuery mockAttributeQuery = mock(AttributeQuery.class); when(mockAttributeQuery.getAttributeName()).thenReturn(attributeName); when(mockAttributeQuery.getCondition()).thenReturn(mockCondition); final QuerySpec querySpec = QuerySpecBuilder.build(mockAttributeQuery, StubItem.class); assertEquals(attributeName, querySpec.getHashKey().getName()); assertEquals(expectedValue, querySpec.getHashKey().getValue()); assertNull(querySpec.getRangeKeyCondition()); }
@Test public void shouldBuild_withCompoundAttributeQuery() { final String attributeName = randomString(10); final String supportingAttributeName = randomString(10); final Condition condition = randomCondition(1); final Condition supportingCondition = randomCondition(1); final CompoundAttributeQuery compoundAttributeQuery = mock(CompoundAttributeQuery.class); final RangeKeyCondition mockRangeKeyCondition = mock(RangeKeyCondition.class); final String expectedValue = condition.getValues().iterator().next(); final String expectedSupportingValue = supportingCondition.getValues().iterator().next(); final Operators expectedSupportingComparisonOperator = supportingCondition.getComparisonOperator(); when(compoundAttributeQuery.getAttributeName()).thenReturn(attributeName); when(compoundAttributeQuery.getCondition()).thenReturn(condition); when(compoundAttributeQuery.getSupportingCondition()).thenReturn(supportingCondition); Mockito.<Class<?>> when(compoundAttributeQuery.getSupportingAttributeType(any())).thenReturn(String.class); when(compoundAttributeQuery.getSupportingAttributeName()).thenReturn(supportingAttributeName); when(RangeKeyConditionBuilder.build(supportingAttributeName, expectedSupportingValue, expectedSupportingComparisonOperator)).thenReturn(mockRangeKeyCondition); final QuerySpec querySpec = QuerySpecBuilder.build(compoundAttributeQuery, StubWithGlobalSecondaryIndexItem.class); assertEquals(attributeName, querySpec.getHashKey().getName()); assertEquals(expectedValue, querySpec.getHashKey().getValue()); assertEquals(mockRangeKeyCondition, querySpec.getRangeKeyCondition()); }
@Test public void shouldBuild_withCompoundAttributeQueryAndMultipleSupportingValues() { final Condition supportingCondition = randomCondition(randomIntInRange(2, 10)); final CompoundAttributeQuery compoundAttributeQuery = mock(CompoundAttributeQuery.class); when(compoundAttributeQuery.getSupportingCondition()).thenReturn(supportingCondition); InvalidConditionValuesException expectedException = null; try { QuerySpecBuilder.build(compoundAttributeQuery, StubWithGlobalSecondaryIndexItem.class); } catch (final InvalidConditionValuesException e) { expectedException = e; } assertNotNull(expectedException); }