// Path: src/main/java/ru/vyarus/guice/ext/core/type/GeneralTypeListener.java
// public class GeneralTypeListener<T> implements TypeListener {
// 
//     private final Class<T> typeClass;
//     private final TypePostProcessor<T> postProcessor;
// 
//     public GeneralTypeListener(final Class<T> typeClass, final TypePostProcessor<T> postProcessor) {
//         this.typeClass = typeClass;
//         this.postProcessor = postProcessor;
//     }
// 
//     @Override
//     @SuppressWarnings("unchecked")
//     public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) {
//         final Class<? super I> actualType = type.getRawType();
//         if (!Utils.isPackageValid(actualType)) {
//             return;
//         }
//         if (typeClass.isAssignableFrom(actualType)) {
//             encounter.register(new InjectionListener<I>() {
//                 @Override
//                 public void afterInjection(final I injectee) {
//                     try {
//                         postProcessor.process((T) injectee);
//                     } catch (Exception ex) {
//                         throw new IllegalStateException(
//                                 String.format("Failed to process type %s of class %s",
//                                         typeClass.getSimpleName(), injectee.getClass().getSimpleName()), ex);
//                     }
//                 }
//             });
//         }
//     }
// }


import com.google.inject.*;
import com.google.inject.matcher.Matchers;
import org.junit.Assert;
import org.junit.Test;
import ru.vyarus.guice.ext.core.type.GeneralTypeListener;
import ru.vyarus.guice.ext.postprocess.support.*;
package ru.vyarus.guice.ext.postprocess;


/**
 * @author Vyacheslav Rusakov
 * @since 06.01.2015
 */
public class TypePostProcessorTest {

    @Test
    public void testPostProcessingByType() throws Exception {
        final PostProcessor postProcessor = new PostProcessor();
        Injector injector = Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bind(Bean1.class).asEagerSingleton();
                bind(Bean2.class).asEagerSingleton();
                bind(Bean3.class).asEagerSingleton();
                bindListener(Matchers.any(),
// Path: src/main/java/ru/vyarus/guice/ext/core/type/GeneralTypeListener.java
// public class GeneralTypeListener<T> implements TypeListener {
// 
//     private final Class<T> typeClass;
//     private final TypePostProcessor<T> postProcessor;
// 
//     public GeneralTypeListener(final Class<T> typeClass, final TypePostProcessor<T> postProcessor) {
//         this.typeClass = typeClass;
//         this.postProcessor = postProcessor;
//     }
// 
//     @Override
//     @SuppressWarnings("unchecked")
//     public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) {
//         final Class<? super I> actualType = type.getRawType();
//         if (!Utils.isPackageValid(actualType)) {
//             return;
//         }
//         if (typeClass.isAssignableFrom(actualType)) {
//             encounter.register(new InjectionListener<I>() {
//                 @Override
//                 public void afterInjection(final I injectee) {
//                     try {
//                         postProcessor.process((T) injectee);
//                     } catch (Exception ex) {
//                         throw new IllegalStateException(
//                                 String.format("Failed to process type %s of class %s",
//                                         typeClass.getSimpleName(), injectee.getClass().getSimpleName()), ex);
//                     }
//                 }
//             });
//         }
//     }
// }


// Path: src/test/java/ru/vyarus/guice/ext/postprocess/TypePostProcessorTest.java
import com.google.inject.*;
import com.google.inject.matcher.Matchers;
import org.junit.Assert;
import org.junit.Test;
import ru.vyarus.guice.ext.core.type.GeneralTypeListener;
import ru.vyarus.guice.ext.postprocess.support.*;

package ru.vyarus.guice.ext.postprocess;


/**
 * @author Vyacheslav Rusakov
 * @since 06.01.2015
 */
public class TypePostProcessorTest {

    @Test
    public void testPostProcessingByType() throws Exception {
        final PostProcessor postProcessor = new PostProcessor();
        Injector injector = Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                bind(Bean1.class).asEagerSingleton();
                bind(Bean2.class).asEagerSingleton();
                bind(Bean3.class).asEagerSingleton();
                bindListener(Matchers.any(),
                        new GeneralTypeListener<AbstractBean>(AbstractBean.class, postProcessor));