org.picocontainer.defaults.PicoExceptionsTestCase 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. *
* *
* Original code by Joerg Schaible *
*****************************************************************************/
package org.picocontainer.defaults;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.PicoCompositionException;
import org.picocontainer.PicoException;
import org.picocontainer.injectors.AbstractInjector;
import org.picocontainer.injectors.ConstructorInjector;
import org.picocontainer.lifecycle.NullLifecycleStrategy;
import org.picocontainer.monitors.AbstractComponentMonitor;
/**
* Unit tests for the several PicoException classes.
*/
public class PicoExceptionsTestCase {
final static public String MESSAGE = "Message of the exception";
final static public Throwable THROWABLE = new Throwable();
@SuppressWarnings({ "unchecked" })
final void executeTestOfStandardException(final Class clazz) {
final ComponentAdapter componentAdapter = new ConstructorInjector(clazz, clazz, null, new AbstractComponentMonitor(),
new NullLifecycleStrategy(), false);
DefaultPicoContainer pico = new DefaultPicoContainer();
pico.addComponent(MESSAGE);
try {
final Exception exception = (Exception) componentAdapter.getComponentInstance(pico);
assertEquals(MESSAGE, exception.getMessage());
} catch (final AbstractInjector.UnsatisfiableDependenciesException ex) {
final Set