### Question:
CustomGroupsManager { public List<CustomGroup> getCustomGroups() { return customGroups; } @Inject  CustomGroupsManager(final DashboardConfig config); List<CustomGroup> getCustomGroups();  }### Answer:
@Test(groups = "fast") public void testDefaultConfiguration() throws Exception { final DashboardConfig config = new ConfigurationObjectFactory(System.getProperties()).build(DashboardConfig.class); final CustomGroupsManager manager = new CustomGroupsManager(config); final List<CustomGroup> configuration = manager.getCustomGroups(); Assert.assertEquals(configuration.size(), 0); }
@Test(groups = "fast") public void testCustomGroupsConfiguration() throws Exception { final String configPath = System.getProperty("java.io.tmpdir") + "/TestCustomGroupsManager-" + System.currentTimeMillis(); final String groupsConfigurationString = "" + "[\n" + " {\n" + " \"name\":\"JVM\",\n" + " \"kinds\":[\n" + " {\n" + " \"eventCategory\":\"JVMMemory\",\n" + " \"sampleKinds\":[\"heapUsed\",\"nonHeapUsed\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"CMSOldGen\",\n" + " \"sampleKinds\":[\"memoryPoolUsed\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"CMSPermGen\",\n" + " \"sampleKinds\":[\"memoryPoolUsed\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"CodeCache\",\n" + " \"sampleKinds\":[\"memoryPoolUsed\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"ParEdenSpace\",\n" + " \"sampleKinds\":[\"memoryPoolUsed\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"ParSurvivorSpace\",\n" + " \"sampleKinds\":[\"memoryPoolUsed\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"ConcurrentMarkSweepGC\",\n" + " \"sampleKinds\":[\"garbageCollectionRate\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"ParNewGC\",\n" + " \"sampleKinds\":[\"garbageCollectionRate\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"Threading\",\n" + " \"sampleKinds\":[\"threadCount\"]\n" + " },\n" + " {\n" + " \"eventCategory\":\"JVMOperatingSystemPerZone\",\n" + " \"sampleKinds\":[\"ProcessCpuTime\"]\n" + " }\n" + " ]\n" + " }\n" + "]"; Files.write(groupsConfigurationString, new File(configPath), Charsets.UTF_8); final DashboardConfig config = Mockito.mock(DashboardConfig.class); Mockito.when(config.getCustomGroupsFile()).thenReturn(configPath); final CustomGroupsManager manager = new CustomGroupsManager(config); final List<CustomGroup> configuration = manager.getCustomGroups(); Assert.assertEquals(configuration.size(), 1); final CustomGroup group = configuration.get(0); Assert.assertEquals(group.getName(), "JVM"); Assert.assertEquals(group.getKinds().size(), 10); Assert.assertEquals(group.getKinds().get(0).getEventCategory(), "JVMMemory"); Assert.assertEquals(group.getKinds().get(0).getSampleKinds().size(), 2); }