class SW360MetaDataUpdater {

    public void createProject(String projectName, String projectVersion, Collection<SW360Release> releases) {
        Optional<String> projectId =
                projectClientAdapter.getProjectByNameAndVersion(projectName, projectVersion)
                        .map(SW360HalResource::getId);

        String id = projectId.orElseGet(() ->
                projectClientAdapter.createProject(prepareNewProject(projectName, projectVersion)).getId());
        projectClientAdapter.addSW360ReleasesToSW360Project(id, releases);
    }

}

class SW360MetaDataUpdaterTest {

    private static final String TEST_FILE_CONTENT;
    private static final String TEST_FILE_SHA1;
    private static final String RELEASE_NAME;
    @Rule
    public TemporaryFolder folder;
    private SW360MetaDataUpdater metaDataUpdater;
    private final SW360Connection connection;
    private final SW360ProjectClientAdapter projectClientAdapter;
    private final SW360LicenseClientAdapter licenseClientAdapter;
    private final SW360ReleaseClientAdapter releaseClientAdapter;

    @Test
    public void testCreateProjectWithProjectPresent() {

        final String projectName = "projectName";
        final String projectVersion = "projectVersion";
        final String projectId = "12345";
        SW360Project project = new SW360Project();
        project.getLinks().setSelf(new Self("https://sw360.org/projects/" + projectId));
        when(projectClientAdapter.getProjectByNameAndVersion(projectName, projectVersion))
                .thenReturn(Optional.of(project));

        metaDataUpdater.createProject(projectName, projectVersion, Collections.emptySet());

        verify(projectClientAdapter, never()).createProject(any());
        verify(projectClientAdapter, times(1)).addSW360ReleasesToSW360Project(projectId, Collections.emptySet());
    }

}