int port = TestUtil.getNonPrivilegedPort();
new Thread(new MockSpamd(port)).start();
SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage(MockSpamd.GTUBE)));
SpamAssassinHandler handler = new SpamAssassinHandler();
handler.setSpamdHost(SPAMD_HOST);
handler.setSpamdPort(port);
handler.setSpamdRejectionHits(2000.0);
HookResult response = handler.onMessage(session, mockedMail);
assertEquals("Email was not rejected", response.getResult(), HookReturnCode.DECLINED);
assertEquals("email was spam", mockedMail.getAttribute(
SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "YES");
assertNotNull("spam hits", mockedMail.getAttribute(