This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task; | |
public class AmbiguousImplementationException extends Exception { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task.testClasses; | |
public class ClassWithOneClassDependency { | |
public final ClassWithoutDependencies dependency; | |
public ClassWithOneClassDependency(ClassWithoutDependencies dependency) { | |
this.dependency = dependency; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task.testClasses; | |
public class ClassWithOneInterfaceDependency { | |
public final Interface dependency; | |
public ClassWithOneInterfaceDependency(Interface dependency) { | |
this.dependency = dependency; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task.testClasses; | |
public class ClassWithoutDependencies { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task; | |
public class ImplementationNotFoundException extends Exception { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task; | |
public class InjectionCycleException extends Exception { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task; | |
import java.util.List; | |
public class Injector { | |
/** | |
* Create and initialize object of `rootClassName` class using classes from | |
* `implementationClassNames` for concrete dependencies. | |
*/ | |
public static Object initialize(String rootClassName, List<String> implementationClassNames) throws Exception { | |
throw new IllegalStateException(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task.testClasses; | |
public interface Interface { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task.testClasses; | |
public class InterfaceImpl implements Interface { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package task; | |
import org.junit.Test; | |
import task.testClasses.ClassWithOneClassDependency; | |
import task.testClasses.ClassWithOneInterfaceDependency; | |
import task.testClasses.ClassWithoutDependencies; | |
import task.testClasses.InterfaceImpl; | |
import java.util.Collections; | |
import static org.junit.Assert.assertTrue; | |
public class TestInjector { | |
@Test | |
public void injectorShouldInitializeClassWithoutDependencies() | |
throws Exception { | |
Object object = Injector.initialize("task.testClasses.ClassWithoutDependencies", Collections.emptyList()); | |
assertTrue(object instanceof ClassWithoutDependencies); | |
} | |
@Test | |
public void injectorShouldInitializeClassWithOneClassDependency() | |
throws Exception { | |
Object object = Injector.initialize( | |
"task.testClasses.ClassWithOneClassDependency", | |
Collections.singletonList("task.testClasses.ClassWithoutDependencies") | |
); | |
assertTrue(object instanceof ClassWithOneClassDependency); | |
ClassWithOneClassDependency instance = (ClassWithOneClassDependency) object; | |
assertTrue(instance.dependency != null); | |
} | |
@Test | |
public void injectorShouldInitializeClassWithOneInterfaceDependency() | |
throws Exception { | |
Object object = Injector.initialize( | |
"task.testClasses.ClassWithOneInterfaceDependency", | |
Collections.singletonList("task.testClasses.InterfaceImpl") | |
); | |
assertTrue(object instanceof ClassWithOneInterfaceDependency); | |
ClassWithOneInterfaceDependency instance = (ClassWithOneInterfaceDependency) object; | |
assertTrue(instance.dependency instanceof InterfaceImpl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment