Search in sources :

Example 1 with Exposed

use of com.google.inject.Exposed in project guice by google.

the class ModuleAnnotatedMethodScannerTest method testPrivateModuleInheritScanner_usingPrivateModule.

public void testPrivateModuleInheritScanner_usingPrivateModule() {
    Injector injector = Guice.createInjector(NamedMunger.module(), new PrivateModule() {

        @Override
        protected void configure() {
        }

        @Exposed
        @TestProvides
        @Named("foo")
        String foo() {
            return "foo";
        }
    });
    assertMungedBinding(injector, String.class, "foo", "foo");
}
Also used : Exposed(com.google.inject.Exposed) Named(com.google.inject.name.Named) Injector(com.google.inject.Injector) PrivateModule(com.google.inject.PrivateModule)

Example 2 with Exposed

use of com.google.inject.Exposed in project guice by google.

the class ModuleAnnotatedMethodScannerTest method testPrivateModuleScannersDontImpactSiblings_usingPrivateModule.

public void testPrivateModuleScannersDontImpactSiblings_usingPrivateModule() {
    Injector injector = Guice.createInjector(new PrivateModule() {

        @Override
        protected void configure() {
            install(NamedMunger.module());
        }

        @Exposed
        @TestProvides
        @Named("foo")
        String foo() {
            return "foo";
        }
    }, new PrivateModule() {

        @Override
        protected void configure() {
        }

        // ignored! (because the scanner doesn't run over this module)
        @Exposed
        @TestProvides
        @Named("foo")
        String foo() {
            return "foo";
        }
    });
    assertMungedBinding(injector, String.class, "foo", "foo");
}
Also used : Exposed(com.google.inject.Exposed) Named(com.google.inject.name.Named) Injector(com.google.inject.Injector) PrivateModule(com.google.inject.PrivateModule)

Example 3 with Exposed

use of com.google.inject.Exposed in project guice by google.

the class ModuleAnnotatedMethodScannerTest method scannerSourceForPrivateModule.

@Test
public void scannerSourceForPrivateModule() {
    Module module = new AbstractModule() {

        @Override
        protected void configure() {
            install(new PrivateModule() {

                @Override
                protected void configure() {
                }

                @Exposed
                @TestProvides
                @Foo
                String privateString() {
                    return "bar";
                }
            });
        }
    };
    TestScanner scanner = new TestScanner(TestProvides.class);
    Injector injector = Guice.createInjector(module, scannerModule(scanner));
    assertThat(getSourceScanner(injector.getBinding(Key.get(String.class, Foo.class)))).isEqualTo(scanner);
}
Also used : Exposed(com.google.inject.Exposed) Injector(com.google.inject.Injector) Module(com.google.inject.Module) PrivateModule(com.google.inject.PrivateModule) ProviderMethodsModule(com.google.inject.internal.ProviderMethodsModule) AbstractModule(com.google.inject.AbstractModule) PrivateModule(com.google.inject.PrivateModule) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 4 with Exposed

use of com.google.inject.Exposed in project guice by google.

the class ModuleAnnotatedMethodScannerTest method privateModuleScannersDontImpactSiblings_usingPrivateModule.

@Test
public void privateModuleScannersDontImpactSiblings_usingPrivateModule() {
    Injector injector = Guice.createInjector(new PrivateModule() {

        @Override
        protected void configure() {
            install(scannerModule(new NamedMunger()));
        }

        @Exposed
        @TestProvides
        @Named("foo")
        String foo() {
            return "foo";
        }
    }, new PrivateModule() {

        @Override
        protected void configure() {
        }

        // ignored! (because the scanner doesn't run over this module)
        @Exposed
        @TestProvides
        @Named("foo")
        String foo() {
            return "foo";
        }
    });
    assertMungedBinding(injector, String.class, "foo", "foo");
}
Also used : Exposed(com.google.inject.Exposed) Named(com.google.inject.name.Named) Injector(com.google.inject.Injector) PrivateModule(com.google.inject.PrivateModule) Test(org.junit.Test)

Example 5 with Exposed

use of com.google.inject.Exposed in project guice by google.

the class ModuleAnnotatedMethodScannerTest method privateModuleInheritsScanner_scannerInstalledAfterPrivateModule.

@Test
public void privateModuleInheritsScanner_scannerInstalledAfterPrivateModule() {
    Injector injector = Guice.createInjector(new PrivateModule() {

        @Override
        protected void configure() {
        }

        @Exposed
        @TestProvides
        @Named("foo")
        String foo() {
            return "foo";
        }
    }, // Scanner installed after private module.
    scannerModule(new NamedMunger()));
    assertMungedBinding(injector, String.class, "foo", "foo");
}
Also used : Exposed(com.google.inject.Exposed) Named(com.google.inject.name.Named) Injector(com.google.inject.Injector) PrivateModule(com.google.inject.PrivateModule) Test(org.junit.Test)

Aggregations

Exposed (com.google.inject.Exposed)7 Injector (com.google.inject.Injector)6 PrivateModule (com.google.inject.PrivateModule)6 Named (com.google.inject.name.Named)5 Test (org.junit.Test)4 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 ProviderMethodsModule (com.google.inject.internal.ProviderMethodsModule)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 AssetRepository (org.lanternpowered.server.asset.AssetRepository)1 LanternAssetManager (org.lanternpowered.server.asset.LanternAssetManager)1 AssetRepositoryJsonDeserializer (org.lanternpowered.server.asset.json.AssetRepositoryJsonDeserializer)1