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 2015/09/14 21:14:29 UTC
svn commit: r1703037 -
/james/server/trunk/container/cli/src/test/java/org/apache/james/cli/type/CmdTypeTest.java
Author: btellier
Date: Mon Sep 14 19:14:29 2015
New Revision: 1703037
URL: http://svn.apache.org/r1703037
Log:
JAMES-1610 Migrate CmdTypeTest to Assertj - contributed by Matthieu Baechler
Modified:
james/server/trunk/container/cli/src/test/java/org/apache/james/cli/type/CmdTypeTest.java
Modified: james/server/trunk/container/cli/src/test/java/org/apache/james/cli/type/CmdTypeTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/cli/src/test/java/org/apache/james/cli/type/CmdTypeTest.java?rev=1703037&r1=1703036&r2=1703037&view=diff
==============================================================================
--- james/server/trunk/container/cli/src/test/java/org/apache/james/cli/type/CmdTypeTest.java (original)
+++ james/server/trunk/container/cli/src/test/java/org/apache/james/cli/type/CmdTypeTest.java Mon Sep 14 19:14:29 2015
@@ -1,92 +1,156 @@
-/****************************************************************
- * 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.cli.type;
-
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
-
-/**
- * Test class for the CmdType enum.
- */
-public class CmdTypeTest {
-
- /**
- * Test the hasCorrectArguments method.
- */
- @Test
- public void testHasCorrectArguments() {
- CmdType cmd;
- boolean result;
-
- cmd = CmdType.ADDDOMAIN;
-
- // Test bogus number
- result = cmd.hasCorrectArguments(-1);
- assertEquals(false, result);
-
- // Test actual number
- result = cmd.hasCorrectArguments(cmd.getArgumentCount());
- assertEquals(true, result);
-
- // Test known bad number
- result = cmd.hasCorrectArguments(cmd.getArgumentCount() - 1);
- assertEquals(false, result);
- }
-
- /**
- * Test the lookup method.
- */
- @Test
- public void testLookup() {
- CmdType result;
-
- // Test happy path
- result = CmdType.lookup(CmdType.ADDUSER.getCommand());
- assertEquals(CmdType.ADDUSER, result);
-
- result = CmdType.lookup(CmdType.REMOVEUSER.getCommand());
- assertEquals(CmdType.REMOVEUSER, result);
-
- result = CmdType.lookup(CmdType.LISTUSERS.getCommand());
- assertEquals(CmdType.LISTUSERS, result);
-
- result = CmdType.lookup(CmdType.ADDDOMAIN.getCommand());
- assertEquals(CmdType.ADDDOMAIN, result);
-
- result = CmdType.lookup(CmdType.REMOVEDOMAIN.getCommand());
- assertEquals(CmdType.REMOVEDOMAIN, result);
-
- result = CmdType.lookup(CmdType.LISTDOMAINS.getCommand());
- assertEquals(CmdType.LISTDOMAINS, result);
-
- result = CmdType.lookup(CmdType.SETPASSWORD.getCommand());
- assertEquals(CmdType.SETPASSWORD, result);
-
- // Test known bad value
- result = CmdType.lookup("");
- assertEquals(null, result);
-
- result = CmdType.lookup("error");
- assertEquals(null, result);
-
- // Test null value
- result = CmdType.lookup(null);
- assertEquals(null, result);
- }
+/****************************************************************
+ * 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.cli.type;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+/**
+ * Test class for the CmdType enum.
+ */
+public class CmdTypeTest {
+
+ @Test
+ public void hasCorrectArgumentShouldBeFalseOnNegativeInput() {
+ assertThat(CmdType.ADDDOMAIN.hasCorrectArguments(-1)).isFalse();
+ }
+
+ @Test
+ public void hasCorrectArgumentShouldBeTrueOnRightArgumentNumber() {
+ assertThat(CmdType.ADDDOMAIN.hasCorrectArguments(2)).isTrue();
+ }
+
+
+ @Test
+ public void hasCorrectArgumentShouldBeFalseOnIncorrectArgumentNumber() {
+ assertThat(CmdType.ADDDOMAIN.hasCorrectArguments(1)).isFalse();
+ }
+
+ @Test
+ public void lookupAddUserShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("adduser")).isEqualTo(CmdType.ADDUSER);
+ }
+
+ @Test
+ public void lookupRemoveUserShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("removeuser")).isEqualTo(CmdType.REMOVEUSER);
+ }
+
+ @Test
+ public void lookupListUsersShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("listusers")).isEqualTo(CmdType.LISTUSERS);
+ }
+
+ @Test
+ public void lookupAddDomainShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("adddomain")).isEqualTo(CmdType.ADDDOMAIN);
+ }
+
+ @Test
+ public void lookupRemoveDomainShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("removedomain")).isEqualTo(CmdType.REMOVEDOMAIN);
+ }
+
+ @Test
+ public void lookupContainsDomainShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("containsdomain")).isEqualTo(CmdType.CONTAINSDOMAIN);
+ }
+
+ @Test
+ public void lookupListDomainsShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("listdomains")).isEqualTo(CmdType.LISTDOMAINS);
+ }
+
+ @Test
+ public void lookupListMappingsShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("listmappings")).isEqualTo(CmdType.LISTMAPPINGS);
+ }
+
+ @Test
+ public void lookupListUserDomainMappingsShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("listuserdomainmappings")).isEqualTo(CmdType.LISTUSERDOMAINMAPPINGS);
+ }
+
+ @Test
+ public void lookupAddAddressMappingShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("addaddressmapping")).isEqualTo(CmdType.ADDADDRESSMAPPING);
+ }
+
+ @Test
+ public void lookupRemoveAddressMappingShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("removeaddressmapping")).isEqualTo(CmdType.REMOVEADDRESSMAPPING);
+ }
+
+ @Test
+ public void lookupAddRegexMappingShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("addregexmapping")).isEqualTo(CmdType.ADDREGEXMAPPING);
+ }
+
+ @Test
+ public void lookupRemoveRegexMappingShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("removeregexmapping")).isEqualTo(CmdType.REMOVEREGEXMAPPING);
+ }
+
+ @Test
+ public void lookupSetPasswordShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("setpassword")).isEqualTo(CmdType.SETPASSWORD);
+ }
+
+ @Test
+ public void lookupCopyMailboxShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("copymailbox")).isEqualTo(CmdType.COPYMAILBOX);
+ }
+
+ @Test
+ public void lookupDeleteUserMailboxesShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("deleteusermailboxes")).isEqualTo(CmdType.DELETEUSERMAILBOXES);
+ }
+
+ @Test
+ public void lookupCreateMailboxShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("createmailbox")).isEqualTo(CmdType.CREATEMAILBOX);
+ }
+
+ @Test
+ public void lookupListUserMailboxesShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("listusermailboxes")).isEqualTo(CmdType.LISTUSERMAILBOXES);
+ }
+
+ @Test
+ public void lookupDeleteMailboxShouldReturnEnumValue() {
+ assertThat(CmdType.lookup("deletemailbox")).isEqualTo(CmdType.DELETEMAILBOX);
+ }
+
+ @Test
+ public void lookupEmptyStringShouldReturnNull() {
+ assertThat(CmdType.lookup("")).isNull();
+ }
+
+ @Test
+ public void lookupUnknownStringShouldReturnNull() {
+ assertThat(CmdType.lookup("error")).isNull();
+ }
+
+ @Test
+ public void lookupNullShouldReturnNull() {
+ assertThat(CmdType.lookup(null)).isNull();
+ }
+
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org