Package se.jbee.inject

Examples of se.jbee.inject.Injector


        listTypeOf( listTypeOf( String.class ) ) );
  }

  @Test
  public void thatCollectionIsAvailableWhenJustListIsInstalled() {
    Injector injector = Bootstrap.injector( CollectionBindsJustListBundle.class );
    Type<? extends Collection<?>> collectionType = collectionTypeOf( Integer.class );
    new AssertInjects( injector ).assertInjectsItems( new Integer[] { 846, 42 }, collectionType );
  }
View Full Code Here


   * A monomodal module has just one initial state (or no state). Therefore it can be determined
   * that installing it twice or more does not make sense.
   */
  @Test
  public void thatMonomodalModulesCanBeInstalledTwice() {
    Injector injector = Bootstrap.injector( LinkerBundle.class );
    assertEquals( 42, injector.resolve( dependency( Integer.class ) ).intValue() );
  }
View Full Code Here

    Bootstrap.injector( RequirementModule.class );
  }

  @Test
  public void thatRequirementIsFulfilledByProvidedBind() {
    Injector injector = Bootstrap.injector( RequiredProvidedBindsBundle.class );
    assertNotNull( injector.resolve( dependency( ExampleService.class ) ) );
  }
View Full Code Here

    assertNotNull( injector.resolve( dependency( ExampleService.class ) ) );
  }

  @Test
  public void thatUnusedProvidedBindIsNotAddedToInjectorContext() {
    Injector injector = Bootstrap.injector( RequiredProvidedBindsBundle.class );
    try {
      injector.resolve( dependency( UnusedImpl.class ) );
      fail( "Should not be bound and therefore throw below exception" );
    } catch ( NoSuchResourceException e ) {
      // expected this
    } catch ( Throwable e ) {
      fail( "Expected another exception but got: " + e );
View Full Code Here

    }
  }

  @Test
  public void thatAnExplicitBindReplacesTheProvidedImplementation() {
    Injector injector = Bootstrap.injector( ExplicitBindBundle.class );
    ExampleService s = injector.resolve( dependency( ExampleService.class ) );
    assertTrue( s instanceof ExplicitExampleService );
  }
View Full Code Here

    assertThat( injectrons[1].instanceFor( dependency( String.class ) ), is( "special" ) );
  }

  @Test
  public void thatInjectorIsAvailableByDefault() {
    Injector resolved = injector.resolve( dependency( Injector.class ) );
    assertThat( resolved, sameInstance( injector ) );
  }
View Full Code Here

   
  }
 
  @Test
  public void thatImplementationIsPickedAsSpecified() {
    Injector injector = Bootstrap.injector(SpecificImplementationBindsModule.class);
   
    Receiver r = injector.resolve(dependency(Receiver.class));
    assertEquals(ActionA.class, r.a.getClass());
    assertEquals(GenericAction.class, r.b.getClass());
    assertEquals(GenericAction.class, r.c.getClass());
    assertEquals("this is b", r.b.doIt());
    assertEquals("and this is c", r.c.doIt());
View Full Code Here

    }
  }

  @Test
  public void thatServiceCanBeResolvedWhenHavingGenericsInSameOrder() {
    Injector injector = Bootstrap.injector( ServiceBindsModule.class );
    @SuppressWarnings ( { "rawtypes" } )
    Dependency<Service> dependency = dependency( raw( Service.class ).parametized(
        Integer.class, Long.class ) );
    @SuppressWarnings ( "unchecked" )
    Service<Integer, Long> square = injector.resolve( dependency );
    assertThat( square.calc( 2 ), is( 4L ) );
  }
View Full Code Here

  }

  @Test
  public void thatBundleCanBeBootstrapped() {
    Injector injector = Bootstrap.injector( Bundle1.class );
    B b = injector.resolve( dependency( B.class ) );
    B leftB = injector.resolve( dependency( B.class ).named( left ) );
    assertNotSame( b, leftB );
    assertEquals( 2, leftB.as.length );
    C c = injector.resolve( dependency( C.class ).injectingInto(
        instance( left, raw( B.class ) ) ) );
    D d = injector.resolve( dependency( D.class ).injectingInto(
        instance( left, raw( B.class ) ) ) );
    assertEqualSets( new A[] { c, d }, leftB.as );
  }
View Full Code Here

  @Test
  public void thatMultipleOptionChoicesArePossible() {
    Options options = Options.STANDARD.chosen( Choices.A, Choices.D );
    Globals globals = Globals.STANDARD.options( options );
    Injector injector = Bootstrap.injector( RootBundle.class, globals );
    assertEqualSets( new String[] { "A", "D" }, injector.resolve( dependency( String[].class ) ) );
  }
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.