Package se.jbee.inject

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


  }

  @Test
  public void thatReconfigurationIsProvidedToAnotherImplementation() {
    Injector injector = Bootstrap.injector( ConfigurationDependentBindsBundle.class );
    Configuration config = injector.resolve( dependency( Configuration.class ) );
    Provider<Validator> v = injector.resolve( dependency( providerTypeOf( Validator.class ) ) );
    String input = "input";
    assertTrue( v.provide().valid( input ) );
    config.setValidationStrength( ValidationStrength.STRICT );
    assertFalse( v.provide().valid( input ) );
View Full Code Here


  @Test
  public void thatReconfigurationIsProvidedToAnotherImplementation() {
    Injector injector = Bootstrap.injector( ConfigurationDependentBindsBundle.class );
    Configuration config = injector.resolve( dependency( Configuration.class ) );
    Provider<Validator> v = injector.resolve( dependency( providerTypeOf( Validator.class ) ) );
    String input = "input";
    assertTrue( v.provide().valid( input ) );
    config.setValidationStrength( ValidationStrength.STRICT );
    assertFalse( v.provide().valid( input ) );
    config.setValidationStrength( ValidationStrength.PERMISSIVE );
View Full Code Here

    assertConfigNumberResolvedToStringEnding( 123, "undefined" ); // equal to null
  }

  private static void assertConfigNumberResolvedToStringEnding( Integer configValue, String ending ) {
    Injector injector = Bootstrap.injector( ConfigurationDependentBindsModule3.class );
    Configuration config = injector.resolve( dependency( Configuration.class ) );
    config.setNumber( configValue );
    String v = injector.resolve( dependency( String.class ) );
    assertTrue( v.endsWith( ending ) );
  }
}
View Full Code Here

  private static void assertConfigNumberResolvedToStringEnding( Integer configValue, String ending ) {
    Injector injector = Bootstrap.injector( ConfigurationDependentBindsModule3.class );
    Configuration config = injector.resolve( dependency( Configuration.class ) );
    config.setNumber( configValue );
    String v = injector.resolve( dependency( String.class ) );
    assertTrue( v.endsWith( ending ) );
  }
}
View Full Code Here

  }

  @Test
  public void thatDependencyParameterIsUnderstood() {
    Injector resolver = Bootstrap.injector( DependencyParameterBindsBundle.class );
    LoggerInspector inspector = resolver.resolve( dependency( LoggerInspector.class ) );
    assertThat( inspector.logger,
        sameInstance( Logger.getLogger( BinderModule.class.getCanonicalName() ) ) );
  }
}
View Full Code Here

  private static void assertOptionResolvedToValue( Machine actualOption, String expected ) {
    Options options = Options.STANDARD.chosen( actualOption );
    Injector injector = Bootstrap.injector( ModularBindsBundle.class,
        Globals.STANDARD.options( options ) );
    String[] actual = injector.resolve( dependency( String[].class ) );
    assertThat( actual, is( new String[] { expected } ) );
  }
}
View Full Code Here

  public void thatServiceCanBeResolvedWhenHavingJustOneGeneric() {
    Injector injector = Bootstrap.injector( CommandBindsModule.class );
    @SuppressWarnings ( "rawtypes" )
    Dependency<Command> dependency = dependency( raw( Command.class ).parametized(
        Integer.class ) );
    Command<Integer> square = injector.resolve( dependency );
    assertThat( square.calc( 3 ), is( 9L ) );
  }
}
View Full Code Here

  @Test
  public void thatBindingsCanJustBeCounted() {
    CountMacro count = new CountMacro();
    Injector injector = injectorWithMacro( MacroBindsModule.class, count );
    assertEquals( 6, count.expands );
    assertEquals( 0, injector.resolve( Dependency.dependency( Injectron[].class ) ).length );
  }

  private static Injector injectorWithMacro( Class<? extends Bundle> root, Macro<?> macro ) {
    return Bootstrap.injector( root,
        Bindings.bindings( Macros.DEFAULT.use( macro ), Inspect.DEFAULT ), Globals.STANDARD );
View Full Code Here

  }

  @Test
  public void thatCustomInitialisationCanBeAdded() {
    Injector injector = injectorWithMacro( MacroBindsModule.class, new InitialisationMacro() );
    assertEquals( "answer", injector.resolve( dependency( Bar.class ) ).s );
  }
}
View Full Code Here

  public void test() {
    Injector injector = Bootstrap.injector( ServiceBindsModule.class );
    @SuppressWarnings ( "rawtypes" )
    Dependency<ServiceMethod> dependency = dependency( raw( ServiceMethod.class ).parametized(
        Integer.class, Integer.class ) );
    ServiceMethod<Integer, Integer> mul2 = injector.resolve( dependency );
    assertNotNull( mul2 );
    assertThat( mul2.invoke( 3 ), is( 9 ) );
    @SuppressWarnings ( "rawtypes" )
    Dependency<ServiceMethod> dependency2 = dependency( raw( ServiceMethod.class ).parametized(
        Number.class, Integer.class ) );
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.