Package com.google.inject

Examples of com.google.inject.ProvisionException


        {
            return new URL( value );
        }
        catch ( final MalformedURLException e )
        {
            throw new ProvisionException( e.toString() );
        }
    }
View Full Code Here


    static class StringProvider
        implements DeferredProvider<String>
    {
        public String get()
        {
            throw new ProvisionException( "OOPS" );
        }
View Full Code Here

    static class OpaqueProvider
        implements Provider<String>
    {
        public String get()
        {
            throw new ProvisionException( "OOPS" );
        }
View Full Code Here

                    bind( C.class ).toProvider( new LoadedClass<C>( CImpl.class ).asProvider() );
                    bind( CImpl.class ).toProvider( new Provider<CImpl>()
                    {
                        public CImpl get()
                        {
                            throw new ProvisionException( "Broken Provider" );
                        }
                    } );
                }
            } ).getInstance( C.class );

            fail( "Expected ProvisionException" );
        }
        catch ( final ProvisionException e )
        {
        }

        try
        {
            Guice.createInjector( new AbstractModule()
            {
                @Override
                protected void configure()
                {
                    bind( C.class ).toProvider( new LoadedClass<C>( CImpl.class ).asProvider() );
                    bind( CImpl.class ).toProvider( new Provider<CImpl>()
                    {
                        public CImpl get()
                        {
                            throw new LinkageError( "Broken Provider" );
                        }
                    } );
                }
            } ).getInstance( C.class );

            fail( "Expected LinkageError" );
        }
        catch ( final LinkageError e )
        {
        }

        try
        {
            Guice.createInjector( new AbstractModule()
            {
                @Override
                protected void configure()
                {
                    bind( C.class ).toProvider( new LoadedClass<C>( CImpl.class ).asProvider() );
                    bind( CImpl.class ).toProvider( new Provider<CImpl>()
                    {
                        public CImpl get()
                        {
                            throw new IllegalArgumentException( new IllegalStateException( new ThreadDeath() ) );
                        }
                    } );
                }
            } ).getInstance( C.class );

            fail( "Expected ThreadDeath" );
        }
        catch ( final ThreadDeath e )
        {
        }

        final ClassSpace space = new URLClassSpace( C.class.getClassLoader(), null );
        try
        {
            Guice.createInjector( new AbstractModule()
            {
                @Override
                protected void configure()
                {
                    bind( C.class ).toProvider( new NamedClass<C>( space, CImpl.class.getName() ).asProvider() );
                    bind( CImpl.class ).toProvider( new Provider<CImpl>()
                    {
                        public CImpl get()
                        {
                            throw new ProvisionException( "Broken Provider" );
                        }
                    } );
                }
            } ).getInstance( C.class );
View Full Code Here

            H2EmbeddedDataSourceConfig config = injector.getInstance(Key.get(H2EmbeddedDataSourceConfig.class, annotation));
            try {
                return new H2EmbeddedDataSource(config);
            }
            catch (Exception e) {
                throw new ProvisionException("Error creating a H2EmbeddedDataSource", e);
            }
        }
View Full Code Here

   }

   public void testGetCause() {
      AuthorizationException aex = createMock(AuthorizationException.class);
      Message message = new Message(ImmutableList.of(), "test", aex);
      ProvisionException pex = new ProvisionException(ImmutableSet.of(message));
      assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), aex);
   }
View Full Code Here

   }

   public void testGetFirstThrowableOfTypeInner() {
      AuthorizationException aex = createMock(AuthorizationException.class);
      Message message = new Message(ImmutableList.of(), "test", aex);
      ProvisionException pex = new ProvisionException(ImmutableSet.of(message));
      assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), aex);
   }
View Full Code Here

   }

   public void testGetFirstThrowableOfTypeFail() {
      TimeoutException aex = createMock(TimeoutException.class);
      Message message = new Message(ImmutableList.of(), "test", aex);
      ProvisionException pex = new ProvisionException(ImmutableSet.of(message));
      assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null);
   }
View Full Code Here

      assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null);
   }

   public void testGetFirstThrowableOfTypeWhenCauseIsNull() {
      Message message = new Message(ImmutableList.of(), "test", null);
      ProvisionException pex = new ProvisionException(ImmutableSet.of(message));
      assertEquals(getFirstThrowableOfType(pex, AuthorizationException.class), null);
   }
View Full Code Here

   @Test(expectedExceptions = AuthorizationException.class)
   public void testPropagateProvisionExceptionAuthorizationException() throws Throwable {
      Exception e = new AuthorizationException();
      propagateIfPossible(
            new ProvisionException(ImmutableSet.of(new Message(ImmutableList.of(), "Error in custom provider", e))),
            ImmutableSet.<TypeToken<? extends Throwable>> of());
   }
View Full Code Here

TOP

Related Classes of com.google.inject.ProvisionException

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.