Пример #1
0
  @Test
  public void testCircularDependenciesThrowsCircularDependencyException() {
    final String moduleA =
        ""
            + "import org.picocontainer.testmodel.*;\n"
            + "import org.picocontainer.modules.*;\n"
            + "import static org.picocontainer.modules.Importer.importModule;\n"
            + "\n"
            + "importModule(\"moduleC\");\n"
            + "\n"
            + "pico = parent.makeChildContainer();\n"
            + "pico.addComponent(Touchable, SimpleTouchable);\n"
            + "\n"
            + "def publisher = new Publisher(pico, parent)\n"
            + "publisher.publish(Touchable)";

    final String moduleB =
        ""
            + "import org.picocontainer.testmodel.*;\n"
            + "import org.picocontainer.modules.*;\n"
            + "import static org.picocontainer.modules.Importer.importModule;\n"
            + "pico = parent.makeChildContainer();\n"
            + "\n"
            + "importModule(\"moduleA\");\n"
            + "\n"
            + "pico.addComponent(DependsOnTouchable);\n"
            + "\n"
            + "def publisher = new Publisher(pico, parent)\n"
            + "publisher.publish(DependsOnTouchable)";

    final String moduleC =
        ""
            + "import org.picocontainer.testmodel.*;\n"
            + "import org.picocontainer.modules.*;\n"
            + "import static org.picocontainer.modules.Importer.importModule;\n"
            + "pico = parent.makeChildContainer();\n"
            + "\n"
            + "importModule(\"moduleB\");\n"
            + "\n"
            + "pico.addComponent(DependsOnTouchable);\n"
            + "\n"
            + "def publisher = new Publisher(pico, parent)\n"
            + "publisher.publish(DependsOnTouchable)";

    moduleFolder.addModule("moduleA", moduleA);
    moduleFolder.addModule("moduleB", moduleB);
    moduleFolder.addModule("moduleC", moduleB);

    try {
      PicoContainer pico = moduleSystem.deploy().getPico();
      fail("Should have thrown CircularDependencyException, instead got: " + pico);
    } catch (CircularDependencyException e) {
      assertNotNull(e.getMessage());
    }
  }
Пример #2
0
  @Test
  public void testCrossModuleDependenciesArePossibleWithImports() {
    final String moduleA =
        ""
            + "import org.picocontainer.testmodel.*;\n"
            + "import org.picocontainer.modules.*;\n"
            + "pico = parent.makeChildContainer();\n"
            + "pico.addComponent(Touchable, SimpleTouchable);\n"
            + "\n"
            + "def publisher = new Publisher(pico, parent)\n"
            + "publisher.publish(Touchable)";

    final String moduleB =
        ""
            + "import org.picocontainer.testmodel.*;\n"
            + "import org.picocontainer.modules.*;\n"
            + "import static org.picocontainer.modules.Importer.importModule;\n"
            + "pico = parent.makeChildContainer();\n"
            + "\n"
            + "importModule(\"moduleA\");\n"
            + "\n"
            + "pico.addComponent(DependsOnTouchable);\n"
            + "\n"
            + "def publisher = new Publisher(pico, parent)\n"
            + "publisher.publish(DependsOnTouchable)";

    moduleFolder.addModule("moduleA", moduleA);
    moduleFolder.addModule("moduleB", moduleB);

    PicoContainer pico = moduleSystem.deploy().getPico();
    DependsOnTouchable depends = pico.getComponent(DependsOnTouchable.class);
    assertNotNull(depends);
  }