[Title] Added comment and unittest of AppIdGenerator
authorchanghyun1.lee <changhyun1.lee@samsung.com>
Tue, 7 Aug 2012 11:12:00 +0000 (20:12 +0900)
committerchanghyun1.lee <changhyun1.lee@samsung.com>
Wed, 8 Aug 2012 01:33:27 +0000 (10:33 +0900)
[Type] Enhancement
[Module]
[Priority]
[CQ#]
[Redmine#] 6281
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: I05d4cad136b0aea104d1f29a606c7f031761b30b

org.tizen.common/src/org/tizen/common/AppIdGenerator.java
org.tizen.common/test/src/org/tizen/common/AppIdGeneratorTest.java [new file with mode: 0644]

index 28aba98..ea04720 100644 (file)
@@ -35,6 +35,10 @@ import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
 import javax.crypto.spec.SecretKeySpec;
 
+/**
+ * Appid generator.
+ * It is consist of 0-9, a-z
+ */
 public class AppIdGenerator {
     final char[] PSEUDO_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7',
             '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
@@ -78,10 +82,21 @@ public class AppIdGenerator {
         return cipher.doFinal(bytes);
     }
 
+    /**
+     * Generate an id of length n.
+     *
+     * @param size id length
+     * @return id
+     */
     public String generate(int size) throws Exception {
         return convertBytesToAlphaNumeric(generateRandomBytes(size), size);
     }
 
+    /**
+     * Generate an id of length 10.
+     *
+     * @return id
+     */
     public String generate() throws Exception {
         return generate(10).toLowerCase();
     }
diff --git a/org.tizen.common/test/src/org/tizen/common/AppIdGeneratorTest.java b/org.tizen.common/test/src/org/tizen/common/AppIdGeneratorTest.java
new file mode 100644 (file)
index 0000000..3481b7e
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+*  Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* ChangHyun Lee <changhyun1.lee@samsung.com>
+*
+* Licensed 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.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.common;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * AppIdGeneratorTest.
+ *
+ * Test case for {@link AppIdGenerator}
+ *
+ * @author Changhyun Lee{@literal <changhyun1.lee@samsung.com>} (S-Core)
+ *
+ * @see AppIdGenerator
+ *
+ */
+public class AppIdGeneratorTest {
+
+    /**
+     * Test {@link AppIdGenerator#generate()}
+     *
+     * @throws Exception in case of failure in test
+     *
+     * @see {@link AppIdGenerator#generate()}
+     */
+    @Test
+    public void test_generate() throws Exception {
+        AppIdGenerator generator = new AppIdGenerator();
+        String id = generator.generate();
+        String id2 = generator.generate();
+        assertTrue(id.length() == 10);
+        assertTrue(id2.length() == 10);
+    }
+
+    /**
+     * Test {@link AppIdGenerator#generate(int size)}
+     *
+     * @throws Exception in case of failure in test
+     *
+     * @see {@link AppIdGenerator#generate(int size)}
+     */
+    @Test
+    public void test_generate2() throws Exception {
+        AppIdGenerator generator = new AppIdGenerator();
+        String id = generator.generate(10);
+        String id2 = generator.generate(11);
+        assertTrue(id.length() == 10);
+        assertTrue(id2.length() == 11);
+    }
+
+}