Repository: james-project Updated Branches: refs/heads/master 8d5c53b12 -> c424accd9
JAMES-2261 Provide some unit tests for IMAPSession utils Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/465f315d Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/465f315d Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/465f315d Branch: refs/heads/master Commit: 465f315d6cb8eef37296c52bc30b525e88f401bf Parents: 58d3ec7 Author: benwa <[email protected]> Authored: Fri Dec 15 11:30:30 2017 +0700 Committer: benwa <[email protected]> Committed: Fri Dec 15 13:50:51 2017 +0700 ---------------------------------------------------------------------- .../james/imap/api/ImapSessionUtilsTest.java | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/465f315d/protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionUtilsTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionUtilsTest.java b/protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionUtilsTest.java new file mode 100644 index 0000000..86e3e99 --- /dev/null +++ b/protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionUtilsTest.java @@ -0,0 +1,60 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.imap.api; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.apache.james.imap.encode.FakeImapSession; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.mock.MockMailboxSession; +import org.junit.Before; +import org.junit.Test; + +public class ImapSessionUtilsTest { + private static final String USERNAME = "username"; + private static final MailboxSession MAILBOX_SESSION = new MockMailboxSession(USERNAME); + private FakeImapSession fakeImapSession; + + @Before + public void setUp() { + fakeImapSession = new FakeImapSession(); + } + + @Test + public void getUserNameShouldReturnNullWhenNoMailboxSession() { + assertThat(ImapSessionUtils.getUserName(fakeImapSession)) + .isNull(); + } + + @Test + public void getUserNameShouldReturnUserWhenMailboxSession() { + fakeImapSession.setAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY, MAILBOX_SESSION); + assertThat(ImapSessionUtils.getUserName(fakeImapSession)) + .isEqualTo(USERNAME); + } + + @Test + public void getUserNameShouldThrowOnNullImapSession() { + assertThatThrownBy(() -> ImapSessionUtils.getUserName(null)) + .isInstanceOf(NullPointerException.class); + } + +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
