Class<? extends Annotation> annotationType = annotation.annotationType(); if (annotationType.isAnnotationPresent(javax.inject.Scope.class)) { if (!scope.isBoundToScopeAnnotation(annotationType)) { throw new IllegalBindingException(format("Class %s cannot be bound." + " It has a scope annotation: %s that is not supported by current scope: %s",
@Test public void testBindScopeAnnotation_shouldReturnFalse_whenNotBound() { //GIVEN Scope scope = Toothpick.openScope("root"); //WHEN boolean isBoundToScopeAnnotation = scope.isBoundToScopeAnnotation(CustomScope.class); //THEN assertThat(isBoundToScopeAnnotation, is(false)); }
@Test public void testCreateScope_shouldNotBindToScopeAnnotation_whenNameIsNotAScopeAnnotation() { //GIVEN Scope scope = new ScopeImpl(NotAScope.class); //WHEN boolean isBoundToScopeAnnotation = scope.isBoundToScopeAnnotation(CustomScope.class); //THEN assertThat(isBoundToScopeAnnotation, is(false)); }
@Test public void testBindScopeAnnotation_shouldReturnTrue_whenRootScopeAskedForSingleton() { //GIVEN Scope parentScope = Toothpick.openScope("root"); //WHEN boolean isBoundToSingleton = parentScope.isBoundToScopeAnnotation(Singleton.class); //THEN assertThat(isBoundToSingleton, is(true)); }
@Test public void testBindScopeAnnotation_shouldReturnFalse_whenNonRootScopeAskedForSingleton() { //GIVEN Scope childScope = Toothpick.openScopes("root", "child"); //WHEN boolean isBoundToSingleton = childScope.isBoundToScopeAnnotation(Singleton.class); //THEN assertThat(isBoundToSingleton, is(false)); }
@Test public void testCreateScope_shouldBindToScopeAnnotation_whenNameIsAScopeAnnotation() { //GIVEN Scope scope = new ScopeImpl(CustomScope.class); //WHEN boolean isBoundToScopeAnnotation = scope.isBoundToScopeAnnotation(CustomScope.class); //THEN assertThat(isBoundToScopeAnnotation, is(true)); }
@Test public void testBindScopeAnnotation_shouldReturnTrue_whenBound() { //GIVEN Scope parentScope = Toothpick.openScope("root"); parentScope.bindScopeAnnotation(CustomScope.class); //WHEN boolean isBoundToScopeAnnotation = parentScope.isBoundToScopeAnnotation(CustomScope.class); //THEN assertThat(isBoundToScopeAnnotation, is(true)); }
Class<? extends Annotation> annotationType = annotation.annotationType(); if (annotationType.isAnnotationPresent(javax.inject.Scope.class)) { if (!scope.isBoundToScopeAnnotation(annotationType)) { throw new IllegalBindingException(format("Class %s cannot be bound." + " It has a scope annotation: %s that is not supported by current scope: %s",