org.picocontainer.adapters.ComponentAdapterTestCase Maven / Gradle / Ivy
/*****************************************************************************
* Copyright (C) PicoContainer Organization. All rights reserved. *
* ------------------------------------------------------------------------- *
* The software in this package is published under the terms of the BSD *
* style license a copy of which has been included with this distribution in *
* the LICENSE.txt file. *
*****************************************************************************/
package org.picocontainer.adapters;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import org.junit.Test;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.ComponentMonitor;
import org.picocontainer.Parameter;
import org.picocontainer.PicoCompositionException;
import org.picocontainer.PicoContainer;
import org.picocontainer.PicoVerificationException;
import org.picocontainer.PicoVisitor;
import org.picocontainer.injectors.AbstractInjector;
import org.picocontainer.lifecycle.NullLifecycleStrategy;
import org.picocontainer.monitors.NullComponentMonitor;
import org.picocontainer.parameters.ConstantParameter;
/**
* Test AbstractAdapter behaviour
* @author Jörg Schaible
*/
public class ComponentAdapterTestCase {
@SuppressWarnings("serial")
private static class TestAdapter extends AbstractAdapter {
TestAdapter(Object componentKey, Class componentImplementation, ComponentMonitor componentMonitor) {
super(componentKey, componentImplementation, componentMonitor);
}
TestAdapter(Object componentKey, Class componentImplementation) {
super(componentKey, componentImplementation);
}
public T getComponentInstance(PicoContainer container) throws PicoCompositionException {
return null;
}
public T getComponentInstance(PicoContainer container, Type into) throws PicoCompositionException {
return null;
}
public void verify(PicoContainer container) throws PicoVerificationException {
}
public String getDescriptor() {
return TestAdapter.class.getName() + ":" ;
}
}
@SuppressWarnings("serial")
private static class TestMonitoringComponentAdapter extends AbstractAdapter {
TestMonitoringComponentAdapter(ComponentMonitor componentMonitor) {
super(null, null, componentMonitor);
}
public T getComponentInstance(PicoContainer container) throws PicoCompositionException {
return null;
}
public T getComponentInstance(PicoContainer container, Type into) throws PicoCompositionException {
return null;
}
public void verify(PicoContainer container) throws PicoVerificationException {
}
public Object getComponentKey() {
return null;
}
public Class getComponentImplementation() {
return null;
}
public void accept(PicoVisitor visitor) {
}
public String getDescriptor() {
return null;
}
}
@SuppressWarnings("serial")
private static class TestInstantiatingAdapter extends AbstractInjector {
TestInstantiatingAdapter(Object componentKey, Class componentImplementation, Parameter... parameters) {
super(componentKey, componentImplementation, parameters, new NullComponentMonitor(), false);
}
@Override
public void verify(PicoContainer container) throws PicoCompositionException {
}
public T getComponentInstance(PicoContainer container, Type into) throws PicoCompositionException {
return null;
}
public T getComponentInstance(PicoContainer container) throws PicoCompositionException {
return null;
}
public String getDescriptor() {
return null;
}
}
@Test public void testComponentImplementationMayNotBeNull() {
try {
new TestAdapter