@SuppressWarnings("deprecation")
    @Test
    void require_that_injected_component_is_reused_even_when_dependent_component_is_changed() {
        Function<String, ComponentGraph> buildGraph = config -> {
            ComponentGraph graph = new ComponentGraph();

            String configId = "componentTakingConfigAndComponent";
            ComponentNode rootComponent = mockComponentNode(ComponentTakingConfigAndComponent.class, "root_component", configId);

            ComponentNode injectedComponent = mockComponentNode(SimpleComponent.class, "injected_component");

            rootComponent.inject(injectedComponent);

            graph.add(rootComponent);
            graph.add(injectedComponent);

            graph.complete();
            graph.setAvailableConfigs(Map.of(new ConfigKey<>(TestConfig.class, configId),
                    ConfigGetter.getConfig(TestConfig.class, "raw: stringVal \"" + config + "\"")));

            return graph;
        };

        ComponentGraph oldGraph = buildGraph.apply("oldGraph");
        SimpleComponent oldInjectedComponent = getComponent(oldGraph, SimpleComponent.class);
        ComponentTakingConfigAndComponent oldDependentComponent = getComponent(oldGraph, ComponentTakingConfigAndComponent.class);

        ComponentGraph newGraph = buildGraph.apply("newGraph");
        newGraph.reuseNodes(oldGraph);
        SimpleComponent newInjectedComponent = getComponent(newGraph, SimpleComponent.class);
        ComponentTakingConfigAndComponent newDependentComponent = getComponent(newGraph, ComponentTakingConfigAndComponent.class);

        assertNotSame(newDependentComponent, oldDependentComponent);
        assertSame(newInjectedComponent, oldInjectedComponent);
    }
@author gjoranv
@author Tony Vaagenes
@author ollivir
container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ReuseComponentsTest.java