|
Java example source code file (TransitiveDependencyVisitorTest.java)
The TransitiveDependencyVisitorTest.java Java example source code/** * Copyright (C) 2008 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.inject.grapher; import com.google.common.collect.ImmutableSet; import com.google.inject.AbstractModule; import com.google.inject.Binding; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Key; import com.google.inject.Module; import com.google.inject.Provider; import com.google.inject.TypeLiteral; import com.google.inject.name.Names; import com.google.inject.spi.ConstructorBinding; import com.google.inject.spi.ConvertedConstantBinding; import com.google.inject.spi.Dependency; import com.google.inject.spi.HasDependencies; import com.google.inject.spi.InstanceBinding; import com.google.inject.spi.LinkedKeyBinding; import com.google.inject.spi.ProviderBinding; import com.google.inject.spi.ProviderInstanceBinding; import com.google.inject.spi.ProviderKeyBinding; import junit.framework.TestCase; import java.util.Collection; import java.util.Set; /** * Tests for {@link TransitiveDependencyVisitor}. * * @author phopkins@gmail.com (Pete Hopkins) */ public class TransitiveDependencyVisitorTest extends TestCase { private TransitiveDependencyVisitor visitor; @Override protected void setUp() throws Exception { super.setUp(); visitor = new TransitiveDependencyVisitor(); } public void testVisitConstructor() { Binding<?> binding = getBinding(Key.get(ConstructedClass.class)); Collection<Key>> dependencies = visitor.visit((ConstructorBinding>) binding); assertDependencies(dependencies, Key.get(A.class), Key.get(B.class), Key.get(C.class), Key.get(D.class)); } public void testVisitConvertedConstant() { Binding<?> binding = getBinding(Key.get(Integer.class, Names.named("number")), new ConvertedConstantModule()); Collection<Key>> dependencies = visitor.visit( (ConvertedConstantBinding<?>) binding); assertDependencies(dependencies, Key.get(String.class, Names.named("number"))); } public void testVisitInstance() { Binding<?> binding = getBinding(Key.get(ConstructedClass.class), new InstanceModule()); Collection<Key>> dependencies = visitor.visit( (InstanceBinding<?>) binding); // Dependencies will only be on the field- and method-injected classes. assertDependencies(dependencies, Key.get(A.class), Key.get(D.class)); } public void testVisitInstance_instanceHasDependencies() { Binding<?> binding = getBinding(Key.get(Interface.class), new HasDependenciesModule()); Collection<Key>> dependencies = visitor.visit( (InstanceBinding<?>) binding); // Dependencies should only be on the stated // HasDependencies#getDependencies() values assertDependencies(dependencies, Key.get(G.class)); } public void testVisitLinkedKey() { Binding<?> binding = getBinding(Key.get(Interface.class), new LinkedKeyModule()); Collection<Key>> dependencies = visitor.visit((LinkedKeyBinding>) binding); // Dependency should be to the class this interface is bound to. assertDependencies(dependencies, Key.get(ConstructedClass.class)); } public void testVisitProviderBinding() { Binding<?> binding = getBinding(Key.get(new TypeLiteral Other Java examples (source code examples)Here is a short list of links related to this Java TransitiveDependencyVisitorTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.