### Question:
ConnectionFactory { public XQConnection getConnection(XQDataSource dataSource) throws Exception { XQConnection connection; if (config.getDataSourceType().connectionPropertiesAreSupported() && config.getUsername() != null && config.getUsername().length() > 0) { connection = dataSource.getConnection(config.getUsername(), config.getPassword()); } else { connection = dataSource.getConnection(); } return connection; } ConnectionFactory(XQueryRunConfig config); XQConnection getConnection(XQDataSource dataSource);  }### Answer:
@Test public void shouldInvokeGetConnectionWithoutParametersWhenConnectionPropertiesNotSupported() throws Exception { given(config.getDataSourceType()).willReturn(XQueryDataSourceType.SAXON); factory.getConnection(dataSource); verify(dataSource).getConnection(); }
@Test public void shouldInvokeGetConnectionWithParametersWhenConnectionPropertiesAreSupportedAndSet() throws Exception { given(config.getDataSourceType()).willReturn(XQueryDataSourceType.MARKLOGIC); given(config.getUsername()).willReturn(USER); given(config.getPassword()).willReturn(PASSWORD); factory.getConnection(dataSource); verify(dataSource).getConnection(USER, PASSWORD); }
@Test public void shouldInvokeGetConnectionWithoutParametersWhenConnectionPropertiesAreSupportedAndUsernameNotSet() throws Exception { given(config.getUsername()).willReturn(null); given(config.getDataSourceType()).willReturn(XQueryDataSourceType.MARKLOGIC); factory.getConnection(dataSource); verify(dataSource).getConnection(); }
@Test public void shouldInvokeGetConnectionWithoutParametersWhenConnectionPropertiesAreSupportedAndUsernameSetEmpty() throws Exception { given(config.getUsername()).willReturn(""); given(config.getDataSourceType()).willReturn(XQueryDataSourceType.MARKLOGIC); factory.getConnection(dataSource); verify(dataSource).getConnection(); }