### Question:
ManagedBasicDataSource extends BasicDataSource { public String getMBeanName() { return mBeanName; } ManagedBasicDataSource();  ManagedBasicDataSource(String mBeanName);  ManagedBasicDataSource(MBeanServer mBeanServer, String mBeanName); String getMBeanName(); @Managed(description = "The current number of active connections that have been allocated from this data source.") synchronized int getNumActive(); @Managed(description = "The current number of idle connections that are waiting to be allocated from this data source.") synchronized int getNumIdle(); @Managed(description = "The maximum number of active connections that can be allocated at the same time.") synchronized int getMaxActive(); @Managed(description = "Set the maximum number of active connections that can be allocated at the same time. Use a negative value for no limit.") synchronized void setMaxActive(int maxActive); @Managed(description = "The maximum number of connections that can remain idle in the pool.") synchronized int getMaxIdle(); @Managed(description = "Set the maximum number of connections that can remain idle in the pool.") synchronized void setMaxIdle(int maxIdle); @Managed(description = "The minimum number of idle connections in the pool.") synchronized int getMinIdle(); @Managed(description = "The minimum number of idle connections in the pool.") synchronized void setMinIdle(int minIdle); @Managed(description = "The maximum number of milliseconds that the pool will wait for a connection to be returned before throwing an exception.") synchronized long getMaxWait(); @Managed(description = "Set the maxWait property. Use -1 to make the pool wait indefinitely.") synchronized void setMaxWait(long maxWait); @Managed synchronized String getUrl(); @Managed String getUsername(); static final String DEFAULT_MBEAN_NAME; }### Answer:
@Test public void testMBeanRegistered() throws Exception { final ManagedBasicDataSource testDataSource = new ManagedBasicDataSource(); assertTrue(getMBeanServerConnection().isRegistered(new ObjectName(testDataSource.getMBeanName()))); }
@Test public void testMBeanRegisteredThroughFactory() throws Exception { final ManagedBasicDataSource testDataSource = (ManagedBasicDataSource) ManagedBasicDataSourceFactory.createDataSource(new Properties()); assertTrue(getMBeanServerConnection().isRegistered(new ObjectName(testDataSource.getMBeanName()))); }
@Test(dataProvider = "testAttributeExistsProvider") public void testAttributeExists(String attributeName) throws Exception { final ManagedBasicDataSource testDataSource = (ManagedBasicDataSource) ManagedBasicDataSourceFactory.createDataSource(new Properties()); getMBeanServerConnection().getAttribute(new ObjectName(testDataSource.getMBeanName()), attributeName); }
@Test(dataProvider = "testConfigurableAttributeProvider") public void testConfigurableAttribute(String attributeProperty, Object attributePropertyValue, String attributeName, String attributeGetterName) throws Exception { final Properties testDataSourceProperties = new Properties(); testDataSourceProperties.put(attributeProperty, String.valueOf(attributePropertyValue)); final ManagedBasicDataSource testDataSource = (ManagedBasicDataSource) ManagedBasicDataSourceFactory.createDataSource(testDataSourceProperties); final Object attributeValue = getMBeanServerConnection().getAttribute(new ObjectName(testDataSource.getMBeanName()), attributeName); assertTrue((ManagedBasicDataSource.class.getMethod(attributeGetterName).invoke(testDataSource)).equals(attributeValue)); }