Sha256: 222399e26bf310af19ff706cf6f1e2e378333a8828028e2f21eb6ed86e95c907

Contents?: true

Size: 1.57 KB

Versions: 149

Compression:

Stored size: 1.57 KB

Contents

package org.embulk.plugin;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.multibindings.Multibinder;

public class MockPluginSource
        implements PluginSource
{
    private final Class<?> expectedIface;
    private final Object plugin;
    private PluginType typeConfig;

    public <T> MockPluginSource(Class<T> expectedIface, T plugin)
    {
        this.expectedIface = expectedIface;
        this.plugin = plugin;
    }

    public PluginType getTypeConfig()
    {
        return typeConfig;
    }

    @SuppressWarnings("unchecked")
    public <T> T newPlugin(Class<T> iface, PluginType typeConfig) throws PluginSourceNotMatchException
    {
        if (expectedIface.equals(iface)) {
            this.typeConfig = typeConfig;
            return (T) plugin;
        } else {
            throw new PluginSourceNotMatchException();
        }
    }

    public static <T> Module newInjectModule(final Class<T> expectedIface, final T plugin)
    {
        return new InjectModule(expectedIface, plugin);
    }

    public static class InjectModule
            implements Module
    {
        private final PluginSource pluginSource;

        public <T> InjectModule(Class<T> expectedIface, T plugin)
        {
            this.pluginSource = new MockPluginSource(expectedIface, plugin);
        }

        @Override
        public void configure(Binder binder)
        {
            Multibinder<PluginSource> multibinder = Multibinder.newSetBinder(binder, PluginSource.class);
            multibinder.addBinding().toInstance(pluginSource);
        }
    }
}

Version data entries

149 entries across 149 versions & 1 rubygems

Version Path
embulk-0.8.39 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.39-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.38 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.38-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.37 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.37-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.36 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.36-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.35 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.35-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.34 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.34-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.33 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.33-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.32 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.32-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.31 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.31-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.30 embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java
embulk-0.8.30-java embulk-core/src/test/java/org/embulk/plugin/MockPluginSource.java