### Question:
ParameterizedMetricClassManager extends SimpleMetricClassManager implements MetricClassManager { @Override public Metric instantiateMetric(String metricName) throws IllegalArgumentException, InstantiationException { final Metric metric; if (!metricConfiguration.containsKey(metricName)) { metric = super.instantiateMetric(metricName); } else { final String className = metricClasses.get(metricName); final Class<? extends Metric> klazz = findMetricClass(className); metric = instantiateClassWithConfiguration(klazz, metricConfiguration.get(metricName)); } return metric; } @SuppressWarnings("rawtypes")  ParameterizedMetricClassManager(Collection<String> metricNames, Map<String, Map> metricConfiguration); @Override Metric instantiateMetric(String metricName); static final String NAME_KEY; static final String MAXIMUM_GRADE_KEY; static final String MISSING_GRADE_KEY; }### Answer:
@Test public void canInstantiateSimpleMetric() throws Exception { Metric m = manager.instantiateMetric("io.sease.rre.core.domain.metrics.impl.PrecisionAtOne"); assertNotNull(m); assertTrue(m instanceof io.sease.rre.core.domain.metrics.impl.PrecisionAtOne); }
@Test(expected = IllegalArgumentException.class) public void throwsExceptionForUndefinedMetric() throws Exception { manager.instantiateMetric("blah.blah.NoMetric"); }
@Test(expected = IllegalArgumentException.class) public void throwsExceptionForNonExistentMetric() throws Exception { manager.instantiateMetric("non.existent.DummyMetric"); }
@Test(expected = InstantiationException.class) public void throwsExceptionForMetricRequiringConfig_whenNoConfigSupplied() throws Exception { manager.instantiateMetric("io.sease.rre.core.domain.metrics.impl.PrecisionAtK"); }
@Test(expected = InstantiationException.class) public void throwsExceptionForParameterizedMetric_whenConfigIsWrong() throws Exception { final Map precisionAtFiveConfig = new HashMap(); precisionAtFiveConfig.put("class", "io.sease.rre.core.domain.metrics.impl.PrecisionAtK"); precisionAtFiveConfig.put("v", 5); final Map<String, Map> metricConfiguration = new HashMap<>(); metricConfiguration.put("pAt5", precisionAtFiveConfig); final MetricClassManager manager = new ParameterizedMetricClassManager(Arrays.asList(METRICS), metricConfiguration); manager.instantiateMetric("pAt5"); }
@Test public void canInstantiateParameterizedMetric() throws Exception { final Map precisionAtFiveConfig = new HashMap(); precisionAtFiveConfig.put("class", "io.sease.rre.core.domain.metrics.impl.PrecisionAtK"); precisionAtFiveConfig.put("k", 5); final Map<String, Map> metricConfiguration = new HashMap<>(); metricConfiguration.put("pAt5", precisionAtFiveConfig); final MetricClassManager manager = new ParameterizedMetricClassManager(Arrays.asList(METRICS), metricConfiguration); Metric m = manager.instantiateMetric("pAt5"); assertNotNull(m); assertTrue(m instanceof io.sease.rre.core.domain.metrics.impl.PrecisionAtK); assertEquals("P@5", m.getName()); }