@Test
  public void testCrafting() throws Exception {
    BlobId[] inputs;
    if (version >= BLOB_ID_V3) {
      inputs = new BlobId[]{
          new BlobId(version, BlobIdType.NATIVE, referenceDatacenterId, referenceAccountId, referenceContainerId,
              referencePartitionId, false, referenceDataType),
          new BlobId(version, BlobIdType.CRAFTED, referenceDatacenterId, referenceAccountId, referenceContainerId,
              referencePartitionId, false, referenceDataType)};
      assertFalse("isCrafted() should be false for native id", BlobId.isCrafted(inputs[0].getID()));
      assertTrue("isCrafted() should be true for crafted id", BlobId.isCrafted(inputs[1].getID()));
    } else {
      inputs = new BlobId[]{
          new BlobId(version, referenceType, referenceDatacenterId, referenceAccountId, referenceContainerId,
              referencePartitionId, false, null)};
      assertFalse("isCrafted() should be false for ids below BLOB_ID_V3", BlobId.isCrafted(inputs[0].getID()));
    }
    short newAccountId = (short) (referenceAccountId + 1 + TestUtils.RANDOM.nextInt(100));
    short newContainerId = (short) (referenceContainerId + 1 + TestUtils.RANDOM.nextInt(100));

    BlobId crafted = null;
    for (BlobId id : inputs) {
      try {
        BlobId.craft(id, BLOB_ID_V1, newAccountId, newContainerId);
        fail("Crafting should fail for target version " + BLOB_ID_V1);
      } catch (IllegalArgumentException e) {
      }
      try {
        BlobId.craft(id, BLOB_ID_V2, newAccountId, newContainerId);
        fail("Crafting should fail for target version " + BLOB_ID_V2);
      } catch (IllegalArgumentException e) {
      }
      short idVersion = (short) Math.max(id.getVersion(), BLOB_ID_V3);
      crafted = BlobId.craft(id, idVersion, newAccountId, newContainerId);
      verifyCrafting(id, crafted);
    }

    BlobId craftedAgain = BlobId.craft(crafted, crafted.getVersion(), crafted.getAccountId(), crafted.getContainerId());
    verifyCrafting(crafted, craftedAgain);
    assertEquals("Accounts should match", crafted.getAccountId(), craftedAgain.getAccountId());
    assertEquals("Containers should match", crafted.getContainerId(), craftedAgain.getContainerId());
    assertEquals("The id string should match", crafted.getID(), craftedAgain.getID());

    if (version == BLOB_ID_V3) {
      // version check to avoid testing this repetitively.
      try {
        BlobId.isCrafted("");
        fail("Empty blob id should not get parsed");
      } catch (IOException e) {
      }
      try {
        BlobId.isCrafted("ZZZZZ");
        fail("Invalid version should get caught");
      } catch (IllegalArgumentException e) {
      }
    }
  }
Test crafting of BlobIds.
Ensure that, except for the version, type, account and container, crafted id has the same constituents as the
input id.
Ensure that crafted id is the same as the input id if the input is a crafted V3 id with the same account and
container as the account and container in the call to craft.
ambry-commons/src/test/java/com/github/ambry/commons/BlobIdTest.java