@Test
  public void testReplicaFromOfflineToBootstrap() {
    MockStatsManager mockStatsManager =
        new MockStatsManager(storageManager, mockClusterMap, replicas, new MetricRegistry(), statsManagerConfig,
            clusterParticipant, dataNodeId);
    // 1. verify stats manager's listener is registered
    assertTrue("Stats manager listener is found in cluster participant",
        clusterParticipant.getPartitionStateChangeListeners().containsKey(StateModelListenerType.StatsManagerListener));
    // 2. test partition not found
    try {
      clusterParticipant.onPartitionBecomeBootstrapFromOffline("InvalidPartition");
      fail("should fail because partition is not found");
    } catch (StateTransitionException e) {
      assertEquals("Transition error doesn't match", ReplicaNotFound, e.getErrorCode());
    }
    // 3. create a new partition and test replica addition failure
    PartitionId newPartition = new MockPartitionId(3, MockClusterMap.DEFAULT_PARTITION_CLASS,
        Collections.singletonList((MockDataNodeId) dataNodeId), 0);
    ((MockStorageManager) storageManager).getReplicaReturnVal = newPartition.getReplicaIds().get(0);
    mockStatsManager.returnValOfAddReplica = false;
    try {
      clusterParticipant.onPartitionBecomeBootstrapFromOffline(newPartition.toPathString());
      fail("should fail because adding replica to stats manager failed");
    } catch (StateTransitionException e) {
      assertEquals("Transition error code doesn't match", ReplicaOperationFailure, e.getErrorCode());
    }
    // 4. test replica addition success during Offline-To-Bootstrap transition
    assertFalse("Before adding new replica, in-mem data structure should not contain new partition",
        mockStatsManager.partitionToReplicaMap.containsKey(newPartition));
    mockStatsManager.returnValOfAddReplica = null;
    clusterParticipant.onPartitionBecomeBootstrapFromOffline(newPartition.toPathString());
    assertTrue("After adding new replica, in-mem data structure should contain new partition",
        mockStatsManager.partitionToReplicaMap.containsKey(newPartition));
    // 5. state transition on existing replica should be no-op
    clusterParticipant.onPartitionBecomeBootstrapFromOffline(replicas.get(0).getPartitionId().toPathString());
  }
Test state transition in stats manager from OFFLINE to BOOTSTRAP
ambry-server/src/test/java/com/github/ambry/server/StatsManagerTest.java