### Question:
PathConversion { public StorageKey toKey(Path fromPath, StorageKey storage) { final List<FieldPartitioner> partitioners = Accessor.getDefault().getFieldPartitioners(storage.getPartitionStrategy()); final List<Object> values = Lists.newArrayList( new Object[partitioners.size()]); Path currentPath = fromPath; int index = partitioners.size() - 1; while (currentPath != null && index >= 0) { values.set(index, valueForDirname( (FieldPartitioner<?, ?>) partitioners.get(index), currentPath.getName())); currentPath = currentPath.getParent(); index -= 1; } storage.replaceValues(values); return storage; } 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 testToKey() { PartitionStrategy strategy = new PartitionStrategy.Builder() .year("timestamp") .month("timestamp") .day("timestamp") .build(); StorageKey expected = new StorageKey(strategy); expected.replaceValues((List) Lists.newArrayList(2013, 11, 5)); Assert.assertEquals(expected, convert.toKey( new Path("year=2013/month=11/day=5"), new StorageKey(strategy))); }
@Test @SuppressWarnings("unchecked") public void toDirNameIdentityWithNonString() { PartitionStrategy strategy = new PartitionStrategy.Builder() .identity("id") .build(); StorageKey expected = new StorageKey(strategy); expected.replace(0, 0L); Assert.assertEquals("Should convert to schema type", expected, convert.toKey(new Path("id=0"), new StorageKey(strategy))); }