Tabnine Logo
ScopeImpl
Code IndexAdd Tabnine to your IDE (free)

How to use
ScopeImpl
in
toothpick

Best Java code snippets using toothpick.ScopeImpl (Showing top 20 results out of 315)

origin: stephanenicolas/toothpick

@Test
public void testEqualsAndHashCode_shouldReturnFalse_whenNodeHasDifferentName() {
 //GIVEN
 Scope scope = new ScopeImpl("foo");
 Scope scope2 = new ScopeImpl("bar");
 //WHEN
 boolean equals = scope.equals(scope2);
 int hashScope = scope.hashCode();
 int hashScope2 = scope2.hashCode();
 //THEN
 assertThat(equals, is(false));
 assertThat(hashScope, not(is(hashScope2)));
}
origin: stephanenicolas/toothpick

@Test
public void installOverrideModules_shouldNotInstallOverrideBindings_whenCalledWithoutTestModules() {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("");
 scope.installTestModules();
 scope.installModules(new ProdModule());
 //WHEN
 Foo instance = scope.getInstance(Foo.class);
 //THEN
 assertThat(instance, notNullValue());
}
origin: stephanenicolas/toothpick

@Test(expected = RuntimeException.class)
public void testLookup_shouldFail_whenNotFindingABindingForANamedProvider() {
 //GIVEN
 //WHEN
 new ScopeImpl("").lookupProvider(Foo.class, "Bar");
 //THEN
 fail("Should throw an exception");
}
origin: stephanenicolas/toothpick

@Override
public <T> T getInstance(Class<T> clazz, String name) {
 crashIfClosed();
 ConfigurationHolder.configuration.checkCyclesStart(clazz, name);
 T t;
 try {
  t = lookupProvider(clazz, name).get(this);
 } finally {
  ConfigurationHolder.configuration.checkCyclesEnd(clazz, name);
 }
 return t;
}
origin: stephanenicolas/toothpick

@Test(expected = IllegalStateException.class)
public void getInstance_shouldFail_whenScopeIsClosed() {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("");
 //WHEN
 scope.close();
 scope.getInstance(Foo.class);
 //THEN
}
origin: stephanenicolas/toothpick

@Test(expected = IllegalStateException.class)
public void getProvider_shouldFail_whenScopeIsClosed() {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("");
 //WHEN
 scope.close();
 scope.getProvider(Foo.class);
 //THEN
}
origin: stephanenicolas/toothpick

 throw new IllegalArgumentException("TP can't get an instance of a null class.");
InternalProviderImpl<? extends T> scopedProvider = getBoundProvider(clazz, bindingName);
if (scopedProvider != null) {
 return scopedProvider;
 Scope parentScope = iterator.next();
 ScopeImpl parentScopeImpl = (ScopeImpl) parentScope;
 InternalProviderImpl<? extends T> parentScopedProvider = parentScopeImpl.getBoundProvider(clazz, bindingName);
 if (parentScopedProvider != null) {
  return parentScopedProvider;
   + "in scope %s and its parents %s", clazz.getName(), bindingName, getName(), getParentScopesNames()));
InternalProviderImpl unScopedProviderInPool = getUnBoundProvider(clazz, null);
if (unScopedProviderInPool != null) {
 return unScopedProviderInPool;
 return targetScopeImpl.installScopedProvider(clazz, null, newProvider, false);
} else {
 return installUnBoundProvider(clazz, null, newProvider);
origin: stephanenicolas/toothpick

private void installModule(boolean isTestModule, Module module) {
 for (Binding binding : module.getBindingSet()) {
  if (binding == null) {
   throw new IllegalStateException("A module can't have a null binding : " + module);
  }
  Class clazz = binding.getKey();
  String bindingName = binding.getName();
  try {
   if (isTestModule || getBoundProvider(clazz, bindingName) == null) {
    InternalProviderImpl provider = toProvider(binding);
    if (binding.isCreatingInstancesInScope()) {
     installScopedProvider(clazz, bindingName, (ScopedProviderImpl) provider, isTestModule);
    } else {
     installBoundProvider(clazz, bindingName, provider, isTestModule);
    }
   }
  } catch (Exception e) {
   throw new IllegalBindingException(format("Binding %s couldn't be installed", bindingName), e);
  }
 }
}
origin: stephanenicolas/toothpick

@Test
public void testToString() {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("root");
 scope.installModules(new TestModule1());
 ScopeImpl childScope = new ScopeImpl("child");
 scope.addChild(childScope);
 //WHEN
 childScope.getInstance(Bar.class);
 String dump = scope.toString();
 //THEN
 Pattern expected = Pattern.compile("root:\\d+.*"
   + "Providers: \\[toothpick.Scope,toothpick.data.Foo\\].*"
   + "\\\\---child:\\d+.*"
   + "Providers:.*\\[toothpick.Scope\\].*"
   + "Unbound providers: \\[toothpick.data.Bar\\].*", Pattern.DOTALL);
 assertThat(dump, MatchesPattern.matchesPattern(expected));
}
origin: stephanenicolas/toothpick

@Test(expected = IllegalStateException.class)
public void getLazy_shouldFail_whenScopeIsClosed() {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("");
 //WHEN
 scope.close();
 scope.getLazy(Foo.class);
 //THEN
}
origin: stephanenicolas/toothpick

@Test(expected = NoFactoryFoundException.class)
public void reset_shouldResetBoundProviders_andFlagTheTestModuleToFalse() throws Exception {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("root");
 scope.installTestModules(new Module() { {
  bind(IFoo.class).to(Foo.class);
 } });
 //WHEN
 scope.reset();
 //THEN
 scope.installTestModules(); // Should not crash
 scope.getInstance(IFoo.class); // Should crash as we don't have the binding for IFoo anymore
}
origin: stephanenicolas/toothpick

@Test
public void reset_shouldRebindScope() throws Exception {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("root");
 //WHEN
 scope.reset();
 //THEN
 assertThat(scope.getInstance(Scope.class), notNullValue());
}
origin: stephanenicolas/toothpick

@Test(expected = IllegalStateException.class)
public void installModules_shouldThrowAnException_whenModuleHasANullBinding() {
 //GIVEN
 ScopeImpl scope = new ScopeImpl("");
 //WHEN
 scope.installModules(new NullBindingModule());
 //THEN
 fail("Should throw an exception.");
}
origin: stephanenicolas/toothpick

@Test(expected = IllegalStateException.class)
public void testToBinding_shouldFail_whenAddingANullBinding() {
 //GIVEN
 //WHEN
 new ScopeImpl("").toProvider(null);
 //THEN
}
origin: com.github.stephanenicolas/toothpick-runtime

@Override
public <T> Provider<T> getProvider(Class<T> clazz) {
 InternalProviderImpl<? extends T> provider = lookupProvider(clazz, null);
 return new ThreadSafeProviderImpl<>(this, provider, false);
}
origin: stephanenicolas/toothpick

@Override
public void installModules(Module... modules) {
 installModules(false, modules);
}
origin: stephanenicolas/toothpick

/**
 * Obtains the provider of the class {@code clazz} and name {@code bindingName}, if any. The returned provider
 * will belong to the pool of unbound providers. It can be {@code null} if there is no such provider.
 *
 * @param clazz the class for which to obtain the unbound provider.
 * @param bindingName the name, possibly {@code null}, for which to obtain the unbound provider.
 * @param <T> the type of {@code clazz}.
 * @return the unbound provider for class {@code clazz} and {@code bindingName}. Returns {@code null} is there
 * is no such unbound provider.
 */
private <T> InternalProviderImpl<? extends T> getUnBoundProvider(Class<T> clazz, String bindingName) {
 return getInternalProvider(clazz, bindingName, false);
}
origin: stephanenicolas/toothpick

@Test(expected = IllegalStateException.class)
public void installTestModules_shoudFailToInstallTestsBindingsAgain_whenCalledTwice() {
 //GIVEN
 Foo testFoo = new Foo();
 Foo testFoo2 = new Foo();
 ScopeImpl scope = new ScopeImpl("");
 scope.installTestModules(new TestModule(testFoo));
 //WHEN
 scope.installTestModules(new TestModule(testFoo2));
 //THEN
 fail("Should throw an exception");
}
origin: stephanenicolas/toothpick

 return createInternalProvider(this,
   binding.getKey(),
   false,
   false);
case CLASS:
 return createInternalProvider(this,
   binding.getImplementationClass(),
   false,
 return createInternalProvider(this,
   binding.getProviderClass(),
   true,
origin: stephanenicolas/toothpick

@Override
public <T> Lazy<T> getLazy(Class<T> clazz) {
 return getLazy(clazz, null);
}
toothpickScopeImpl

Javadoc

A note on concurrency :

  • all operations related to the scope tree are synchronized on the Toothpick class.
  • all operations related to a scope's content (binding & providers) are synchronized on the key (class) of the binding/injection.
  • all providers provided by the public API (including Lazy) should return a thread safe provider (done) but internally, we can live with a non synchronized provider.
All operations on the scope itself are non thread-safe. They must be used via the Toothpick class or must be synchronized using the Toothpick class if used concurrently.

Most used methods

  • <init>
  • installModules
  • lookupProvider
    The core of Toothpick internals : the provider lookup. It will look for a scoped provider, bubbling
  • toProvider
  • createInternalProvider
  • getBoundProvider
    Obtains the provider of the class clazz and name bindingName, if any. The returned provider will be
  • getInstance
  • getInternalProvider
    Obtains the provider of the class clazz and name bindingName. The returned provider can either be bo
  • getLazy
  • getName
  • getProvider
  • getRootScope
  • getProvider,
  • getRootScope,
  • getUnBoundProvider,
  • installBoundProvider,
  • installInternalProvider,
  • installModule,
  • installNamedProvider,
  • installScopedProvider,
  • installUnBoundProvider,
  • installUnNamedProvider

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSystemService (Context)
  • setScale (BigDecimal)
  • getExternalFilesDir (Context)
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • JFileChooser (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now