public static Sensor getInvocationSensor(
      final Metrics metrics,
      final String sensorName,
      final String groupName,
      final String functionDescription
  ) {
    final Sensor sensor = metrics.sensor(sensorName);
    if (sensor.hasMetrics()) {
      return sensor;
    }

    final BiFunction<String, String, MetricName> metricNamer = (suffix, descPattern) -> {
      final String description = String.format(descPattern, functionDescription);
      return metrics.metricName(sensorName + "-" + suffix, groupName, description);
    };

    sensor.add(
        metricNamer.apply("avg", AVG_DESC),
        new Avg()
    );

    sensor.add(
        metricNamer.apply("max", MAX_DESC),
        new Max()
    );

    sensor.add(
        metricNamer.apply("count", COUNT_DESC),
        new WindowedCount()
    );

    sensor.add(
        metricNamer.apply("rate", RATE_DESC),
        new Rate(TimeUnit.SECONDS, new WindowedCount())
    );

    return sensor;
  }
@Test
  public void shouldGetSensorWithCorrectName() {
    // When:
    FunctionMetrics
        .getInvocationSensor(metrics, SENSOR_NAME, GROUP_NAME, FUNC_NAME);

    // Then:
    verify(metrics).sensor(SENSOR_NAME);
  }