|
|
@ -42,27 +42,49 @@ class ConnectionDetailsFactoriesTests {
|
|
|
|
private final MockSpringFactoriesLoader loader = new MockSpringFactoriesLoader();
|
|
|
|
private final MockSpringFactoriesLoader loader = new MockSpringFactoriesLoader();
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void getConnectionDetailsWhenNoFactoryForSourceThrowsException() {
|
|
|
|
void getRequiredConnectionDetailsWhenNoFactoryForSourceThrowsException() {
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
assertThatExceptionOfType(ConnectionDetailsFactoryNotFoundException.class)
|
|
|
|
assertThatExceptionOfType(ConnectionDetailsFactoryNotFoundException.class)
|
|
|
|
.isThrownBy(() -> factories.getConnectionDetails("source"));
|
|
|
|
.isThrownBy(() -> factories.getConnectionDetails("source", true));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void getOptionalConnectionDetailsWhenNoFactoryForSourceThrowsException() {
|
|
|
|
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
|
|
|
|
assertThat(factories.getConnectionDetails("source", false)).isEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void getConnectionDetailsWhenSourceHasOneMatchReturnsSingleResult() {
|
|
|
|
void getConnectionDetailsWhenSourceHasOneMatchReturnsSingleResult() {
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, new TestConnectionDetailsFactory());
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, new TestConnectionDetailsFactory());
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
Map<Class<?>, ConnectionDetails> connectionDetails = factories.getConnectionDetails("source");
|
|
|
|
Map<Class<?>, ConnectionDetails> connectionDetails = factories.getConnectionDetails("source", false);
|
|
|
|
assertThat(connectionDetails).hasSize(1);
|
|
|
|
assertThat(connectionDetails).hasSize(1);
|
|
|
|
assertThat(connectionDetails.get(TestConnectionDetails.class)).isInstanceOf(TestConnectionDetailsImpl.class);
|
|
|
|
assertThat(connectionDetails.get(TestConnectionDetails.class)).isInstanceOf(TestConnectionDetailsImpl.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void getRequiredConnectionDetailsWhenSourceHasNoMatchTheowsException() {
|
|
|
|
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, new NullResultTestConnectionDetailsFactory());
|
|
|
|
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
|
|
|
|
assertThatExceptionOfType(ConnectionDetailsNotFoundException.class)
|
|
|
|
|
|
|
|
.isThrownBy(() -> factories.getConnectionDetails("source", true));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void getOptionalConnectionDetailsWhenSourceHasNoMatchReturnsEmptyMap() {
|
|
|
|
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, new NullResultTestConnectionDetailsFactory());
|
|
|
|
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
|
|
|
|
Map<Class<?>, ConnectionDetails> connectionDetails = factories.getConnectionDetails("source", false);
|
|
|
|
|
|
|
|
assertThat(connectionDetails).isEmpty();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void getConnectionDetailsWhenSourceHasMultipleMatchesReturnsMultipleResults() {
|
|
|
|
void getConnectionDetailsWhenSourceHasMultipleMatchesReturnsMultipleResults() {
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, new TestConnectionDetailsFactory(),
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, new TestConnectionDetailsFactory(),
|
|
|
|
new OtherConnectionDetailsFactory());
|
|
|
|
new OtherConnectionDetailsFactory());
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
Map<Class<?>, ConnectionDetails> connectionDetails = factories.getConnectionDetails("source");
|
|
|
|
Map<Class<?>, ConnectionDetails> connectionDetails = factories.getConnectionDetails("source", false);
|
|
|
|
assertThat(connectionDetails).hasSize(2);
|
|
|
|
assertThat(connectionDetails).hasSize(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -71,7 +93,7 @@ class ConnectionDetailsFactoriesTests {
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, new TestConnectionDetailsFactory(),
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, new TestConnectionDetailsFactory(),
|
|
|
|
new TestConnectionDetailsFactory());
|
|
|
|
new TestConnectionDetailsFactory());
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
assertThatIllegalStateException().isThrownBy(() -> factories.getConnectionDetails("source"))
|
|
|
|
assertThatIllegalStateException().isThrownBy(() -> factories.getConnectionDetails("source", false))
|
|
|
|
.withMessage("Duplicate connection details supplied for " + TestConnectionDetails.class.getName());
|
|
|
|
.withMessage("Duplicate connection details supplied for " + TestConnectionDetails.class.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -82,7 +104,7 @@ class ConnectionDetailsFactoriesTests {
|
|
|
|
TestConnectionDetailsFactory orderThree = new TestConnectionDetailsFactory(3);
|
|
|
|
TestConnectionDetailsFactory orderThree = new TestConnectionDetailsFactory(3);
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, orderOne, orderThree, orderTwo);
|
|
|
|
this.loader.addInstance(ConnectionDetailsFactory.class, orderOne, orderThree, orderTwo);
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
ConnectionDetailsFactories factories = new ConnectionDetailsFactories(this.loader);
|
|
|
|
List<Registration<String, ?>> registrations = factories.getRegistrations("source");
|
|
|
|
List<Registration<String, ?>> registrations = factories.getRegistrations("source", false);
|
|
|
|
assertThat(registrations.get(0).factory()).isEqualTo(orderOne);
|
|
|
|
assertThat(registrations.get(0).factory()).isEqualTo(orderOne);
|
|
|
|
assertThat(registrations.get(1).factory()).isEqualTo(orderTwo);
|
|
|
|
assertThat(registrations.get(1).factory()).isEqualTo(orderTwo);
|
|
|
|
assertThat(registrations.get(2).factory()).isEqualTo(orderThree);
|
|
|
|
assertThat(registrations.get(2).factory()).isEqualTo(orderThree);
|
|
|
@ -119,6 +141,16 @@ class ConnectionDetailsFactoriesTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final class NullResultTestConnectionDetailsFactory
|
|
|
|
|
|
|
|
implements ConnectionDetailsFactory<String, TestConnectionDetails> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public TestConnectionDetails getConnectionDetails(String source) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final class OtherConnectionDetailsFactory
|
|
|
|
private static final class OtherConnectionDetailsFactory
|
|
|
|
implements ConnectionDetailsFactory<String, OtherConnectionDetails> {
|
|
|
|
implements ConnectionDetailsFactory<String, OtherConnectionDetails> {
|
|
|
|
|
|
|
|
|
|
|
|