CreateCollectionActor { public void createTable(CreateCollectionWrapper message) throws CreateCollectionActorException { try { final ConnectionOptions options = IOC.resolve(Keys.getOrAdd(message.getConnectionOptionsRegistrationName())); final IPool pool = IOC.resolve(Keys.getOrAdd("PostgresConnectionPool"), options); String collectionName = message.getCollectionName(); try (PoolGuard guard = new PoolGuard(pool)) { ITask task = IOC.resolve( Keys.getOrAdd("db.collection.create-if-not-exists"), guard.getObject(), collectionName, message.getOptions() ); task.execute(); } catch (TaskExecutionException | ResolutionException | PoolGuardException e) { throw new CreateCollectionActorException(e); } } catch (ReadValueException | ResolutionException e) { throw new CreateCollectionActorException(e); } }  void createTable(CreateCollectionWrapper message);  }
@Test public void Should_CreateCollection() throws Exception { CreateCollectionWrapper wrapper = mock(CreateCollectionWrapper.class); when(wrapper.getCollectionName()).thenReturn("test"); when(wrapper.getConnectionOptionsRegistrationName()).thenReturn("connectionOptions"); when(wrapper.getOptions()).thenReturn(null); ITask task = mock(ITask.class); IOC.register(Keys.getOrAdd("db.collection.create-if-not-exists"), new ApplyFunctionToArgumentsStrategy(args -> task) ); actor.createTable(wrapper); verify(task, VerificationModeFactory.times(1)).execute(); }