Search in sources :

Example 1 with DropwizardAppRule

use of io.dropwizard.testing.junit.DropwizardAppRule in project dropwizard-guicey by xvik.

the class DropwizardAppExtension method buildResourceFactory.

@Override
protected GuiceyInterceptor.ExternalRuleAdapter buildResourceFactory(final UseDropwizardApp annotation) {
    return new GuiceyInterceptor.ExternalRuleAdapter() {

        private DropwizardAppRule rule;

        @Override
        @SuppressWarnings("unchecked")
        public ExternalResource newResource() {
            Preconditions.checkState(rule == null, "External resource creation could be called once.");
            rule = new DropwizardAppRule(annotation.value(), annotation.config(), convertOverrides(annotation.configOverride()));
            return rule;
        }

        @Override
        public Injector getInjector() {
            Preconditions.checkState(rule != null, "External resource not created.");
            return InjectorLookup.getInjector(rule.getApplication()).get();
        }
    };
}
Also used : DropwizardAppRule(io.dropwizard.testing.junit.DropwizardAppRule)

Aggregations

DropwizardAppRule (io.dropwizard.testing.junit.DropwizardAppRule)1