Package se.jbee.inject

Examples of se.jbee.inject.Injector


    assertEqualSets( new Integer[] { 1, 2, 3, 4, 5, 11 }, anys );
  }

  @Test
  public void thatMultipleBoundNamedElementsCanUsedAsList() {
    Injector injector = Bootstrap.injector( MultibindBindsBundle.class );
    List<Integer> foos = injector.resolve( dependency( listTypeOf( Integer.class ) ).named( foo ) );
    assertEqualSets( new Integer[] { 2, 3 }, foos.toArray() );
    List<Integer> bars = injector.resolve( dependency( listTypeOf( Integer.class ) ).named( bar ) );
    assertEqualSets( new Integer[] { 4, 5 }, bars.toArray() );
  }
View Full Code Here


    assertEqualSets( new Integer[] { 4, 5 }, bars.toArray() );
  }

  @Test
  public void thatMultipleBoundNamedElementsCanUsedAsSet() {
    Injector injector = Bootstrap.injector( MultibindBindsBundle.class );
    Set<Integer> foos = injector.resolve( dependency( setTypeOf( Integer.class ) ).named( foo ) );
    assertEqualSets( new Integer[] { 2, 3 }, foos.toArray() );
    Set<Integer> bars = injector.resolve( dependency( setTypeOf( Integer.class ) ).named( bar ) );
    assertEqualSets( new Integer[] { 4, 5 }, bars.toArray() );
  }
View Full Code Here

    }
  }

  @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 );
  }
View Full Code Here

  }

  @Test
  public void test() {
    Injector injector = Bootstrap.injector( SupplierBindsModule.class );
    String value = injector.resolve( dependency( String.class ) );
    assertThat( value, is( "foobar" ) );
  }
View Full Code Here

  /**
   * The assert itself doesn't play such huge role here. we just want to reach this code.
   */
  @Test(timeout=50)
  public void thatBundlesAreNotBootstrappedMultipleTimesEvenWhenTheyAreMutual() {
    Injector injector = Bootstrap.injector( OneMutualDependentBundle.class );
    assertThat( injector, notNullValue() );
  }
View Full Code Here

    Bootstrap.injector( ClashingBindsModule.class );
  }

  @Test ( expected = DependencyCycleException.class, timeout=50 )
  public void thatDependencyCyclesAreDetected() {
    Injector injector = Bootstrap.injector( CyclicBindsModule.class );
    Foo foo = injector.resolve( dependency( Foo.class ) );
    fail( "foo should not be resolvable but was: " + foo );
  }
View Full Code Here

    fail( "foo should not be resolvable but was: " + foo );
  }

  @Test ( expected = DependencyCycleException.class, timeout=50 )
  public void thatDependencyCyclesInCirclesAreDetected() {
    Injector injector = Bootstrap.injector( CircularBindsModule.class );
    A a = injector.resolve( dependency( A.class ) );
    fail( "A should not be resolvable but was: " + a );
  }
View Full Code Here

   * {@link Float} but an {@link DeclarationType#EXPLICIT} bind done overrides these automatic
   * binds. They are removed and no {@link Injectron} is created for them.
   */
  @Test
  public void thatBindingsAreReplacedByMorePreciseOnes() {
    Injector injector = Bootstrap.injector( ReplacingBindsModule.class );
    assertEquals( 6, injector.resolve( dependency( Number.class ) ) );
    Injectron<?>[] injectrons = injector.resolve( dependency( Injectron[].class ) );
    assertEquals( 7, injectrons.length ); // 3x Comparable, Float, Double, Integer and Number (3x Serializable has been nullified)
    Injectron<Number>[] numberInjectrons = injector.resolve( dependency( injectronsTypeOf( Number.class ) ) );
    assertEquals( 1, numberInjectrons.length );
    @SuppressWarnings ( "rawtypes" )
    Injectron<Comparable>[] compareableInjectrons = injector.resolve( dependency( injectronsTypeOf( Comparable.class ) ) );
    assertEquals( 3, compareableInjectrons.length );
  }
View Full Code Here

    assertEquals( 3, compareableInjectrons.length );
  }

  @Test
  public void thatEagerSingeltonsCanBeCreated() {
    Injector injector = Bootstrap.injector( EagerSingletonsBindsModule.class );
    int before = EagerSingletonsBindsModule.eagers;
    Bootstrap.eagerSingletons( injector );
    assertEquals( before + 1, EagerSingletonsBindsModule.eagers );
  }
View Full Code Here

    assertEquals( before + 1, EagerSingletonsBindsModule.eagers );
  }

  @Test
  public void thatCustomInspectorIsUsedToPickConstructor() {
    Injector injector = Bootstrap.injector( CustomInspectedBundle.class );
    assertEquals( "will be passed to D", injector.resolve( dependency( D.class ) ).s );
  }
View Full Code Here

TOP

Related Classes of se.jbee.inject.Injector

Copyright © 2018 www.massapicom. 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.