package hudson.plugins.git;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

class GitLockFailedExceptionTest {

    @Test
    void throwsGitLockFailedException() {
        GitLockFailedException lockFailed = assertThrows(GitLockFailedException.class, () -> {
            throw new GitLockFailedException();
        });
        assertThat(lockFailed.getMessage(), is(nullValue()));
    }

    @Test
    void throwsGitLockFailedExceptionWithMessage() {
        String message = "My local exception message";
        GitLockFailedException lockFailed = assertThrows(GitLockFailedException.class, () -> {
            throw new GitLockFailedException(message);
        });
        assertThat(lockFailed.getMessage(), is(message));
    }

    @Test
    void throwsGitLockFailedExceptionWithCause() {
        String message = "My git exception message";
        GitException e = new GitException(message);
        GitLockFailedException lockFailed = assertThrows(GitLockFailedException.class, () -> {
            throw new GitLockFailedException(e);
        });
        assertThat(lockFailed.getMessage(), is("hudson.plugins.git.GitException: " + message));
    }

    @Test
    void throwsGitLockFailedExceptionWithCauseAndMessage() {
        String message = "My git exception message";
        GitException e = new GitException(message);
        String lockMessage = "My lock message that is not part of the GitException";
        GitLockFailedException lockFailed = assertThrows(GitLockFailedException.class, () -> {
            throw new GitLockFailedException(lockMessage, e);
        });
        assertThat(lockFailed.getMessage(), is(lockMessage));
    }
}
