Search in sources :

Example 1 with Pop3MailClient

use of com.thoughtworks.go.utils.Pop3MailClient in project gocd by gocd.

the class Pop3Matchers method emailCount.

public static TypeSafeMatcher<Pop3MailClient> emailCount(final String subject, int count) {
    return new TypeSafeMatcher<Pop3MailClient>() {

        private String errorMessage = "";

        public boolean matchesSafely(Pop3MailClient client) {
            try {
                Message message = client.findMessageWithSubject(subject);
                boolean b = message != null;
                if (b) {
                    errorMessage = "No message";
                }
                return b;
            } catch (Exception e) {
                errorMessage = e.getMessage();
                return false;
            }
        }

        public void describeTo(Description description) {
            description.appendText(String.format("Expected to find message with subject [%s], but got error: %s", subject, errorMessage));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) Pop3MailClient(com.thoughtworks.go.utils.Pop3MailClient) Message(javax.mail.Message)

Example 2 with Pop3MailClient

use of com.thoughtworks.go.utils.Pop3MailClient in project gocd by gocd.

the class EmailMatchers method emailSubjectContains.

public static TypeSafeMatcher<Pop3MailClient> emailSubjectContains(final String subject) {
    return new TypeSafeMatcher<Pop3MailClient>() {

        private String errorMessage = "";

        public boolean matchesSafely(Pop3MailClient client) {
            try {
                Message message = client.findMessageWithSubject(subject);
                boolean found = message != null;
                if (!found) {
                    errorMessage = "No message";
                }
                return found;
            } catch (Exception e) {
                errorMessage = e.getMessage();
                return false;
            }
        }

        public void describeTo(Description description) {
            description.appendText(String.format("Expected to find message with subject [%s], but got error: %s", subject, errorMessage));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) Pop3MailClient(com.thoughtworks.go.utils.Pop3MailClient) Message(javax.mail.Message)

Aggregations

Pop3MailClient (com.thoughtworks.go.utils.Pop3MailClient)2 Message (javax.mail.Message)2 Description (org.hamcrest.Description)2 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)2