public static void mergeDependencies(final Dependency dependency, final Dependency relatedDependency,
            final Set<Dependency> dependenciesToRemove) {
        synchronized (DEPENDENCY_LOCK) {
            LOGGER.debug("Merging '{}' into '{}'", relatedDependency.getFilePath(), dependency.getFilePath());
            dependency.addRelatedDependency(relatedDependency);
            relatedDependency.getEvidence(EvidenceType.VENDOR).forEach((e) -> dependency.addEvidence(EvidenceType.VENDOR, e));
            relatedDependency.getEvidence(EvidenceType.PRODUCT).forEach((e) -> dependency.addEvidence(EvidenceType.PRODUCT, e));
            relatedDependency.getEvidence(EvidenceType.VERSION).forEach((e) -> dependency.addEvidence(EvidenceType.VERSION, e));

            relatedDependency.getRelatedDependencies()
                    .forEach(dependency::addRelatedDependency);
            relatedDependency.clearRelatedDependencies();
            dependency.addAllProjectReferences(relatedDependency.getProjectReferences());
            if (dependenciesToRemove != null) {
                dependenciesToRemove.add(relatedDependency);
            }
        }
    }
@Test
    public void testMergeDependencies() {
        Dependency dependency = new Dependency(true);
        dependency.setName("main");
        dependency.addEvidence(EvidenceType.VENDOR, "test", "vendor", "main", Confidence.HIGHEST);
        dependency.addEvidence(EvidenceType.PRODUCT, "test", "product", "main", Confidence.HIGHEST);
        dependency.addEvidence(EvidenceType.VERSION, "test", "version", "1.0", Confidence.HIGHEST);
        Dependency relatedDependency = new Dependency(true);
        relatedDependency.addEvidence(EvidenceType.VENDOR, "test", "vendor", "related", Confidence.HIGHEST);
        relatedDependency.addEvidence(EvidenceType.PRODUCT, "test", "product", "related", Confidence.HIGHEST);
        relatedDependency.addEvidence(EvidenceType.VERSION, "test", "version", "1.0", Confidence.HIGHEST);
        relatedDependency.setName("related");
        relatedDependency.addProjectReference("related");
        Set<Dependency> dependenciesToRemove = new HashSet<>();
        DependencyMergingAnalyzer.mergeDependencies(dependency, relatedDependency, dependenciesToRemove);
        assertTrue(dependenciesToRemove.contains(relatedDependency));
        assertEquals(2, dependency.getEvidence(EvidenceType.VENDOR).size());
        assertEquals(2, dependency.getEvidence(EvidenceType.PRODUCT).size());
        assertEquals(1, dependency.getEvidence(EvidenceType.VERSION).size());
        assertEquals(1, dependency.getRelatedDependencies().size());
        assertEquals(0, relatedDependency.getRelatedDependencies().size());
    }