### Question:
StatsManager { public static OperationStats getComponent(String component) { return getInstance() .stats .computeIfAbsent(component, key -> new OperationStats(getInstance())); } private  StatsManager(); static StatsManager getInstance(); static List<String> getComponentNames(); static OperationStats getComponent(String component); synchronized void stop(); synchronized void resume(); synchronized boolean isRunning(); synchronized Object takeSnapshot(); @SuppressWarnings("unused") synchronized void mergeWithSnapshot(Object snapshot); @SuppressWarnings("unused") synchronized void startFromSnapshot(Object snapshot); String printStats();  }### Answer:
@Test public void testGetComponent() { StatsManager.OperationStats component1 = StatsManager.getComponent("testComponent1"); StatsManager.OperationStats component2 = StatsManager.getComponent("testComponent2"); StatsManager.OperationStats component2again = StatsManager.getComponent("testComponent2"); assertNotNull(component1); assertNotNull(component2); assertNotNull(component2again); assertNotEquals(component1, component2); assertEquals(component2, component2again); }
@Test public void testEvent() { StatsManager.OperationStats component = StatsManager.getComponent("testComponent1"); Event event = component.event(TestEnum.VALUE1); assertNotNull(event); }
@Test public void testEvent2() { StatsManager.OperationStats component = StatsManager.getComponent("testComponent2"); Event event = component.event("event"); assertNotNull(event); }
@Test public void testRegister() { StatsManager.OperationStats component = StatsManager.getComponent("testComponent3"); int before = component.getRegisteredCount("operation"); component.register("operation"); int after = component.getRegisteredCount("operation"); assertEquals(1, after - before); }
@Test public void testSuccessCount() { StatsManager.OperationStats component = StatsManager.getComponent("testComponent5"); int before = component.getSuccessCount("operation"); component.event("operation").start().success(); int after = component.getSuccessCount("operation"); assertEquals(1, after - before); }
@Test public void testFailureCount() { StatsManager.OperationStats component = StatsManager.getComponent("testComponent5"); int before = component.getFailureCount("operation"); component.event("operation").start().failure(); int after = component.getFailureCount("operation"); assertEquals(1, after - before); }
@Test public void testLogResult() { StatsManager.OperationStats component = StatsManager.getComponent("testComponent4"); int beforeOne = component.getLogResultCounter("operation", "one"); int beforeTwo = component.getLogResultCounter("operation", "two"); component.logResult("operation", "one"); component.logResult("operation", "two"); component.logResult("operation", "two"); int afterOne = component.getLogResultCounter("operation", "one"); int afterTwo = component.getLogResultCounter("operation", "two"); assertEquals(1, afterOne - beforeOne); assertEquals(2, afterTwo - beforeTwo); }
@Test public void event_canFailEventWithoutStarting() { OperationStats stats = StatsManager.getComponent("StatsManagerTest"); Event event = stats.event("operation"); event.failure(); assertEquals(1, stats.getFailureCount("operation")); }
@Test public void event_canPassEventWithoutStarting() { OperationStats stats = StatsManager.getComponent("StatsManagerTest"); Event event = stats.event("operation"); event.success(); assertEquals(1, stats.getSuccessCount("operation")); }