Package se.jbee.inject.bind

Source Code of se.jbee.inject.bind.TestScopedBinds$Foo

package se.jbee.inject.bind;

import static org.junit.Assert.fail;
import static se.jbee.inject.Dependency.dependency;

import org.junit.Test;

import se.jbee.inject.Injector;
import se.jbee.inject.DIRuntimeException.MoreFrequentExpiryException;
import se.jbee.inject.bootstrap.Bootstrap;
import se.jbee.inject.util.Scoped;

public class TestScopedBinds {

  private static class Foo {

    @SuppressWarnings ( "unused" )
    Foo( Bar bar ) {
      // it is just about the instances
    }
  }

  private static class Bar {
    // just to demo
  }

  private static class ScopedBindsModule
      extends BinderModule {

    @Override
    protected void declare() {
      per( Scoped.APPLICATION ).construct( Foo.class );
      per( Scoped.INJECTION ).construct( Bar.class );
    }
  }

  @Test ( expected = MoreFrequentExpiryException.class )
  public void thatInjectingAnInjectionScopedInstanceIntoAppScopedInstanceThrowsAnException() {
    Injector injector = Bootstrap.injector( ScopedBindsModule.class );
    Foo foo = injector.resolve( dependency( Foo.class ) );
    fail( "It should not be possible to create a foo but got one: " + foo );
  }
}
TOP

Related Classes of se.jbee.inject.bind.TestScopedBinds$Foo

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.