public static DeviceId toDeviceId(ResourceId path) {
        checkArgument(isUnderDeviceRootNode(path), path);
        // FIXME if we decide to drop any of intermediate nodes
        //        "/" - "devices" - "device"
        int rootIdx = ResourceIds.startsWithRootNode(path) ? 0 : -1;
        return toDeviceId(path.nodeKeys().get(rootIdx + DEVICE_INDEX));
    }
@Test
    public void testToDeviceId() throws CloneNotSupportedException {
        ResourceId ridAchild = ridA.copyBuilder()
                    .addBranchPointSchema("some", "ns")
                    .addBranchPointSchema("random", "ns")
                    .addBranchPointSchema("child", "ns")
                    .build();

        assertEquals(DID_A, DeviceResourceIds.toDeviceId(ridAchild));

        NodeKey<?> nodeKey = ridA.nodeKeys().get(2);
        assertThat(nodeKey, is(instanceOf(ListKey.class)));
        assertThat(nodeKey.schemaId(), is(equalTo(new SchemaId(DEVICE_NAME, DCS_NAMESPACE))));
        ListKey listKey = (ListKey) nodeKey;
        assertThat(listKey.keyLeafs(), is(contains(new KeyLeaf(DEVICE_ID_KL_NAME, DCS_NAMESPACE, DID_A.toString()))));
    }