### Question:
PathConversion { public Path fromKey(StorageKey key) { final StringBuilder pathBuilder = new StringBuilder(); final List<FieldPartitioner> partitioners = Accessor.getDefault().getFieldPartitioners(key.getPartitionStrategy()); for (int i = 0; i < partitioners.size(); i++) { final FieldPartitioner fp = partitioners.get(i); if (i != 0) { pathBuilder.append(Path.SEPARATOR_CHAR); } @SuppressWarnings("unchecked") String dirname = dirnameForValue(fp, key.get(i)); pathBuilder.append(dirname); } return new Path(pathBuilder.toString()); } PathConversion(Schema schema); StorageKey toKey(Path fromPath, StorageKey storage); Path fromKey(StorageKey key); T valueForDirname(FieldPartitioner<?, T> field, String name); static String dirnameForValue(FieldPartitioner<?, T> field, T value); static String valueToString(FieldPartitioner<?, T> field, T value); static T valueForDirname(FieldPartitioner<?, T> field, Schema schema, String name); static String dirnameToValueString(String name);  }### Answer:
@Test @SuppressWarnings("unchecked") public void testFromKey() { PartitionStrategy strategy = new PartitionStrategy.Builder() .year("timestamp") .month("timestamp") .day("timestamp") .build(); StorageKey key = new StorageKey(strategy); key.replaceValues((List) Lists.newArrayList(2013, 11, 5)); Assert.assertEquals( new Path("year=2013/month=11/day=05"), convert.fromKey(key)); }
@Test @SuppressWarnings("unchecked") public void toDirNameIdentityWithSlashes() { PartitionStrategy strategy = new PartitionStrategy.Builder() .identity("name") .identity("address") .build(); StorageKey key = new StorageKey(strategy); key.replaceValues((List) Lists.newArrayList("John Doe", "NY/USA")); Assert.assertEquals( new Path("name_copy=John+Doe/address_copy=NY%2FUSA"), convert.fromKey(key)); }