Permalink
Browse files

factory - added test denoting circular dependency detection error rep…

…orted to the user
  • Loading branch information...
fcamblor committed Aug 28, 2017
1 parent 0e4188d commit 682fb8a59c3b2b566c3dbe1a5c0781edb12a1d4a
Showing with 35 additions and 2 deletions.
  1. +35 −2 restx-factory/src/test/java/restx/factory/FactoryTest.java
@@ -189,6 +189,34 @@ public void should_fail_with_missing_deps() throws Exception {
}
}
@Test
public void should_fail_with_circular_dependencies() throws Exception {
Factory factory = Factory.builder()
.addMachine(failingSingleDepMachine("test5", "test4"))
.addMachine(failingSingleDepMachine("test4", "test3"))
.addMachine(failingSingleDepMachine("test3", "test2"))
.addMachine(failingSingleDepMachine("test2", "test1"))
.addMachine(failingSingleDepMachine("test1", "test4"))
.build();
try {
factory.queryByName(Name.of(String.class, "test5")).findOne();
fail("should raise exception when asking for a component with circular dependency");
} catch (IllegalStateException e) {
assertThat(e)
.hasMessage(
"Circular dependency detected : \n" +
"-> Name{name='test4', clazz=java.lang.String[]}\n" +
" -> Name{name='test3', clazz=java.lang.String[]}\n" +
" -> Name{name='test2', clazz=java.lang.String[]}\n" +
" -> Name{name='test1', clazz=java.lang.String[]}\n" +
" -> Name{name='test4', clazz=java.lang.String[]}\n" +
"\n" +
"Please, fix this as current RestX DI can't handle cycles.")
;
}
}
@Test
public void should_fail_with_similar_components() throws Exception {
SingleNameFactoryMachine<String> machine = machineWithMissingDependency();
@@ -587,11 +615,16 @@ protected String doNewComponent(SatisfiedBOM satisfiedBOM) {
}
private SingleNameFactoryMachine<String> machineWithMissingDependency() {
return failingSingleDepMachine("test", "missing");
}
private SingleNameFactoryMachine<String> failingSingleDepMachine(final String name, final String depName) {
return new SingleNameFactoryMachine<>(
0, new StdMachineEngine<String>(Name.of(String.class, "test"), BoundlessComponentBox.FACTORY) {
0, new StdMachineEngine<String>(Name.of(String.class, name), BoundlessComponentBox.FACTORY) {
@Override
public BillOfMaterials getBillOfMaterial() {
return BillOfMaterials.of(Factory.Query.byName(Name.of(String.class, "missing")));
return BillOfMaterials.of(Factory.Query.byName(Name.of(String.class, depName)));
}
@Override

0 comments on commit 682fb8a

Please sign in to comment.