### Question:
HiveMetricsHelper { public static Optional<Long> incrementCounter(String name) { try { Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { return Optional.of(metrics.incrementCounter(name)); } } catch (Exception e) { log.warn("Unable to increment counter {}", name, e); } return Optional.empty(); }  static Optional<Long> incrementCounter(String name);  }### Answer:
@Test public void incrementCounter() throws Exception { conf.setVar(HiveConf.ConfVars.HIVE_METRICS_CLASS, "org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics"); MetricsFactory.init(conf); assertThat(HiveMetricsHelper.incrementCounter("name")).get().isEqualTo(1L); }
@Test public void nullMetricsClass() { assertThat(HiveMetricsHelper.incrementCounter("name")).isNotPresent(); }
@Test public void metricsThrowsException() throws Exception { conf.setVar(HiveConf.ConfVars.HIVE_METRICS_CLASS, "com.expediagroup.apiary.extensions.events.metastore.kafka.metrics." + "ExceptionMetrics"); MetricsFactory.init(conf); assertThat(HiveMetricsHelper.incrementCounter("name")).isNotPresent(); }