### Question:
CreatePartitionStrategyCommand extends BaseCommand { @Override public int run() throws IOException { PartitionStrategy.Builder strategyBuilder = new PartitionStrategy.Builder(); for (String partition : partitions) { Matcher m = PARTITION_FIELD.matcher(partition); if (m.matches()) { String fieldName = m.group(1); ValidationException.check(fieldName != null && !fieldName.isEmpty(), "Invalid field name: %s", String.valueOf(fieldName)); String partitionerType = m.group(2); if ("hash".equals(partitionerType)) { String width = m.group(3); ValidationException.check(width != null, "Missing number of hash partitions: %s:hash[?]", fieldName); strategyBuilder.hash(fieldName, Integer.parseInt(width)); } else if ("copy".equals(partitionerType)) { strategyBuilder.identity(fieldName); } else if ("year".equals(partitionerType)) { strategyBuilder.year(fieldName); } else if ("month".equals(partitionerType)) { strategyBuilder.month(fieldName); } else if ("day".equals(partitionerType)) { strategyBuilder.day(fieldName); } else if ("hour".equals(partitionerType)) { strategyBuilder.hour(fieldName); } else if ("minute".equals(partitionerType)) { strategyBuilder.minute(fieldName); } else if ("provided".equals(partitionerType)) { strategyBuilder.provided(fieldName); } else { throw new ValidationException( "Unknown partitioner type: " + partitionerType); } } else { throw new ValidationException( "Invalid partition <field:type>: " + partition); } } DatasetDescriptor descriptor = new DatasetDescriptor.Builder() .partitionStrategy(strategyBuilder.build()) .schema(open(avroSchemaFile)) .build(); String strategy = descriptor.getPartitionStrategy().toString(!minimize); output(strategy, console, outputPath); return 0; } CreatePartitionStrategyCommand(Logger console); @Override int run(); @Override List<String> getExamples();  }### Answer:
@Test public void testBasic() throws Exception { command.partitions = Lists.newArrayList( "username:hash[16]", "username:copy"); command.run(); PartitionStrategy strategy = new PartitionStrategy.Builder() .hash("username", 16) .identity("username") .build(); verify(console).info(strategy.toString(true)); verifyNoMoreInteractions(console); }
@Test public void testNested() throws Exception { command.partitions = Lists.newArrayList("address.line1:copy"); command.run(); PartitionStrategy strategy = new PartitionStrategy.Builder() .identity("address.line1") .build(); verify(console).info(strategy.toString(true)); verifyNoMoreInteractions(console); }
@Test public void testTime() throws Exception { command.partitions = Lists.newArrayList( "created_at:year", "created_at:month", "created_at:day", "created_at:hour", "created_at:minute" ); command.run(); PartitionStrategy strategy = new PartitionStrategy.Builder() .year("created_at") .month("created_at") .day("created_at") .hour("created_at") .minute("created_at") .build(); verify(console).info(strategy.toString(true)); verifyNoMoreInteractions(console); }
@Test public void testMissingWidth() throws Exception { command.partitions = Lists.newArrayList("username:hash"); TestHelpers.assertThrows("Should reject missing hash width", ValidationException.class, new Callable() { @Override public Object call() throws Exception { command.run(); return null; } }); }
@Test public void testUnknownSourceField() { command.partitions = Lists.newArrayList("id:copy"); TestHelpers.assertThrows("Should reject missing field \"id\"", ValidationException.class, new Callable() { @Override public Object call() throws Exception { command.run(); return null; } }); }
@Test public void testUnknownType() { command.partitions = Lists.newArrayList("username:id"); TestHelpers.assertThrows("Should unknown partition function \"id\"", ValidationException.class, new Callable() { @Override public Object call() throws Exception { command.run(); return null; } }); }