### Question:
BaseCommand { public List<T> configuredEntities(Class<T> toValueType, String entitiesKey, String entitiesFileKey) { LOG.info("Config contains, {}: {}, {}: {}", entitiesKey, cmdConfig.containsKey(entitiesKey), entitiesFileKey, cmdConfig.containsKey(entitiesFileKey)); Object entities = cmdConfig.containsKey(entitiesKey) ? cmdConfig.get(entitiesKey) : cmdConfig.get(entitiesFileKey); Objects.requireNonNull(entities, "Missing entities in config"); List<Map<String, Object>> unParsed = configuredEntities(cmdConfig, entitiesKey, entitiesFileKey); final List<Map<String, Object>> forCluster; if (cluster == null) { forCluster = unParsed; LOG.info("Cluster is not set"); } else { forCluster = ClusterEntities.forCluster(unParsed, cluster); LOG.info("Out of total {}, found {} matching entities for cluster {}", unParsed.size(), forCluster.size(), cluster); } return forCluster.stream() .map(t -> MAPPER.convertValue(t, toValueType)) .collect(Collectors.toList()); } BaseCommand();  BaseCommand(Map<String, Object> cmdConfig);  BaseCommand(Map<String, Object> cmdConfig, String cluster); Map<String, Object> kafkaConfig(); List<T> configuredEntities(Class<T> toValueType, String entitiesKey, String entitiesFileKey); int run(); static int SUCCESS; static int FAILURE; }### Answer:
@Test public void testClusterEntitiesFromFile() throws IOException { String dummies = String.join( "\n", new String[]{ "---", "- name: dummy_a", " config: {}", " clusters:", " cluster_a: {}", }); Assert.assertEquals( 1, new BaseCommand<Dummy>(configWithEntitiesFile(dummies), "cluster_a") .configuredEntities(Dummy.class, "dummies", "dummiesFile") .size()); Assert.assertEquals( 0, new BaseCommand<Dummy>(configWithEntitiesFile(dummies), "cluster_b") .configuredEntities(Dummy.class, "dummies", "dummiesFile") .size()); }
@Test public void testConfiguredT() throws IOException { Map<String, Object> config = converter.convert(confStream(testConf)); List<Dummy> configured = new BaseCommand<Dummy>(config).configuredEntities(Dummy.class, "dummies", "dummiesFile"); Assert.assertEquals(2, configured.size()); }
@Test(expected = IllegalArgumentException.class) public void testConfiguredBad() throws IOException { String badConf = "---\n" + "kafka:\n" + " bootstrap.servers: localhost:9092\n" + "dummies:\n" + " - name: dummy_a\n"; Map<String, Object> config = converter.convert(confStream(badConf)); new BaseCommand<Dummy>(config).configuredEntities(Dummy.class, "dummies", "dummiesFile"); }
@Test public void testFromFile() throws IOException { String dummies = String.join( "\n", new String[]{ "---", "- name: dummy_a", " config: {}" }); Assert.assertEquals( 1, new BaseCommand<Dummy>(configWithEntitiesFile(dummies)) .configuredEntities(Dummy.class, "dummies", "dummiesFile") .size()); }