@Test public void returns_error_if_both_database_instance_and_datasource_are_provided() { Collection<String> errors = datasourceConfigurationValidator.validate( Optional.empty(), Optional.of(mock(DataSource.class)), Optional.of("some-instance")); assertThat(errors).containsExactly("Database instance cannot be configured when configuring a DataSource"); }
public Collection<String> validate(Optional<String> uri, Optional<DataSource> dataSource, Optional<String> database) { if (uri.isPresent() == dataSource.isPresent()) { return Collections.singletonList("Exactly one of JDBC URI or DataSource need to be configured"); } if (database.isPresent() && dataSource.isPresent()) { return Collections.singletonList("Database instance cannot be configured when configuring a DataSource"); } return uri.map(DatasourceConfigurationValidator::validateConnectionString).orElse(emptyList()); }
DatasourceConfigurationValidator { public Collection<String> validate(Optional<String> uri, Optional<DataSource> dataSource, Optional<String> database) { if (uri.isPresent() == dataSource.isPresent()) { return Collections.singletonList("Exactly one of JDBC URI or DataSource need to be configured"); } if (database.isPresent() && dataSource.isPresent()) { return Collections.singletonList("Database instance cannot be configured when configuring a DataSource"); } return uri.map(DatasourceConfigurationValidator::validateConnectionString).orElse(emptyList()); } }
DatasourceConfigurationValidator { public Collection<String> validate(Optional<String> uri, Optional<DataSource> dataSource, Optional<String> database) { if (uri.isPresent() == dataSource.isPresent()) { return Collections.singletonList("Exactly one of JDBC URI or DataSource need to be configured"); } if (database.isPresent() && dataSource.isPresent()) { return Collections.singletonList("Database instance cannot be configured when configuring a DataSource"); } return uri.map(DatasourceConfigurationValidator::validateConnectionString).orElse(emptyList()); }  }
DatasourceConfigurationValidator { public Collection<String> validate(Optional<String> uri, Optional<DataSource> dataSource, Optional<String> database) { if (uri.isPresent() == dataSource.isPresent()) { return Collections.singletonList("Exactly one of JDBC URI or DataSource need to be configured"); } if (database.isPresent() && dataSource.isPresent()) { return Collections.singletonList("Database instance cannot be configured when configuring a DataSource"); } return uri.map(DatasourceConfigurationValidator::validateConnectionString).orElse(emptyList()); }  Collection<String> validate(Optional<String> uri, Optional<DataSource> dataSource, Optional<String> database); }
DatasourceConfigurationValidator { public Collection<String> validate(Optional<String> uri, Optional<DataSource> dataSource, Optional<String> database) { if (uri.isPresent() == dataSource.isPresent()) { return Collections.singletonList("Exactly one of JDBC URI or DataSource need to be configured"); } if (database.isPresent() && dataSource.isPresent()) { return Collections.singletonList("Database instance cannot be configured when configuring a DataSource"); } return uri.map(DatasourceConfigurationValidator::validateConnectionString).orElse(emptyList()); }  Collection<String> validate(Optional<String> uri, Optional<DataSource> dataSource, Optional<String> database);  }