### Question:
CustomDataSourceContextStrategy implements
        ContextManagementStrategy<ClientCustomDataSource, ClientCustomDataSource>,
        GenericTypeMetadataBuilder<ClientCustomDataSource>,
        ContextParametrizedMetadataBuilder<ClientCustomDataSource, PartialMetadataOptions> { @Override public Object build(ClientCustomDataSource context, Map<String, String[]> options, Map<String, Object> contextData) { Object result; try { result = jdbcDataSourceMetadataBuilder.build(context, options, contextData); } catch (UnsupportedDataSourceException e) { throw e; } catch (Exception e) { throw new ErrorDescriptorException(e, secureExceptionHandler); } return result; }  @Override ClientCustomDataSource createContext(ClientCustomDataSource contextDescription, Map<String, Object> data); @Override void deleteContext(ClientCustomDataSource contextDescription, Map<String, Object> data); @Override ClientCustomDataSource getContextForClient(ClientCustomDataSource contextDescription, Map<String, Object> data, Map<String, String[]> additionalProperties); boolean isMetadataSupported(ClientCustomDataSource clientCustomDataSource, String metadataClientType); @Override Object build(ClientCustomDataSource context, Map<String, String[]> options, Map<String, Object> contextData); @Override String getMetadataClientResourceType(ClientCustomDataSource connectionDescription); @Override Object build(ClientCustomDataSource context, PartialMetadataOptions options, Map<String, Object> contextData);  }### Answer:
@Test public void build_jdbcDataSourceMetadataBuilder_isUsed(){ final ResourceGroupElement expectedResult = new ResourceGroupElement(); doReturn(expectedResult).when(jdbcDataSourceMetadataBuilder).build(same(customDataSource), any(Map.class), any(Map.class)); final Object result = strategySpy.build(customDataSource, new HashMap<String, String[]>(), new HashMap<String, Object>()); assertSame(result, expectedResult); }
@Test public void build_containsMetadataIsFalse_partialMetadataOptions_jdbcDataSourceMetadataBuilder_isUsed(){ final ResourceGroupElement expectedResult = new ResourceGroupElement(); doReturn(expectedResult).when(jdbcDataSourceMetadataBuilder).build(same(customDataSource), any(PartialMetadataOptions.class), any(Map.class)); final Object result = strategySpy.build(customDataSource, new PartialMetadataOptions(), new HashMap<String, Object>()); assertSame(result, expectedResult); }
@Test(expectedExceptions = ErrorDescriptorException.class) public void build_containsMetadataIsFalse_jdbcDataSourceMetadataBuilderThrowsException_exceptionIsExpected(){ doThrow(new RuntimeException()).when(jdbcDataSourceMetadataBuilder).build(same(customDataSource), any(Map.class), any(Map.class)); strategySpy.build(customDataSource, new HashMap<String, String[]>(), new HashMap<String, Object>()); }
@Test(expectedExceptions = UnsupportedDataSourceException.class) public void build_containsMetadataIsFalse_UnsupportedDataSourceException_NotAcceptableException(){ doThrow(new UnsupportedDataSourceException()).when(jdbcDataSourceMetadataBuilder).build(same(customDataSource), any(Map.class), any(Map.class)); strategySpy.build(customDataSource, new HashMap<String, String[]>(), new HashMap<String, Object>()); }