You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/08/03 08:52:17 UTC
[04/20] james-project git commit: JAMES-2506 Remove jmock from
protocols-imap
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
index bf1e169..a221e72 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
@@ -19,6 +19,15 @@
package org.apache.james.imap.processor;
+import static org.apache.james.imap.api.message.response.StatusResponse.Type.OK;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.only;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
import java.util.Optional;
import org.apache.james.core.quota.QuotaCount;
@@ -26,6 +35,7 @@ import org.apache.james.core.quota.QuotaSize;
import org.apache.james.imap.api.ImapCommand;
import org.apache.james.imap.api.ImapSessionState;
import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.message.response.ImapResponseMessage;
import org.apache.james.imap.api.message.response.StatusResponse;
import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.api.process.ImapSession;
@@ -44,11 +54,9 @@ import org.apache.james.mailbox.model.QuotaRoot;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.metrics.api.NoopMetricFactory;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
public class GetQuotaRootProcessorTest {
@@ -60,7 +68,6 @@ public class GetQuotaRootProcessorTest {
Quota.<QuotaSize>builder().used(QuotaSize.size(240)).computedLimit(QuotaSize.size(15890)).build();
private GetQuotaRootProcessor testee;
- private Mockery mockery;
private ImapSession mockedImapSession;
private ImapProcessor.Responder mockedResponder;
private QuotaManager mockedQuotaManager;
@@ -71,122 +78,86 @@ public class GetQuotaRootProcessorTest {
@Before
public void setUp() {
mailboxSession = new MockMailboxSession("plop");
- mockery = new JUnit4Mockery();
UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
- mockedImapSession = mockery.mock(ImapSession.class);
- mockedQuotaManager = mockery.mock(QuotaManager.class);
- mockedQuotaRootResolver = mockery.mock(QuotaRootResolver.class);
- mockedResponder = mockery.mock(ImapProcessor.Responder.class);
- mockedMailboxManager = mockery.mock(MailboxManager.class);
- testee = new GetQuotaRootProcessor(mockery.mock(ImapProcessor.class), mockedMailboxManager,
+ mockedImapSession = mock(ImapSession.class);
+ mockedQuotaManager = mock(QuotaManager.class);
+ mockedQuotaRootResolver = mock(QuotaRootResolver.class);
+ mockedResponder = mock(ImapProcessor.Responder.class);
+ mockedMailboxManager = mock(MailboxManager.class);
+ testee = new GetQuotaRootProcessor(mock(ImapProcessor.class), mockedMailboxManager,
statusResponseFactory, mockedQuotaRootResolver, mockedQuotaManager, new NoopMetricFactory());
}
@Test
public void processorShouldWorkOnValidRights() throws Exception {
GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest("A004", ImapCommand.anyStateCommand("Name"), "INBOX");
- Expectations expectations = new Expectations();
- expectations.allowing(mockedImapSession).getState();
- expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
-
- expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
- expectations.will(Expectations.returnValue(mailboxSession));
-
- expectations.allowing(mockedQuotaRootResolver).getQuotaRoot(expectations.with(MAILBOX_PATH));
- expectations.will(Expectations.returnValue(QUOTA_ROOT));
-
- expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
- expectations.with(MailboxACL.Right.Read), expectations.with(mailboxSession));
- expectations.will(Expectations.returnValue(true));
-
- expectations.allowing(mockedQuotaManager).getMessageQuota(expectations.with(QUOTA_ROOT));
- expectations.will(Expectations.returnValue(MESSAGE_QUOTA));
-
- expectations.allowing(mockedQuotaManager).getStorageQuota(expectations.with(QUOTA_ROOT));
- expectations.will(Expectations.returnValue(STORAGE_QUOTA));
-
- expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
-
- expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+ when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
+ when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+ when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+ when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession)).thenReturn(true);
+ when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenReturn(MESSAGE_QUOTA);
+ when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(STORAGE_QUOTA);
final QuotaResponse storageQuotaResponse = new QuotaResponse("STORAGE", "plop", STORAGE_QUOTA);
final QuotaResponse messageQuotaResponse = new QuotaResponse("MESSAGE", "plop", MESSAGE_QUOTA);
final QuotaRootResponse quotaRootResponse = new QuotaRootResponse("INBOX", "plop");
- mockery.checking(expectations);
+ testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
- mockery.checking(new Expectations() {
- {
- oneOf(mockedResponder).respond(with(equal(quotaRootResponse)));
- oneOf(mockedResponder).respond(with(equal(storageQuotaResponse)));
- oneOf(mockedResponder).respond(with(equal(messageQuotaResponse)));
- oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.OK)));
- }
- });
+ verify(mockedMailboxManager, times(1)).startProcessingRequest(mailboxSession);
+ verify(mockedMailboxManager, times(1)).endProcessingRequest(mailboxSession);
- testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+ ArgumentCaptor<ImapResponseMessage> responseCaptor = ArgumentCaptor.forClass(ImapResponseMessage.class);
+ verify(mockedResponder, times(4)).respond(responseCaptor.capture());
+
+ List<ImapResponseMessage> captorValues = responseCaptor.getAllValues();
+ assertThat(captorValues).contains(quotaRootResponse, storageQuotaResponse, messageQuotaResponse);
+ assertThat(captorValues).anySatisfy(response -> assertThat(response).isInstanceOfSatisfying(
+ StatusResponse.class,
+ st -> assertThat(st.getServerResponseType()).isEqualTo(OK)));
}
@Test
public void processorShouldWorkOnErrorThrown() throws Exception {
GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest("A004", ImapCommand.anyStateCommand("Name"), "INBOX");
- Expectations expectations = new Expectations();
-
- expectations.allowing(mockedImapSession).getState();
- expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
- expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
- expectations.will(Expectations.returnValue(mailboxSession));
-
- expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
- expectations.with(MailboxACL.Right.Read), expectations.with(mailboxSession));
- expectations.will(Expectations.throwException(new MailboxException()));
-
- expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
-
- expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+ when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
+ when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+ when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession)).thenThrow(new MailboxException());
+ testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
- mockery.checking(expectations);
+ verify(mockedMailboxManager).startProcessingRequest(mailboxSession);
+ verify(mockedMailboxManager).endProcessingRequest(mailboxSession);
- mockery.checking(new Expectations() {
- {
- oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.BAD)));
- }
- });
+ ArgumentCaptor<StatusResponse> responseCaptor = ArgumentCaptor.forClass(StatusResponse.class);
+ verify(mockedResponder, only()).respond(responseCaptor.capture());
- testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+ assertThat(responseCaptor.getValue())
+ .extracting(StatusResponse::getServerResponseType)
+ .containsOnlyOnce(StatusResponse.Type.BAD);
}
@Test
public void processorShouldWorkOnNonValidRights() throws Exception {
GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest("A004", ImapCommand.anyStateCommand("Name"), "INBOX");
- Expectations expectations = new Expectations();
- expectations.allowing(mockedImapSession).getState();
- expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
+ when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
+ when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+ when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession)).thenReturn(false);
- expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
- expectations.will(Expectations.returnValue(mailboxSession));
-
- expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
- expectations.with(MailboxACL.Right.Read), expectations.with(mailboxSession));
- expectations.will(Expectations.returnValue(false));
-
- expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
-
- expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+ testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
- mockery.checking(expectations);
+ verify(mockedMailboxManager).startProcessingRequest(mailboxSession);
+ verify(mockedMailboxManager).endProcessingRequest(mailboxSession);
- mockery.checking(new Expectations() {
- {
- oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.NO)));
- }
- });
+ ArgumentCaptor<StatusResponse> responseCaptor = ArgumentCaptor.forClass(StatusResponse.class);
+ verify(mockedResponder, only()).respond(responseCaptor.capture());
- testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+ assertThat(responseCaptor.getValue())
+ .extracting(StatusResponse::getServerResponseType)
+ .containsOnlyOnce(StatusResponse.Type.NO);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
index 67d7414..648d139 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
@@ -19,6 +19,12 @@
package org.apache.james.imap.processor;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -38,9 +44,6 @@ import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.SubscriptionManager;
import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.metrics.api.NoopMetricFactory;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Before;
import org.junit.Test;
@@ -90,45 +93,32 @@ public class LSubProcessorTest {
};
LSubProcessor processor;
-
ImapProcessor next;
-
SubscriptionManager manager;
-
ImapProcessor.Responder responder;
-
MailboxMetaData result;
-
ImapSession session;
-
MailboxSession mailboxSession;
-
StatusResponseFactory serverResponseFactory;
-
StatusResponse statusResponse;
-
Collection<String> subscriptions;
-
ImapCommand command;
-
private ImapProcessor.Responder responderImpl;
- private Mockery mockery = new JUnit4Mockery();
-
@Before
public void setUp() throws Exception {
subscriptions = new ArrayList<>();
- serverResponseFactory = mockery.mock(StatusResponseFactory.class);
- session = mockery.mock(ImapSession.class);
+ serverResponseFactory = mock(StatusResponseFactory.class);
+ session = mock(ImapSession.class);
command = ImapCommand.anyStateCommand("Command");
- next = mockery.mock(ImapProcessor.class);
- responder = mockery.mock(ImapProcessor.Responder.class);
- result = mockery.mock(MailboxMetaData.class);
- statusResponse = mockery.mock(StatusResponse.class);
+ next = mock(ImapProcessor.class);
+ responder = mock(ImapProcessor.Responder.class);
+ result = mock(MailboxMetaData.class);
+ statusResponse = mock(StatusResponse.class);
responderImpl = responder;
- manager = mockery. mock(SubscriptionManager.class);
- mailboxSession = mockery.mock(MailboxSession.class);
- processor = new LSubProcessor(next, mockery.mock(MailboxManager.class), manager, serverResponseFactory, new NoopMetricFactory());
+ manager = mock(SubscriptionManager.class);
+ mailboxSession = mock(MailboxSession.class);
+ processor = new LSubProcessor(next, mock(MailboxManager.class), manager, serverResponseFactory, new NoopMetricFactory());
}
@Test
@@ -140,23 +130,19 @@ public class LSubProcessorTest {
subscriptions.add(CHILD_ONE);
subscriptions.add(CHILD_TWO);
- mockery.checking(new Expectations() {{
- oneOf(mailboxSession).getUser(); will(returnValue(USER));
- oneOf(responder).respond(with(
- equal(new LSubResponse(CHILD_ONE, false, HIERARCHY_DELIMITER))));
- oneOf(responder).respond(with(
- equal(new LSubResponse(CHILD_TWO, false, HIERARCHY_DELIMITER))));
- }
- }
- );
-
+ when(mailboxSession.getUser()).thenReturn(USER);
+
expectSubscriptions();
- expectOk();
+ when(serverResponseFactory.taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
+ .thenReturn(statusResponse);
LsubRequest request = new LsubRequest(command, "", PARENT
+ HIERARCHY_DELIMITER + "%", TAG);
processor.doProcessRequest(request, session, TAG, command, responderImpl);
+ verify(responder).respond(new LSubResponse(CHILD_ONE, false, HIERARCHY_DELIMITER));
+ verify(responder).respond(new LSubResponse(CHILD_TWO, false, HIERARCHY_DELIMITER));
+ verify(responder).respond(statusResponse);
}
@Test
@@ -168,21 +154,18 @@ public class LSubProcessorTest {
subscriptions.add(CHILD_ONE);
subscriptions.add(CHILD_TWO);
- mockery.checking(new Expectations() {{
- oneOf(mailboxSession).getUser(); will(returnValue(USER));
- oneOf(responder).respond(with(
- equal(new LSubResponse(PARENT, true, HIERARCHY_DELIMITER))));
- }
- }
- );
+ when(mailboxSession.getUser()).thenReturn(USER);
expectSubscriptions();
- expectOk();
+ when(serverResponseFactory.taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
+ .thenReturn(statusResponse);
LsubRequest request = new LsubRequest(command, "", ROOT
+ HIERARCHY_DELIMITER + "%", TAG);
processor.doProcessRequest(request, session, TAG, command, responderImpl);
+ verify(responder).respond(new LSubResponse(PARENT, true, HIERARCHY_DELIMITER));
+ verify(responder).respond(statusResponse);
}
@Test
@@ -195,70 +178,43 @@ public class LSubProcessorTest {
subscriptions.add(CHILD_ONE);
subscriptions.add(CHILD_TWO);
- mockery.checking(new Expectations() {{
- oneOf(mailboxSession).getUser(); will(returnValue(USER));
- oneOf(responder).respond(with(
- equal(new LSubResponse(PARENT, false, HIERARCHY_DELIMITER))));
- }
- }
- );
+ when(mailboxSession.getUser()).thenReturn(USER);
expectSubscriptions();
- expectOk();
+ when(serverResponseFactory.taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
+ .thenReturn(statusResponse);
LsubRequest request = new LsubRequest(command, "", ROOT
+ HIERARCHY_DELIMITER + "%", TAG);
processor.doProcessRequest(request, session, TAG, command, responderImpl);
+ verify(responder).respond(new LSubResponse(PARENT, false, HIERARCHY_DELIMITER));
+ verify(responder).respond(statusResponse);
}
@Test
public void testSelectAll() throws Exception {
- mockery.checking(new Expectations() {{
- oneOf(mailboxSession).getUser(); will(returnValue(USER));
- oneOf(responder).respond(with(equal(
- new LSubResponse(MAILBOX_A, false, HIERARCHY_DELIMITER))));
- oneOf(responder).respond(with(equal(
- new LSubResponse(MAILBOX_B, false, HIERARCHY_DELIMITER))));
- oneOf(responder).respond(with(equal(
- new LSubResponse(MAILBOX_C, false, HIERARCHY_DELIMITER))));
- }
- }
- );
subscriptions.add(MAILBOX_A);
subscriptions.add(MAILBOX_B);
subscriptions.add(MAILBOX_C);
+ when(mailboxSession.getUser()).thenReturn(USER);
expectSubscriptions();
- expectOk();
+ when(serverResponseFactory.taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
+ .thenReturn(statusResponse);
LsubRequest request = new LsubRequest(command, "", "*", TAG);
processor.doProcessRequest(request, session, TAG, command, responderImpl);
- }
-
-
- private void expectOk() {
- mockery.checking(new Expectations() {{
- oneOf(serverResponseFactory).taggedOk(
- with(equal(TAG)),
- with(same(command)),
- with(equal(HumanReadableText.COMPLETED)));will(returnValue(statusResponse));
- oneOf(responder).respond(with(same(statusResponse)));
- }
- }
- );
+ verify(responder).respond(new LSubResponse(MAILBOX_A, false, HIERARCHY_DELIMITER));
+ verify(responder).respond(new LSubResponse(MAILBOX_B, false, HIERARCHY_DELIMITER));
+ verify(responder).respond(new LSubResponse(MAILBOX_C, false, HIERARCHY_DELIMITER));
+ verify(responder).respond(statusResponse);
}
private void expectSubscriptions() throws Exception {
- mockery.checking(new Expectations() {{
- exactly(2).of(session).getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY);
- will(returnValue(mailboxSession));
- allowing(mailboxSession).getPathDelimiter(); will(returnValue(HIERARCHY_DELIMITER));
- oneOf(mailboxSession).getUser(); will(returnValue(USER));
- oneOf(manager).subscriptions(with(same(mailboxSession)));will(returnValue(subscriptions));
- }
- }
- );
+ when(session.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+ when(mailboxSession.getPathDelimiter()).thenReturn(HIERARCHY_DELIMITER);
+ when(manager.subscriptions(mailboxSession)).thenReturn(subscriptions);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
index 0a6d718..fd9785b 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
@@ -236,7 +236,7 @@ public class MoveProcessorTest {
}
@Test
- public void processShouldNotHandleCopyRequests() throws Exception {
+ public void processShouldNotHandleCopyRequests() {
CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
testee.process(copyRequest, mockResponder, mockImapSession);
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
index 5ba4461..b6162e6 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
@@ -18,6 +18,14 @@
****************************************************************/
package org.apache.james.imap.processor;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -28,7 +36,6 @@ import org.apache.james.imap.api.ImapSessionState;
import org.apache.james.imap.api.ImapSessionUtils;
import org.apache.james.imap.api.display.HumanReadableText;
import org.apache.james.imap.api.message.response.StatusResponse;
-import org.apache.james.imap.api.message.response.StatusResponse.ResponseCode;
import org.apache.james.imap.api.message.response.StatusResponseFactory;
import org.apache.james.imap.api.process.ImapProcessor;
import org.apache.james.imap.api.process.ImapProcessor.Responder;
@@ -39,9 +46,6 @@ import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.metrics.api.NoopMetricFactory;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Before;
import org.junit.Test;
@@ -56,92 +60,74 @@ public class NamespaceProcessorTest {
StatusResponseFactory statusResponseStub;
ImapSession imapSessionStub;
MailboxSession mailboxSessionStub;
- String personalSpaceStub;
- String usersSpaceStub;
- String sharedSpaceStub;
NamespaceRequest namespaceRequest;
Collection<String> sharedSpaces;
MailboxManager mailboxManagerStub;
- Mockery mockery = new JUnit4Mockery();
-
+
@Before
public void setUp() throws Exception {
sharedSpaces = new ArrayList<>();
- statusResponseStub = mockery.mock(StatusResponseFactory.class);
- mailboxManagerStub = mockery.mock(MailboxManager.class);
- subject = new NamespaceProcessor(mockery.mock(ImapProcessor.class), mailboxManagerStub, statusResponseStub, new NoopMetricFactory());
- imapSessionStub = mockery.mock(ImapSession.class);
- mailboxSessionStub = mockery.mock(MailboxSession.class);
+ statusResponseStub = mock(StatusResponseFactory.class);
+ mailboxManagerStub = mock(MailboxManager.class);
+ subject = new NamespaceProcessor(mock(ImapProcessor.class), mailboxManagerStub, statusResponseStub, new NoopMetricFactory());
+ imapSessionStub = mock(ImapSession.class);
+ mailboxSessionStub = mock(MailboxSession.class);
namespaceRequest = new NamespaceRequest(ImapCommand.anyStateCommand("Name"), "TAG");
}
-
-
@Test
- public void testNamespaceResponseShouldContainPersonalAndUserSpaces() throws Exception {
- mockery.checking(new Expectations() {{
- allowing(imapSessionStub).supportMultipleNamespaces(); will(returnValue(true));
- allowing(imapSessionStub).getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY); will(returnValue(mailboxSessionStub));
- allowing(imapSessionStub).getAttribute(EnableProcessor.ENABLED_CAPABILITIES); will(returnValue(null));
- allowing(any(ImapSession.class)).method("setAttribute");
-
- allowing(mailboxSessionStub).getPersonalSpace(); will(returnValue(PERSONAL_PREFIX));
- allowing(mailboxSessionStub).getOtherUsersSpace(); will(returnValue(USERS_PREFIX));
- allowing(mailboxSessionStub).getSharedSpaces();will(returnValue(new ArrayList<String>()));
- allowing(mailboxSessionStub).getPathDelimiter();will(returnValue(MailboxConstants.DEFAULT_DELIMITER));
- allowing(imapSessionStub).getState();will(returnValue(ImapSessionState.AUTHENTICATED));
- allowing(statusResponseStub).taggedOk(
- with(any(String.class)), with(any(ImapCommand.class)),
- with(any(HumanReadableText.class)), with(any(ResponseCode.class))); will(returnValue(mockery.mock(StatusResponse.class)));
- ignoring(imapSessionStub);
- ignoring(mailboxSessionStub);
- ignoring(mailboxManagerStub);
- ignoring(statusResponseStub);
- }
- }
- );
-
+ public void testNamespaceResponseShouldContainPersonalAndUserSpaces() {
+ when(imapSessionStub.supportMultipleNamespaces()).thenReturn(true);
+ when(imapSessionStub.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSessionStub);
+ when(imapSessionStub.getAttribute(EnableProcessor.ENABLED_CAPABILITIES)).thenReturn(null);
+
+ when(mailboxSessionStub.getPersonalSpace()).thenReturn(PERSONAL_PREFIX);
+ when(mailboxSessionStub.getOtherUsersSpace()).thenReturn(USERS_PREFIX);
+ when(mailboxSessionStub.getSharedSpaces()).thenReturn(new ArrayList<>());
+ when(mailboxSessionStub.getPathDelimiter()).thenReturn(MailboxConstants.DEFAULT_DELIMITER);
+
+ when(imapSessionStub.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
+ when(statusResponseStub.taggedOk(anyString(), any(ImapCommand.class), any(HumanReadableText.class)))
+ .thenReturn(mock(StatusResponse.class));
+
final NamespaceResponse response = buildResponse(null);
-
- final Responder responderMock = expectResponse(response);
-
+ final Responder responderMock = mock(Responder.class);
+
subject.doProcess(namespaceRequest, responderMock, imapSessionStub);
+
+ verify(responderMock, times(1)).respond(response);
+ verify(responderMock, times(1)).respond(any(StatusResponse.class));
+ verifyNoMoreInteractions(responderMock);
}
@Test
- public void testNamespaceResponseShouldContainSharedSpaces() throws Exception {
- mockery.checking(new Expectations() {{
- allowing(imapSessionStub).supportMultipleNamespaces(); will(returnValue(true));
- allowing(imapSessionStub).getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY); will(returnValue(mailboxSessionStub));
- allowing(imapSessionStub).getAttribute(EnableProcessor.ENABLED_CAPABILITIES); will(returnValue(null));
- allowing(any(ImapSession.class)).method("setAttribute");
- allowing(mailboxSessionStub).getPersonalSpace(); will(returnValue(PERSONAL_PREFIX));
- allowing(mailboxSessionStub).getOtherUsersSpace(); will(returnValue(USERS_PREFIX));
- allowing(mailboxSessionStub).getSharedSpaces();will(returnValue(Arrays.asList(SHARED_PREFIX)));
- allowing(mailboxSessionStub).getPathDelimiter();will(returnValue(MailboxConstants.DEFAULT_DELIMITER));
- allowing(imapSessionStub).getState();will(returnValue(ImapSessionState.AUTHENTICATED));
- allowing(statusResponseStub).taggedOk(
- with(any(String.class)), with(any(ImapCommand.class)),
- with(any(HumanReadableText.class)), with(any(ResponseCode.class))); will(returnValue(mockery.mock(StatusResponse.class)));
- ignoring(imapSessionStub);
- ignoring(mailboxSessionStub);
- ignoring(mailboxManagerStub);
- ignoring(statusResponseStub);
- }
- }
- );
- this.sharedSpaces.add(sharedSpaceStub);
-
+ public void testNamespaceResponseShouldContainSharedSpaces() {
+ when(imapSessionStub.supportMultipleNamespaces()).thenReturn(true);
+ when(imapSessionStub.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSessionStub);
+ when(imapSessionStub.getAttribute(EnableProcessor.ENABLED_CAPABILITIES)).thenReturn(null);
+
+ when(mailboxSessionStub.getPersonalSpace()).thenReturn(PERSONAL_PREFIX);
+ when(mailboxSessionStub.getOtherUsersSpace()).thenReturn(USERS_PREFIX);
+ when(mailboxSessionStub.getSharedSpaces()).thenReturn(Arrays.asList(SHARED_PREFIX));
+ when(mailboxSessionStub.getPathDelimiter()).thenReturn(MailboxConstants.DEFAULT_DELIMITER);
+
+ when(imapSessionStub.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
+ when(statusResponseStub.taggedOk(anyString(), any(ImapCommand.class), any(HumanReadableText.class)))
+ .thenReturn(mock(StatusResponse.class));
final List<NamespaceResponse.Namespace> sharedSpaces = new ArrayList<>();
sharedSpaces.add(new NamespaceResponse.Namespace(SHARED_PREFIX, MailboxConstants.DEFAULT_DELIMITER));
final NamespaceResponse response = buildResponse(sharedSpaces);
- final Responder responderMock = expectResponse(response);
-
+ final Responder responderMock = mock(Responder.class);
+
subject.doProcess(namespaceRequest, responderMock, imapSessionStub);
+
+ verify(responderMock, times(1)).respond(response);
+ verify(responderMock, times(1)).respond(any(StatusResponse.class));
+ verifyNoMoreInteractions(responderMock);
}
private NamespaceResponse buildResponse(List<NamespaceResponse.Namespace> sharedSpaces) {
@@ -153,16 +139,5 @@ public class NamespaceProcessorTest {
return new NamespaceResponse(personalSpaces, otherUsersSpaces, sharedSpaces);
}
-
- private Responder expectResponse(final NamespaceResponse response) {
- final Responder responderMock = mockery.mock(Responder.class);
- mockery.checking(new Expectations() {{
- oneOf(responderMock).respond(with(equal(response)));
- oneOf(responderMock).respond(with(any(StatusResponse.class)));
- }
- }
- );
- return responderMock;
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
index 4e468a8..ccf2cb1 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
@@ -19,6 +19,12 @@
package org.apache.james.imap.processor;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
@@ -27,6 +33,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.TimeZone;
+
import javax.mail.Flags;
import javax.mail.Flags.Flag;
@@ -56,10 +63,7 @@ import org.apache.james.mailbox.model.SearchQuery.AddressType;
import org.apache.james.mailbox.model.SearchQuery.Criterion;
import org.apache.james.mailbox.model.SearchQuery.DateResolution;
import org.apache.james.metrics.api.NoopMetricFactory;
-
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -97,55 +101,42 @@ public class SearchProcessorTest {
private static final MailboxPath mailboxPath = new MailboxPath("namespace", "user", "name");
SearchProcessor processor;
-
ImapProcessor next;
-
ImapProcessor.Responder responder;
-
ImapSession session;
-
ImapCommand command;
-
StatusResponseFactory serverResponseFactory;
-
StatusResponse statusResponse;
-
MessageManager mailbox;
-
MailboxManager mailboxManager;
-
MailboxSession mailboxSession;
-
SelectedMailbox selectedMailbox;
- private Mockery mockery = new JUnit4Mockery();
-
@Before
public void setUp() throws Exception {
- serverResponseFactory = mockery.mock(StatusResponseFactory.class);
- session = mockery.mock(ImapSession.class);
+ serverResponseFactory = mock(StatusResponseFactory.class);
+ session = mock(ImapSession.class);
command = ImapCommand.anyStateCommand("Command");
- next = mockery.mock(ImapProcessor.class);
- responder = mockery.mock(ImapProcessor.Responder.class);
- statusResponse = mockery.mock(StatusResponse.class);
- mailbox = mockery.mock(MessageManager.class);
- mailboxManager = mockery.mock(MailboxManager.class);
- mailboxSession = mockery.mock(MailboxSession.class);
- selectedMailbox = mockery.mock(SelectedMailbox.class);
+ next = mock(ImapProcessor.class);
+ responder = mock(ImapProcessor.Responder.class);
+ statusResponse = mock(StatusResponse.class);
+ mailbox = mock(MessageManager.class);
+ mailboxManager = mock(MailboxManager.class);
+ mailboxSession = mock(MailboxSession.class);
+ selectedMailbox = mock(SelectedMailbox.class);
processor = new SearchProcessor(next, mailboxManager, serverResponseFactory, new NoopMetricFactory());
expectOk();
}
+ @After
+ public void afterEach() {
+ verifyCalls();
+ }
+
private void allowUnsolicitedResponses() {
- mockery.checking(new Expectations() {{
- atMost(1).of(session).getAttribute(
- with(equal(ImapSessionUtils.MAILBOX_USER_ATTRIBUTE_SESSION_KEY)));will(returnValue("user"));
- atMost(1).of(session).getAttribute(
- with(equal(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)));will(returnValue(mailboxSession));
- }
- }
- );
+ when(session.getAttribute(ImapSessionUtils.MAILBOX_USER_ATTRIBUTE_SESSION_KEY)).thenReturn("user");
+ when(session.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
}
@Test
@@ -153,14 +144,12 @@ public class SearchProcessorTest {
expectsGetSelectedMailbox();
final IdRange[] ids = { new IdRange(1, Long.MAX_VALUE) };
final SearchQuery.UidRange[] ranges = { new SearchQuery.UidRange(MessageUid.of(42), MessageUid.of(100)) };
- mockery.checking(new Expectations() {{
- allowing(selectedMailbox).existsCount();will(returnValue(100L));
- oneOf(selectedMailbox).uid(with(equal(1)));will(returnValue(Optional.of(MessageUid.of(42))));
- allowing(selectedMailbox).getFirstUid(); will(returnValue(Optional.of(MessageUid.of(1))));
- allowing(selectedMailbox).getLastUid(); will(returnValue(Optional.of(MessageUid.of(100))));
- }
- }
- );
+
+ when(selectedMailbox.existsCount()).thenReturn(100L);
+ when(selectedMailbox.uid(1)).thenReturn(Optional.of(MessageUid.of(42L)));
+ when(selectedMailbox.getFirstUid()).thenReturn(Optional.of(MessageUid.of(1L)));
+ when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(100L)));
+
allowUnsolicitedResponses();
check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));
}
@@ -170,15 +159,13 @@ public class SearchProcessorTest {
expectsGetSelectedMailbox();
final IdRange[] ids = { new IdRange(1, 5) };
final SearchQuery.UidRange[] ranges = { new SearchQuery.UidRange(MessageUid.of(42), MessageUid.of(1729)) };
- mockery.checking(new Expectations() {{
- allowing(selectedMailbox).existsCount();will(returnValue(2L));
- oneOf(selectedMailbox).uid(with(equal(1)));will(returnValue(Optional.of(MessageUid.of(42L))));
- oneOf(selectedMailbox).uid(with(equal(5)));will(returnValue(Optional.of(MessageUid.of(1729L))));
- allowing(selectedMailbox).getFirstUid(); will(returnValue(Optional.of(MessageUid.of(1L))));
- allowing(selectedMailbox).getLastUid(); will(returnValue(Optional.of(MessageUid.MAX_VALUE)));
- }
- }
- );
+
+ when(selectedMailbox.existsCount()).thenReturn(100L);
+ when(selectedMailbox.uid(1)).thenReturn(Optional.of(MessageUid.of(42L)));
+ when(selectedMailbox.uid(5)).thenReturn(Optional.of(MessageUid.of(1729L)));
+ when(selectedMailbox.getFirstUid()).thenReturn(Optional.of(MessageUid.of(1L)));
+ when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.MAX_VALUE));
+
allowUnsolicitedResponses();
check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));
}
@@ -188,12 +175,10 @@ public class SearchProcessorTest {
expectsGetSelectedMailbox();
final IdRange[] ids = { new IdRange(1) };
final SearchQuery.UidRange[] ranges = { new SearchQuery.UidRange(MessageUid.of(42)) };
- mockery.checking(new Expectations() {{
- allowing(selectedMailbox).existsCount();will(returnValue(1L));
- exactly(2).of(selectedMailbox).uid(with(equal(1)));will(returnValue(Optional.of(MessageUid.of(42L))));
- }
- }
- );
+
+ when(selectedMailbox.existsCount()).thenReturn(1L);
+ when(selectedMailbox.uid(1)).thenReturn(Optional.of(MessageUid.of(42L)));
+
allowUnsolicitedResponses();
check(SearchKey.buildSequenceSet(ids), SearchQuery.uid(ranges));
}
@@ -205,23 +190,15 @@ public class SearchProcessorTest {
}
private void expectsGetSelectedMailbox() throws Exception {
- mockery.checking(new Expectations() {{
- atMost(1).of(mailboxManager).getMailbox(with(equal(mailboxPath)), with(same(mailboxSession)));will(returnValue(mailbox));
- atMost(1).of(mailboxManager).getMailbox(with(equal(mailboxPath)), with(same(mailboxSession)));will(returnValue(mailbox));
- allowing(session).getSelected();will(returnValue(selectedMailbox));
- atMost(1).of(selectedMailbox).isRecentUidRemoved();will(returnValue(false));
- atLeast(1).of(selectedMailbox).isSizeChanged();will(returnValue(false));
- atLeast(1).of(selectedMailbox).getPath();will(returnValue(mailboxPath));
- atMost(1).of(selectedMailbox).flagUpdateUids();will(returnValue(Collections.EMPTY_LIST));
- atMost(1).of(selectedMailbox).resetEvents();
-
- oneOf(selectedMailbox).getRecent();will(returnValue(new ArrayList<MessageUid>()));
- }
- }
- );
+ when(mailboxManager.getMailbox(mailboxPath, mailboxSession)).thenReturn(mailbox, mailbox);
+ when(session.getSelected()).thenReturn(selectedMailbox);
+ when(selectedMailbox.isRecentUidRemoved()).thenReturn(false);
+ when(selectedMailbox.isSizeChanged()).thenReturn(false);
+ when(selectedMailbox.getPath()).thenReturn(mailboxPath);
+ when(selectedMailbox.flagUpdateUids()).thenReturn(Collections.EMPTY_LIST);
+ when(selectedMailbox.getRecent()).thenReturn(new ArrayList<>());
}
-
private Calendar getGMT() {
return Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.UK);
}
@@ -428,14 +405,11 @@ public class SearchProcessorTest {
@Test
public void testUID() throws Exception {
- mockery.checking(new Expectations() {{
- allowing(selectedMailbox).getFirstUid();will(returnValue(Optional.of(MessageUid.of(1))));
- allowing(selectedMailbox).getLastUid();will(returnValue(Optional.of(MessageUid.of(1048))));
- allowing(selectedMailbox).existsCount();will(returnValue(1L));
- }
- }
- );
- expectsGetSelectedMailbox();
+ when(selectedMailbox.getFirstUid()).thenReturn(Optional.of(MessageUid.of(1)));
+ when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(1048)));
+ when(selectedMailbox.existsCount()).thenReturn(1L);
+
+ expectsGetSelectedMailbox();
check(SearchKey.buildUidSet(IDS), SearchQuery.uid(RANGES));
}
@@ -486,37 +460,29 @@ public class SearchProcessorTest {
check(key, query);
}
- private void check(SearchKey key, final SearchQuery query) throws Exception {
- mockery.checking(new Expectations() {{
- allowing(session).getAttribute(
- with(equal(SearchProcessor.SEARCH_MODSEQ))); will(returnValue(null));
- allowing(session).setAttribute(SearchProcessor.SEARCH_MODSEQ, null);
- allowing(session).getAttribute(
- with(equal(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))); will(returnValue((MailboxSession) mailboxSession));
- oneOf(mailbox).search(
- with(equal(query)),
- with(equal(mailboxSession)));will(
- returnValue(new ArrayList<MessageUid>().iterator()));
- oneOf(responder).respond(with(equal(new SearchResponse(EMPTY, null))));
- allowing(selectedMailbox).getApplicableFlags(); will(returnValue(new Flags()));
- allowing(selectedMailbox).hasNewApplicableFlags(); will(returnValue(false));
-
- }
- }
- );
+ private void check(SearchKey key, final SearchQuery query) throws Exception {
+ when(session.getAttribute(SearchProcessor.SEARCH_MODSEQ)).thenReturn(null);
+ when(session.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+ when(mailbox.search(query, mailboxSession)).thenReturn(new ArrayList<MessageUid>().iterator());
+ when(selectedMailbox.getApplicableFlags()).thenReturn(new Flags());
+ when(selectedMailbox.hasNewApplicableFlags()).thenReturn(false);
+
SearchRequest message = new SearchRequest(command, new SearchOperation(key, new ArrayList<>()), false, TAG);
processor.doProcess(message, session, TAG, command, responder);
}
private void expectOk() {
- mockery.checking(new Expectations() {{
- oneOf(serverResponseFactory).taggedOk(
- with(equal(TAG)),
- with(same(command)),
- with(equal(HumanReadableText.COMPLETED)));will(returnValue(statusResponse));
- oneOf(responder).respond(with(same(statusResponse)));
- }
- }
- );
+ when(serverResponseFactory
+ .taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
+ .thenReturn(statusResponse);
+ }
+
+ private void verifyCalls() {
+ verify(selectedMailbox).resetEvents();
+
+ verify(session).setAttribute(SearchProcessor.SEARCH_MODSEQ, null);
+ verify(responder).respond(new SearchResponse(EMPTY, null));
+
+ verify(responder).respond(same(statusResponse));
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
index 91337c6..4f6340e 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
@@ -60,7 +60,7 @@ public class SetQuotaProcessorTest {
}
@Test
- public void processorShouldWorkOnNoRights() throws Exception {
+ public void processorShouldWorkOnNoRights() {
SetQuotaRequest setQuotaRequest = new SetQuotaRequest("A004", ImapCommand.anyStateCommand("Name"), "quotaRoot");
when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 0f797a7..87f7c76 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -119,7 +119,7 @@ public class MailboxEventAnalyserTest {
}
@Test
- public void testShouldBeNoSizeChangeOnOtherEvent() throws Exception {
+ public void testShouldBeNoSizeChangeOnOtherEvent() {
MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(MAILBOX_SESSION, MAILBOX_PATH) {};
testee.event(event);
@@ -128,13 +128,13 @@ public class MailboxEventAnalyserTest {
}
@Test
- public void testShouldBeNoSizeChangeOnAdded() throws Exception {
+ public void testShouldBeNoSizeChangeOnAdded() {
testee.event(new FakeMailboxListenerAdded(MAILBOX_SESSION, ImmutableList.of(MessageUid.of(11)), MAILBOX_PATH));
assertThat(testee.isSizeChanged()).isTrue();
}
@Test
- public void testShouldNoSizeChangeAfterReset() throws Exception {
+ public void testShouldNoSizeChangeAfterReset() {
testee.event(new FakeMailboxListenerAdded(MAILBOX_SESSION, ImmutableList.of(MessageUid.of(11)), MAILBOX_PATH));
testee.resetEvents();
@@ -142,7 +142,7 @@ public class MailboxEventAnalyserTest {
}
@Test
- public void testShouldNotSetUidWhenNoSystemFlagChange() throws Exception {
+ public void testShouldNotSetUidWhenNoSystemFlagChange() {
FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(MAILBOX_SESSION,
ImmutableList.of(MessageUid.of(90L)),
ImmutableList.of(UpdatedFlags.builder()
@@ -158,7 +158,7 @@ public class MailboxEventAnalyserTest {
}
@Test
- public void testShouldSetUidWhenSystemFlagChange() throws Exception {
+ public void testShouldSetUidWhenSystemFlagChange() {
MessageUid uid = MessageUid.of(900);
FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(OTHER_MAILBOX_SESSION,
@@ -176,7 +176,7 @@ public class MailboxEventAnalyserTest {
}
@Test
- public void testShouldClearFlagUidsUponReset() throws Exception {
+ public void testShouldClearFlagUidsUponReset() {
MessageUid uid = MessageUid.of(900);
SelectedMailboxImpl analyser = this.testee;
@@ -197,7 +197,7 @@ public class MailboxEventAnalyserTest {
}
@Test
- public void testShouldSetUidWhenSystemFlagChangeDifferentSessionInSilentMode() throws Exception {
+ public void testShouldSetUidWhenSystemFlagChangeDifferentSessionInSilentMode() {
MessageUid uid = MessageUid.of(900);
FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(OTHER_MAILBOX_SESSION,
@@ -217,7 +217,7 @@ public class MailboxEventAnalyserTest {
}
@Test
- public void testShouldNotSetUidWhenSystemFlagChangeSameSessionInSilentMode() throws Exception {
+ public void testShouldNotSetUidWhenSystemFlagChangeSameSessionInSilentMode() {
FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(MAILBOX_SESSION,
ImmutableList.of(MessageUid.of(345)),
ImmutableList.of(UpdatedFlags.builder()
@@ -235,7 +235,7 @@ public class MailboxEventAnalyserTest {
}
@Test
- public void testShouldNotSetUidWhenOnlyRecentFlagUpdated() throws Exception {
+ public void testShouldNotSetUidWhenOnlyRecentFlagUpdated() {
FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(MAILBOX_SESSION,
ImmutableList.of(MessageUid.of(886)),
ImmutableList.of(UpdatedFlags.builder()
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index 2e881cb..b640cba 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -50,7 +50,6 @@ import org.apache.james.mailbox.store.SimpleMessageMetaData;
import org.apache.james.mailbox.store.event.EventFactory;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -161,6 +160,6 @@ public class SelectedMailboxImplTest {
private void emitEvent(MailboxListener mailboxListener) {
TreeMap<MessageUid, MessageMetaData> result = new TreeMap<>();
result.put(EMITTED_EVENT_UID, new SimpleMessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId()));
- mailboxListener.event(new EventFactory().added(mock(MailboxSession.class), result, mailbox, ImmutableMap.<MessageUid, MailboxMessage>of()));
+ mailboxListener.event(new EventFactory().added(mock(MailboxSession.class), result, mailbox, ImmutableMap.of()));
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/MailboxMessageResultUtilsTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/MailboxMessageResultUtilsTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/MailboxMessageResultUtilsTest.java
index 182cd7e..54354b6 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/MailboxMessageResultUtilsTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/MailboxMessageResultUtilsTest.java
@@ -22,7 +22,6 @@ package org.apache.james.imap.processor.fetch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -71,7 +70,7 @@ public class MailboxMessageResultUtilsTest {
@Override
- public InputStream getInputStream() throws IOException {
+ public InputStream getInputStream() {
return null;
}
@@ -90,7 +89,7 @@ public class MailboxMessageResultUtilsTest {
}
@Test
- public void testGetAllContent() throws Exception {
+ public void testGetAllContent() {
List<MessageResult.Header> results = MessageResultUtils.getAll(headers.iterator());
assertEquals(3, results.size());
assertEquals(headerOne, results.get(0));
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/PartialFetchBodyElementTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/PartialFetchBodyElementTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/PartialFetchBodyElementTest.java
index 2848b80..0015c8b 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/PartialFetchBodyElementTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/fetch/PartialFetchBodyElementTest.java
@@ -20,11 +20,10 @@
package org.apache.james.imap.processor.fetch;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import org.apache.james.imap.message.response.FetchResponse.BodyElement;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Before;
import org.junit.Test;
@@ -34,105 +33,75 @@ public class PartialFetchBodyElementTest {
BodyElement mockBodyElement;
- private Mockery mockery = new JUnit4Mockery();
-
@Before
public void setUp() throws Exception {
- mockBodyElement = mockery.mock(BodyElement.class);
- mockery.checking(new Expectations() {{
- oneOf(mockBodyElement).getName();will(returnValue("Name"));
- }
- }
- );
+ mockBodyElement = mock(BodyElement.class);
+ when(mockBodyElement.getName()).thenReturn("Name");
}
@Test
public void testSizeShouldBeNumberOfOctetsWhenSizeMoreWhenStartIsZero()
throws Exception {
final long moreThanNumberOfOctets = NUMBER_OF_OCTETS + 1;
- PartialFetchBodyElement element = new PartialFetchBodyElement(
- mockBodyElement, 0, NUMBER_OF_OCTETS);
- mockery.checking(new Expectations() {{
- oneOf(mockBodyElement).size();will(returnValue(new Long(moreThanNumberOfOctets)));
- }
- }
- );
+ PartialFetchBodyElement element = new PartialFetchBodyElement(mockBodyElement, 0, NUMBER_OF_OCTETS);
+ when(mockBodyElement.size()).thenReturn(moreThanNumberOfOctets);
+
assertEquals(
- "Size is more than number of octets so should be number of octets",
- NUMBER_OF_OCTETS, element.size());
+ "Size is more than number of octets so should be number of octets",
+ NUMBER_OF_OCTETS, element.size());
}
@Test
public void testSizeShouldBeSizeWhenNumberOfOctetsMoreWhenStartIsZero()
throws Exception {
final long lessThanNumberOfOctets = NUMBER_OF_OCTETS - 1;
- PartialFetchBodyElement element = new PartialFetchBodyElement(
- mockBodyElement, 0, NUMBER_OF_OCTETS);
- mockery.checking(new Expectations() {{
- oneOf(mockBodyElement).size();will(returnValue(new Long(lessThanNumberOfOctets)));
- }
- }
- );
+ PartialFetchBodyElement element = new PartialFetchBodyElement(mockBodyElement, 0, NUMBER_OF_OCTETS);
+ when(mockBodyElement.size()).thenReturn(lessThanNumberOfOctets);
+
assertEquals("Size is less than number of octets so should be size",
- lessThanNumberOfOctets, element.size());
+ lessThanNumberOfOctets, element.size());
}
@Test
public void testWhenStartPlusNumberOfOctetsIsMoreThanSizeSizeShouldBeSizeMinusStart()
throws Exception {
final long size = 60;
- PartialFetchBodyElement element = new PartialFetchBodyElement(
- mockBodyElement, 10, NUMBER_OF_OCTETS);
- mockery.checking(new Expectations() {{
- oneOf(mockBodyElement).size();will(returnValue(new Long(size)));
- }
- }
- );
+ PartialFetchBodyElement element = new PartialFetchBodyElement(mockBodyElement, 10, NUMBER_OF_OCTETS);
+ when(mockBodyElement.size()).thenReturn(size);
+
assertEquals("Size is less than number of octets so should be size",
- 50, element.size());
+ 50, element.size());
}
@Test
public void testWhenStartPlusNumberOfOctetsIsLessThanSizeSizeShouldBeNumberOfOctetsMinusStart()
throws Exception {
final long size = 100;
- PartialFetchBodyElement element = new PartialFetchBodyElement(
- mockBodyElement, 10, NUMBER_OF_OCTETS);
- mockery.checking(new Expectations() {{
- oneOf(mockBodyElement).size();will(returnValue(new Long(size)));
- }
- }
- );
+ PartialFetchBodyElement element = new PartialFetchBodyElement(mockBodyElement, 10, NUMBER_OF_OCTETS);
+ when(mockBodyElement.size()).thenReturn(size);
+
assertEquals("Size is less than number of octets so should be size",
- 90, element.size());
+ 90, element.size());
}
@Test
public void testSizeShouldBeZeroWhenStartIsMoreThanSize() throws Exception {
final long size = 100;
- PartialFetchBodyElement element = new PartialFetchBodyElement(
- mockBodyElement, 1000, NUMBER_OF_OCTETS);
- mockery.checking(new Expectations() {{
- oneOf(mockBodyElement).size();will(returnValue(new Long(size)));
- }
- }
- );
+ PartialFetchBodyElement element = new PartialFetchBodyElement(mockBodyElement, 1000, NUMBER_OF_OCTETS);
+ when(mockBodyElement.size()).thenReturn(size);
+
assertEquals("Size is less than number of octets so should be size", 0,
- element.size());
+ element.size());
}
@Test
public void testSizeShouldBeNumberOfOctetsWhenStartMoreThanOctets()
throws Exception {
final long size = 2000;
- PartialFetchBodyElement element = new PartialFetchBodyElement(
- mockBodyElement, 1000, NUMBER_OF_OCTETS);
- mockery.checking(new Expectations() {{
- oneOf(mockBodyElement).size();will(returnValue(new Long(size)));
- }
- }
- );
+ PartialFetchBodyElement element = new PartialFetchBodyElement(mockBodyElement, 1000, NUMBER_OF_OCTETS);
+ when(mockBodyElement.size()).thenReturn(size);
+
assertEquals("Content size is less than start. Size should be zero.",
- NUMBER_OF_OCTETS, element.size());
+ NUMBER_OF_OCTETS, element.size());
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6373f39a/protocols/imap/src/test/java/org/apache/james/protocols/imap/utils/DecoderUtilsTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/protocols/imap/utils/DecoderUtilsTest.java b/protocols/imap/src/test/java/org/apache/james/protocols/imap/utils/DecoderUtilsTest.java
index 7693b32..108d9c0 100644
--- a/protocols/imap/src/test/java/org/apache/james/protocols/imap/utils/DecoderUtilsTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/protocols/imap/utils/DecoderUtilsTest.java
@@ -105,7 +105,7 @@ public class DecoderUtilsTest {
checkDateTime("123456789012345678901234567");
}
- private void checkDateTime(String datetime) throws Exception {
+ private void checkDateTime(String datetime) {
try {
DecoderUtils.decodeDateTime(datetime);
fail("Bad date-time" + datetime);
@@ -325,7 +325,7 @@ public class DecoderUtilsTest {
}
@Test
- public void testRejectBogusMonths() throws Exception {
+ public void testRejectBogusMonths() {
checkReject('N', 'O', 'C');
checkReject('A', 'N', 'T');
checkReject('Z', 'Z', 'Z');
@@ -357,7 +357,7 @@ public class DecoderUtilsTest {
}
@Test
- public void testRejectBogusYear() throws Exception {
+ public void testRejectBogusYear() {
checkRejectYear('D', '0', '2', '3');
checkRejectYear('1', 'A', '2', '3');
checkRejectYear('1', '5', 'B', '3');
@@ -432,7 +432,7 @@ public class DecoderUtilsTest {
}
@Test
- public void testBogusZones() throws Exception {
+ public void testBogusZones() {
checkRejectZone(" 0000");
checkRejectZone(" GMT ");
checkRejectZone("DANG!");
@@ -457,7 +457,7 @@ public class DecoderUtilsTest {
}
@Test
- public void testIsSimpleDigit() throws Exception {
+ public void testIsSimpleDigit() {
assertTrue(DecoderUtils.isSimpleDigit('0'));
assertTrue(DecoderUtils.isSimpleDigit('1'));
assertTrue(DecoderUtils.isSimpleDigit('2'));
@@ -507,7 +507,7 @@ public class DecoderUtilsTest {
}
@Test
- public void testRejectNumber() throws Exception {
+ public void testRejectNumber() {
checkRejectNumber("A1");
checkRejectNumber("1A");
checkRejectNumber("AA");
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org