### Question:
MetricsModes { public static MetricsMode fromString(String mode) { if ("none".equalsIgnoreCase(mode)) { return None.get(); } else if ("counts".equalsIgnoreCase(mode)) { return Counts.get(); } else if ("full".equalsIgnoreCase(mode)) { return Full.get(); } Matcher truncateMatcher = TRUNCATE.matcher(mode.toLowerCase(Locale.ENGLISH)); if (truncateMatcher.matches()) { int length = Integer.parseInt(truncateMatcher.group(1)); return Truncate.withLength(length); } throw new IllegalArgumentException("Invalid metrics mode: " + mode); } private  MetricsModes(); static MetricsMode fromString(String mode);  }### Answer:
@Test public void testMetricsModeParsing() { Assert.assertEquals(None.get(), MetricsModes.fromString("none")); Assert.assertEquals(None.get(), MetricsModes.fromString("nOnE")); Assert.assertEquals(Counts.get(), MetricsModes.fromString("counts")); Assert.assertEquals(Counts.get(), MetricsModes.fromString("coUntS")); Assert.assertEquals(Truncate.withLength(1), MetricsModes.fromString("truncate(1)")); Assert.assertEquals(Truncate.withLength(10), MetricsModes.fromString("truNcAte(10)")); Assert.assertEquals(Full.get(), MetricsModes.fromString("full")); Assert.assertEquals(Full.get(), MetricsModes.fromString("FULL")); }
@Test public void testInvalidTruncationLength() { exceptionRule.expect(IllegalArgumentException.class); exceptionRule.expectMessage("length should be positive"); MetricsModes.fromString("truncate(0)"); }