MetricName { public static MetricName parse(String metric) { Matcher m = METRIC_PATTERN.matcher(metric); if (!m.matches()) { throw new IllegalArgumentException(String.format("invalid metric name '%s'", metric)); } return new MetricName(m.group(METRIC_PREFIX_INDEX), m.group(METRIC_SUFFIX_INDEX), m .group(METRIC_INSTANCE_INDEX)); } private  MetricName(String prefix, String suffix, String instance); String getMetric(); String getInstanceDomainTag(); static MetricName parse(String metric); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test(expected = IllegalArgumentException.class) public void testCannotParseWithTrailingDot() { MetricName.parse("a.."); }
@Test(expected = IllegalArgumentException.class) public void testCannotParseWithDoubleDot() { MetricName.parse("a..b"); }
@Test(expected = IllegalArgumentException.class) public void testCannotParseWithLeadingDot() { MetricName.parse(".a"); }
@Test public void testCanParseWithSingleSegment() { assertMetricNameMatches(MetricName.parse("a"), "a", null, "a"); }
@Test public void testCanParseWithMultipleSegments() { assertMetricNameMatches(MetricName.parse("a.b"), "a.b", null, "a.b"); }
@Test public void testCanParseWithInstance() { assertMetricNameMatches(MetricName.parse("a[x].b"), "a.b", "x", "a"); }
@Test public void testCanParseWithInstanceAtEnd() { assertMetricNameMatches(MetricName.parse("a.b[x]"), "a.b", "x", "a.b"); }
@Test(expected = IllegalArgumentException.class) public void testCannotParseWithTwoInstances() { MetricName.parse("a[x].b[x]"); }
@Test(expected = IllegalArgumentException.class) public void testCannotParseWithHalfAnInstance() { MetricName.parse("a[x.b"); }
@Test public void testCanParseWithUnderscores() { assertMetricNameMatches(MetricName.parse("a._b_"), "a._b_", null, "a._b_"); }