package com.atlassian.bitbucket.internal.integration.jira;

import com.atlassian.bitbucket.integration.jira.JiraIssue;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.TypeSafeMatcher;

public class JiraIssueMatcher extends TypeSafeMatcher<JiraIssue> {

    private final JiraIssue expected;

    private JiraIssueMatcher(JiraIssue expected) {
        this.expected = expected;
    }

    @Factory
    public static JiraIssueMatcher issue(String key, String url) {
        return new JiraIssueMatcher(SimpleJiraIssue.maybeCreate(key, url));
    }

    @Override
    public void describeTo(Description description) {
        description.appendText("a JIRA issue with key").appendValue(expected.getKey())
                .appendText("and url").appendValue(expected.getUrl());
    }

    @Override
    protected boolean matchesSafely(JiraIssue actual) {
        return StringUtils.equals(actual.getKey(), expected.getKey())
                && StringUtils.equals(actual.getUrl(), expected.getUrl());
    }
}
