Package se.jbee.inject

Examples of se.jbee.inject.Injector.resolve()


  @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

 
  @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

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

    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

    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

  }

  @Test
  public void thatEachClassGetsTheLoggerWithItsCanonicalName() {
    Injector injector = Bootstrap.injector( LoggerBindsBundle.class );
    Foo foo = injector.resolve( dependency( Foo.class ) );
    assertThat( foo.logger, sameInstance( Logger.getLogger( Foo.class.getCanonicalName() ) ) );
  }
}
View Full Code Here

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.