### Question:
ManagementService implements CacheManagerEventListener { private void registerCacheManager(CacheManager cacheManager) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { if (registerCacheManager) { mBeanServer.registerMBean(cacheManager, cacheManager.getObjectName()); } } ManagementService(net.sf.ehcache.CacheManager cacheManager,
                             MBeanServer mBeanServer,
                             boolean registerCacheManager,
                             boolean registerCaches,
                             boolean registerCacheConfigurations,
                             boolean registerCacheStatistics,
                             boolean registerCacheStores);  ManagementService(net.sf.ehcache.CacheManager cacheManager,
                                 MBeanServer mBeanServer,
                                 boolean registerCacheManager,
                                 boolean registerCaches,
                                 boolean registerCacheConfigurations,
                                 boolean registerCacheStatistics); static void registerMBeans(
            net.sf.ehcache.CacheManager cacheManager,
            MBeanServer mBeanServer,
            boolean registerCacheManager,
            boolean registerCaches,
            boolean registerCacheConfigurations,
            boolean registerCacheStatistics,
            boolean registerCacheStores); static void registerMBeans(
            net.sf.ehcache.CacheManager cacheManager,
            MBeanServer mBeanServer,
            boolean registerCacheManager,
            boolean registerCaches,
            boolean registerCacheConfigurations,
            boolean registerCacheStatistics); void init(); Status getStatus(); void dispose(); void notifyCacheAdded(String cacheName); void notifyCacheRemoved(String cacheName);  }### Answer:
@Test public void testRegisterCacheManager() throws Exception { Ehcache ehcache = new net.sf.ehcache.Cache("testNoOverflowToDisk", 1, false, false, 500, 200); manager.addCache(ehcache); ehcache.put(new Element("key1", "value1")); ehcache.put(new Element("key2", "value1")); assertNull(ehcache.get("key1")); assertNotNull(ehcache.get("key2")); ObjectName name = new ObjectName("net.sf.ehcache:type=CacheManager,name=1"); CacheManager cacheManager = new CacheManager(manager); mBeanServer.registerMBean(cacheManager, name); mBeanServer.unregisterMBean(name); name = new ObjectName("net.sf.ehcache:type=CacheManager.Cache,CacheManager=1,name=testOverflowToDisk"); mBeanServer.registerMBean(new Cache(ehcache), name); mBeanServer.unregisterMBean(name); name = new ObjectName("net.sf.ehcache:type=CacheManager.Cache,CacheManager=1,name=sampleCache1"); mBeanServer.registerMBean(new Cache(manager.getCache("sampleCache1")), name); mBeanServer.unregisterMBean(name); }
@Test public void testRegisterCacheManager() throws Exception { Ehcache ehcache = new net.sf.ehcache.Cache("testNoOverflowToDisk", 1, false, false, 500, 200); manager.addCache(ehcache); ehcache.put(new Element("key1", "value1")); ehcache.put(new Element("key2", "value1")); assertThat(ehcache.get("key1"), nullValue()); assertThat(ehcache.get("key2"), notNullValue()); ObjectName name = new ObjectName("net.sf.ehcache:type=CacheManager,name=1"); CacheManager cacheManager = new CacheManager(manager); mBeanServer.registerMBean(cacheManager, name); mBeanServer.unregisterMBean(name); name = new ObjectName("net.sf.ehcache:type=CacheManager.Cache,CacheManager=1,name=testOverflowToDisk"); mBeanServer.registerMBean(new Cache(ehcache), name); mBeanServer.unregisterMBean(name); name = new ObjectName("net.sf.ehcache:type=CacheManager.Cache,CacheManager=1,name=sampleCache1"); mBeanServer.registerMBean(new Cache(manager.getCache("sampleCache1")), name); mBeanServer.unregisterMBean(name); }