### Question:
ThreadPoolMonitor { public static void attach( final Registry registry, final ThreadPoolExecutor threadPool, final String threadPoolName) { Preconditions.checkNotNull(registry, "registry"); Preconditions.checkNotNull(threadPool, "threadPool"); final String idValue; if (threadPoolName == null || threadPoolName.isEmpty()) { idValue = DEFAULT_ID; } else { idValue = threadPoolName; } final Tag idTag = new BasicTag(ID_TAG_NAME, idValue); PolledMeter.using(registry) .withName(TASK_COUNT) .withTag(idTag) .monitorMonotonicCounter(threadPool, ThreadPoolExecutor::getTaskCount); PolledMeter.using(registry) .withName(COMPLETED_TASK_COUNT) .withTag(idTag) .monitorMonotonicCounter(threadPool, ThreadPoolExecutor::getCompletedTaskCount); PolledMeter.using(registry) .withName(CURRENT_THREADS_BUSY) .withTag(idTag) .monitorValue(threadPool, ThreadPoolExecutor::getActiveCount); PolledMeter.using(registry) .withName(MAX_THREADS) .withTag(idTag) .monitorValue(threadPool, ThreadPoolExecutor::getMaximumPoolSize); PolledMeter.using(registry) .withName(POOL_SIZE) .withTag(idTag) .monitorValue(threadPool, ThreadPoolExecutor::getPoolSize); PolledMeter.using(registry) .withName(CORE_POOL_SIZE) .withTag(idTag) .monitorValue(threadPool, ThreadPoolExecutor::getCorePoolSize); PolledMeter.using(registry) .withName(QUEUE_SIZE) .withTag(idTag) .monitorValue(threadPool, tp -> tp.getQueue().size()); Counter rejected = registry.counter(registry.createId(REJECTED_TASK_COUNT).withTag(idTag)); RejectedExecutionHandler handler = threadPool.getRejectedExecutionHandler(); RejectedExecutionHandler monitoredHandler = (Runnable r, ThreadPoolExecutor exec) -> { rejected.increment(); handler.rejectedExecution(r, exec); }; threadPool.setRejectedExecutionHandler(monitoredHandler); } private  ThreadPoolMonitor(); static void attach(
      final Registry registry,
      final ThreadPoolExecutor threadPool,
      final String threadPoolName);  }### Answer:
@Test public void monitorThrowsIfNullRegistry() throws Exception { Assertions.assertThrows(NullPointerException.class, () -> ThreadPoolMonitor.attach(null, latchedExecutor, THREAD_POOL_NAME)); }
@Test public void monitorThrowsIfNullThreadPool() throws Exception { Assertions.assertThrows(NullPointerException.class, () -> ThreadPoolMonitor.attach(registry, null, THREAD_POOL_NAME)); }
@Test public void monitorAcceptsNullThreadPoolName() { ThreadPoolMonitor.attach(registry, latchedExecutor, null); }
@Test public void threadPoolMonitorHasRejectedExecutionsCounter() { ThreadPoolMonitor.attach(registry, latchedExecutor, THREAD_POOL_NAME); latchedExecutor.shutdown(); int rejected = 0; try { latchedExecutor.submit(() -> {}); } catch (RejectedExecutionException e) { e.printStackTrace(); ++rejected; } Counter c = registry.counter(ThreadPoolMonitor.REJECTED_TASK_COUNT, "id", THREAD_POOL_NAME); Assertions.assertNotNull(c); Assertions.assertEquals(rejected, c.count()); }