### Question:
FieldValidator { public void validatePrimaryKeys(Collection<Field<?>> keys, boolean allowPrefix) throws InvalidFieldException { List<String> primaryKeys = tableSchema.getPrimaryKeys(); if (keys.size() > primaryKeys.size()) { throw new InvalidFieldException( tableSchema.getTableId(), keys, String.format("Given keys %s contain more fields than the primary keys %s", keys, primaryKeys)); } if (!allowPrefix && keys.size() < primaryKeys.size()) { throw new InvalidFieldException( tableSchema.getTableId(), keys, String.format("Given keys %s do not contain all the primary keys %s", keys, primaryKeys)); } int i = 0; for (Field<?> key : keys) { validateField(key); if (!key.getName().equals(primaryKeys.get(i))) { throw new InvalidFieldException( tableSchema.getTableId(), keys, String.format("Given keys %s are not the prefix of the primary keys %s", keys, primaryKeys)); } i++; } } FieldValidator(StructuredTableSchema tableSchema); void validateField(Field<?> field); void validatePrimaryKeys(Collection<Field<?>> keys, boolean allowPrefix);  }### Answer:
@Test public void testValidatePrimaryKeys() { FieldValidator validator = new FieldValidator(schema); validator.validatePrimaryKeys(Arrays.asList(Fields.intField(KEY, 10), Fields.longField(KEY2, 100L), Fields.stringField(KEY3, "s")), false); validator.validatePrimaryKeys(Arrays.asList(Fields.intField(KEY, 10), Fields.longField(KEY2, 100L)), true); validator.validatePrimaryKeys(Collections.singletonList(Fields.intField(KEY, 10)), true); try { validator.validatePrimaryKeys(Arrays.asList(Fields.floatField(KEY, 10.0f), Fields.longField(KEY2, 100L), Fields.stringField(KEY3, "s")), false); Assert.fail("Expected InvalidFieldException"); } catch (InvalidFieldException e) { } try { validator.validatePrimaryKeys(Arrays.asList(Fields.intField(KEY, 10), Fields.longField(KEY2, 100L)), false); Assert.fail("Expected InvalidFieldException"); } catch (InvalidFieldException e) { } }