public Search saveForUser(Search search, SearchUser searchUser) {
        this.executionGuard.check(search, searchUser::canReadStream);

        final Optional<Search> previous = Optional.ofNullable(search.id()).flatMap(dbService::get);
        if (!searchUser.isAdmin() && !previous.map(searchUser::owns).orElse(true)) {
            throw new PermissionException("Unable to update search with id <" + search.id() + ">, already exists and user is not permitted to overwrite it.");
        }

        return dbService.save(search.withOwner(searchUser.username()));
    }
@Test
    public void saveAddsOwnerToSearch() {
        final Search search = mockSearchWithOwner(null);
        final SearchUser searchUser = mock(SearchUser.class);
        when(searchUser.username()).thenReturn("eberhard");
        when(searchUser.isAdmin()).thenReturn(true);

        sut.saveForUser(search, searchUser);

        final ArgumentCaptor<Search> savedCaptor = ArgumentCaptor.forClass(Search.class);
        verify(dbService, times(1)).save(savedCaptor.capture());

        final Search result = savedCaptor.getValue();

        assertThat(result.owner()).contains("eberhard");
    }