package com.calclab.suco.tests.ioc;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
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.HashMapContainer;
import com.calclab.suco.client.ioc.Provider;
@SuppressWarnings("unchecked")
public class HashMapContainerTest {
private Container container;
@Before
public void beforeTests() {
container = new HashMapContainer();
}
@Test(expected = RuntimeException.class)
public void shouldFaillToGetUnregisteredComponent() {
container.getInstance(Object.class);
}
@Test(expected = RuntimeException.class)
public void shouldNotRegisterSameKeyTwice() {
container.registerProvider(null, Object.class, TestHelper.provider());
container.registerProvider(null, Object.class, TestHelper.provider());
}
@Test
public void shouldRegisterProviders() {
final Provider<Object> provider = mock(Provider.class);
container.registerProvider(null, Object.class, provider);
container.getInstance(Object.class);
verify(provider).get();
}
@Test
public void shouldRemove() {
container.registerProvider(null, Object.class, TestHelper.provider());
assertTrue(container.hasProvider(Object.class));
container.removeProvider(Object.class);
assertFalse(container.hasProvider(Object.class));
}
@Test
public void shouldTestIfExsists() {
assertFalse(container.hasProvider(Object.class));
final Provider<Object> provider = mock(Provider.class);
container.registerProvider(null, Object.class, provider);
assertTrue(container.hasProvider(Object.class));
}
}