    @Test
    public void testInvalidLocalDependency() throws MavenEmbedderException, ProjectBuildingException, ComponentLookupException, SettingsBuildingException, InvalidRepositoryException {

        final MavenExecutionRequestPopulator mavenExecutionRequestPopulator =  mock(MavenExecutionRequestPopulator.class);
        final Logger logger =  mock(Logger.class);
        final RepositorySystem repositorySystem = mock(RepositorySystem.class);
        final ArtifactRepository artifactRepository = mock(ArtifactRepository.class);

        final SettingsBuilder settingsBuilder =  mock(SettingsBuilder.class);
        final SettingsBuildingResult settingsBuildingResult = mock(SettingsBuildingResult.class);
        final ProjectBuilder projectBuilderMock =  mock(ProjectBuilder.class);
        final DependencyResolutionResult drr = mock(DependencyResolutionResult.class);
        final ProjectBuildingResult projectBuildingResult =  mock(ProjectBuildingResult.class);
        final ArtifactDescriptorException exception = mock(ArtifactDescriptorException.class);
        final ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();

        final ArtifactDescriptorResult result = new ArtifactDescriptorResult(request);
        final Artifact artifactResult = mock(Artifact .class);

        final List<Exception> list = singletonList(exception);

        request.setArtifact(artifactResult);
        result.setArtifact(artifactResult);

        doReturn(settingsBuilder).when(componentProviderMocked).lookup(SettingsBuilder.class);
        doReturn(settingsBuildingResult).when(settingsBuilder).build(any(SettingsBuildingRequest.class));
        when(settingsBuildingResult.getEffectiveSettings()).thenReturn(mock(Settings.class));
        when(componentProviderMocked.getSystemClassLoader()).thenReturn(getClass().getClassLoader());


        doReturn(artifactRepository).when(repositorySystem).createLocalRepository(any(File.class));

        doReturn(new File("").toPath().toString()).when(artifactRepository).getBasedir();

        doReturn(repositorySystem).when(componentProviderMocked).lookup(RepositorySystem.class);

        doReturn(projectBuilderMock).when(componentProviderMocked).lookup(ProjectBuilder.class);

        doReturn(logger).when(componentProviderMocked).lookup(Logger.class);
        doReturn(mavenExecutionRequestPopulator).when(componentProviderMocked).lookup(MavenExecutionRequestPopulator.class);

        doReturn(projectBuildingResult).when(projectBuilderMock).build(any(ModelSource.class), any(ProjectBuildingRequest.class));
        when(projectBuildingResult.getDependencyResolutionResult()).thenReturn(drr);
        when(projectBuildingResult.getDependencyResolutionResult()).thenReturn(drr);
        when(drr.getCollectionErrors()).thenReturn(list);
        when(exception.getResult()).thenReturn(result);

        boolean[] didExecuteTryRemoveLocalArtifact = {false};
        final MavenRequest mavenRequest = createMavenRequest(null);
        final MavenEmbedder embedder = new MavenEmbedderMock2( mavenRequest, null ) {
            void tryRemoveLocalArtifact(Artifact artifact) {
                didExecuteTryRemoveLocalArtifact[0] = true;
                assertEquals(artifact, artifactResult);
            }
        };

        assertThatThrownBy(() -> embedder.readProject(mock(InputStream.class)))
                .isInstanceOf(MavenEmbedderException.class);

        assertTrue(didExecuteTryRemoveLocalArtifact[0]);
    }