MetricNameValidator { void validateNameConstraints(MetricName metricName) { validateName(metricName); validateInstance(metricName); } MetricNameValidator(int nameLimit, int domainLimit);   }
@Test(expected = IllegalArgumentException.class) public void shouldRaiseAnErrorIfTheMetricNameIsLongerThanTheAllowedLength() { MetricName metricName = mock(MetricName.class); when(metricName.getMetric()).thenReturn(METRIC_NAME_64_CHARS); validator.validateNameConstraints(metricName); }
@Test public void shouldNotRaiseAnErrorIfTheMetricNameIsUnderTheLimit() { MetricName metricName = mock(MetricName.class); when(metricName.getMetric()).thenReturn(METRIC_NAME_63_CHARS); validator.validateNameConstraints(metricName); }
@Test(expected = IllegalArgumentException.class) public void shouldRaiseAnErrorIfTheMetricHasAnInstanceAndItsNameIsLongerThanTheAllowedLength() { MetricName metricName = mock(MetricName.class); when(metricName.getMetric()).thenReturn(""); when(metricName.hasInstance()).thenReturn(true); when(metricName.getInstance()).thenReturn(INSTANCE_NAME_64_CHARS); validator.validateNameConstraints(metricName); }
@Test public void shouldNotRaiseAnErrorIfTheMetricHasAnInstanceAndItsNameIsShorterThanTheAllowedLength() { MetricName metricName = mock(MetricName.class); when(metricName.getMetric()).thenReturn(""); when(metricName.hasInstance()).thenReturn(true); when(metricName.getInstance()).thenReturn(INSTANCE_NAME_63_CHARS); validator.validateNameConstraints(metricName); }