Package com.calclab.suco.client.ioc.module

Source Code of com.calclab.suco.client.ioc.module.ModuleBuiderTest

package com.calclab.suco.client.ioc.module;

import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import org.junit.Before;
import org.junit.Test;

import com.calclab.suco.client.ioc.Container;
import com.calclab.suco.client.ioc.Decorator;
import com.calclab.suco.client.ioc.Provider;
import com.calclab.suco.client.ioc.TestHelper;
import com.calclab.suco.client.ioc.TestHelper.VerificableFactory;
import com.calclab.suco.client.ioc.decorator.NoDecoration;

public class ModuleBuiderTest {

    private Container container;
    private ModuleBuilderImpl builder;

    @Before
    public void before() {
  container = mock(Container.class);
  builder = new ModuleBuilderImpl();
  builder.setContainer(container);
    }

    @Test
    public void shouldRegisterFactoriesWithoutDecoration() {
  final VerificableFactory<Object> f1 = TestHelper.factory();
  final VerificableFactory<Object> f2 = TestHelper.factory();
  builder.register(f1, f2);
  verify(container).registerProvider(same(NoDecoration.instance), eq(Object.class), same(f1));
    }

    @Test
    public void shouldRegisterProviderWithDecorator() {
  final Decorator d = NoDecoration.instance;
  final Class<Object> cType = Object.class;
  final Provider<Object> provider = TestHelper.provider();
  builder.register(d, cType, provider);
  verify(container).registerProvider(d, cType, provider);
    }

    @Test
    public void shouldRegisterProviderWithDecoratorType() {
  final Class<NoDecoration> dType = NoDecoration.class;
  final Class<Object> cType = Object.class;
  final Provider<Object> provider = TestHelper.provider();
  builder.register(dType, cType, provider);
  verify(container).getInstance(dType);
  verify(container).registerProvider(null, cType, provider);
    }

    @Test
    public void shouldRegisterProviderWithoutDecorator() {
  final Class<Object> cType = Object.class;
  final Provider<Object> provider = TestHelper.provider();
  builder.register(cType, provider);
  verify(container).registerProvider(null, cType, provider);
    }

    @Test
    public void testInstall() {
  final SucoModule m1 = mock(SucoModule.class);
  final SucoModule m2 = mock(SucoModule.class);
  builder.install(m1, m2);
  verify(m1).onInstall(container);
  verify(m2).onInstall(container);
    }
}
TOP

Related Classes of com.calclab.suco.client.ioc.module.ModuleBuiderTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.