All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.paradoxical.common.test.web.modules.MockEnvironmentModule Maven / Gradle / Ivy

There is a newer version: 2.0
Show newest version
package io.paradoxical.common.test.web.modules;

import com.google.inject.Module;
import io.dropwizard.setup.Environment;
import io.paradoxical.common.test.guice.OverridableModule;
import lombok.Getter;
import org.mockito.Mockito;

/**
 * Can be used to mock out dropwizard environment and auto mock the config class for a dropwizard service
 */
public class MockEnvironmentModule extends OverridableModule {
    private final Class configClass;

    @Getter
    private final T configInstance;

    @Getter
    private Environment mockEnvironment = Mockito.mock(Environment.class);


    public MockEnvironmentModule(Class configClass) {
        this.configClass = configClass;

        configInstance = Mockito.mock(configClass);
    }

    public MockEnvironmentModule(T config) {
        configClass = (Class) config.getClass();

        configInstance = config;
    }

    @Override
    public Class getOverridesModule() {
        return null;
    }

    @Override
    protected void configure() {
        bind(Environment.class).toInstance(mockEnvironment);

        bind(configClass).toInstance(configInstance);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy