Package se.jbee.inject

Examples of se.jbee.inject.Injector


    assertTrue( v.valid( input ) ); // PERMISSIVE
  }

  @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( 42, "42" );
    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

    }
  }

  @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

    assertOptionResolvedToValue( null, "on-generic" );
  }

  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

  }

  @SuppressWarnings ( "unchecked" )
  @Test
  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 );
  }
View Full Code Here

  }

  @Test ( expected = NoSuchResourceException.class )
  public void thatAllConstructorParameterTypesCanBeMadeRequired() {
    Macro<?> required = new RequiredConstructorParametersMacro();
    Injector injector = injectorWithMacro( MacroBindsModule.class, required );
    assertNull( injector ); // just to fail in case we get here
  }
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

  }

  @SuppressWarnings ( "unchecked" )
  @Test
  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 ) );
    ServiceMethod<Number, Integer> negate = injector.resolve( dependency2 );
    assertNotNull( mul2 );
    assertThat( negate.invoke( 3 ), is( -3 ) );
    assertThat( mul2.invoke( 4 ), is( 11 ) );
  }
View Full Code Here

  }

  @Test
  public void thatMultipleNamedElementsCanBeBound() {
    Injector injector = Bootstrap.injector( MultibindBindsBundle.class );
    Integer[] foos = injector.resolve( dependency( Integer[].class ).named( foo ) );
    assertEqualSets( new Integer[] { 2, 3 }, foos );
    Integer[] bars = injector.resolve( dependency( Integer[].class ).named( bar ) );
    assertEqualSets( new Integer[] { 4, 5 }, bars );
    Integer[] defaults = injector.resolve( dependency( Integer[].class ).named( Name.DEFAULT ) );
    assertEqualSets( new Integer[] { 1, 11 }, defaults );
    Integer[] anys = injector.resolve( dependency( Integer[].class ).named( Name.ANY ) );
    assertEqualSets( new Integer[] { 1, 2, 3, 4, 5, 11 }, anys );
  }
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.