From 1fddc61a7cb329379779ee34c86dd1ffb5662862 Mon Sep 17 00:00:00 2001 From: Dhandapani Date: Fri, 23 Sep 2011 11:24:07 +0530 Subject: Added StringUtil Junit test case --- .../management/core/utils/StringUtilTest.java | 328 +++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java (limited to 'src') diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java new file mode 100644 index 00000000..15cdbcaa --- /dev/null +++ b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java @@ -0,0 +1,328 @@ +package com.gluster.storage.management.core.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +/** + * The class StringUtilTest contains tests for the class {@link StringUtil}. + * + * @generatedBy CodePro at 21/9/11 4:53 PM + * @author root + * @version $Revision: 1.0 $ + */ +public class StringUtilTest { + public enum Season { WINTER, SPRING, SUMMER, FALL }; + /** + * Run the String collectionToString(Collection,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_1() + throws Exception { + List string = new ArrayList(); + string.add("test string"); + String delimiter = ""; + + String result = StringUtil.collectionToString(string, delimiter); + assertEquals("test string", result); + } + + /** + * Run the String collectionToString(Collection,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_2() + throws Exception { + List string = new ArrayList(); + string.add("test string"); + string.add("welcome to world"); + String delimiter = "::"; + + String result = StringUtil.collectionToString(string, delimiter); + + assertEquals("test string::welcome to world", result); + } + + /** + * Run the String collectionToString(Collection,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_3() + throws Exception { + List string = new ArrayList(); + string.add("test ## string"); + string.add("java world"); + String delimiter = "##"; + + String result = StringUtil.collectionToString(string, delimiter); + assertEquals("test ## string##java world", result); + } + + /** + * Run the List enumToArray(T[]) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testEnumToArray_1() + throws Exception { + + String[] expected = new String[] {"WINTER", "SPRING", "SUMMER", "FALL"}; + List result = StringUtil.enumToArray(Season.values()); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List extractList(String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractList_1() + throws Exception { + String input = "This is test message"; + String delim = " "; + + List result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List extractList(String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractList_2() + throws Exception { + String input = "welcome#to#java#world"; + String delim = "#"; + + List result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List extractList(String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractList_3() + throws Exception { + String input = "list$to%string"; + String delim = "%"; + + List result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(2, result.size()); + } + + /** + * Run the Map extractMap(String,String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractMap_1() + throws Exception { + String input = "k1=v1,k2=v2,k3=v3"; + String majorDelim = ","; + String minorDelim = "="; + + Map result = StringUtil.extractMap(input, majorDelim, minorDelim); + + // add additional test code here + assertNotNull(result); + assertEquals(3, result.size()); + } + + /** + * Run the Map extractMap(String,String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractMap_2() + throws Exception { + String input = "k1=>v1&k2=>v2&k3=>v3"; + String majorDelim = "&"; + String minorDelim = "=>"; + + Map result = StringUtil.extractMap(input, majorDelim, minorDelim); + + // add additional test code here + assertNotNull(result); + assertEquals(3, result.size()); + } + + /** + * Run the boolean filterString(String,String,boolean) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testFilterString_1() + throws Exception { + String sourceString = "This is java program"; + String filterString = "Java"; + boolean caseSensitive = true; + + boolean result = StringUtil.filterString(sourceString, filterString, caseSensitive); + + assertEquals(false, result); + } + + /** + * Run the boolean filterString(String,String,boolean) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testFilterString_2() + throws Exception { + String sourceString = "This is java program"; + String filterString = "Java"; + boolean caseSensitive = false; + + boolean result = StringUtil.filterString(sourceString, filterString, caseSensitive); + + assertEquals(true, result); + } + + /** + * Run the String formatNumber(Double,int) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testFormatNumber_1() + throws Exception { + Double number = new Double(1.0); + int dec = 1; + + String result = StringUtil.formatNumber(number, dec); + + assertEquals("1", result); + } + + /** + * Run the String formatNumber(Double,int) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testFormatNumber_2() + throws Exception { + Double number = new Double(105.87); + int dec = 1; + + String result = StringUtil.formatNumber(number, dec); + + assertEquals("105.9", result); + } + + /** + * Run the String removeSpaces(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testRemoveSpaces_1() + throws Exception { + String str = "this is test string"; + + String result = StringUtil.removeSpaces(str); + + // add additional test code here + assertEquals("thisisteststring", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StringUtilTest.class); + } +} \ No newline at end of file -- cgit From 4e56c956f5e8eec6e70156530ab33ad445f6ec79 Mon Sep 17 00:00:00 2001 From: Dhandapani Date: Fri, 23 Sep 2011 11:24:07 +0530 Subject: Added StringUtil Junit test case --- .../management/core/utils/StringUtilTest.java | 292 +++++++++++++++++++++ .../storage/management/core/utils/StringUtil.java | 8 - 2 files changed, 292 insertions(+), 8 deletions(-) create mode 100644 src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java (limited to 'src') diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java new file mode 100644 index 00000000..534e684c --- /dev/null +++ b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java @@ -0,0 +1,292 @@ +package com.gluster.storage.management.core.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +/** + * The class StringUtilTest contains tests for the class {@link StringUtil}. + * + * @generatedBy CodePro at 21/9/11 4:53 PM + * @author root + * @version $Revision: 1.0 $ + */ +public class StringUtilTest { + public enum Season { WINTER, SPRING, SUMMER, FALL }; + /** + * Run the String collectionToString(Collection,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_1() + throws Exception { + List string = new ArrayList(); + string.add("test string"); + String delimiter = ""; + + String result = StringUtil.collectionToString(string, delimiter); + assertEquals("test string", result); + } + + /** + * Run the String collectionToString(Collection,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_2() + throws Exception { + List string = new ArrayList(); + string.add("test string"); + string.add("welcome to world"); + String delimiter = "::"; + + String result = StringUtil.collectionToString(string, delimiter); + + assertEquals("test string::welcome to world", result); + } + + /** + * Run the String collectionToString(Collection,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_3() + throws Exception { + List string = new ArrayList(); + string.add("test ## string"); + string.add("java world"); + String delimiter = "##"; + + String result = StringUtil.collectionToString(string, delimiter); + assertEquals("test ## string##java world", result); + } + + /** + * Run the List enumToArray(T[]) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testEnumToArray_1() + throws Exception { + + String[] expected = new String[] {"WINTER", "SPRING", "SUMMER", "FALL"}; + List result = StringUtil.enumToArray(Season.values()); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List extractList(String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractList_1() + throws Exception { + String input = "This is test message"; + String delim = " "; + + List result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List extractList(String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractList_2() + throws Exception { + String input = "welcome#to#java#world"; + String delim = "#"; + + List result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List extractList(String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractList_3() + throws Exception { + String input = "list$to%string"; + String delim = "%"; + + List result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(2, result.size()); + } + + /** + * Run the Map extractMap(String,String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractMap_1() + throws Exception { + String input = "k1=v1,k2=v2,k3=v3"; + String majorDelim = ","; + String minorDelim = "="; + + Map result = StringUtil.extractMap(input, majorDelim, minorDelim); + + // add additional test code here + assertNotNull(result); + assertEquals(3, result.size()); + } + + /** + * Run the Map extractMap(String,String,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testExtractMap_2() + throws Exception { + String input = "k1=>v1&k2=>v2&k3=>v3"; + String majorDelim = "&"; + String minorDelim = "=>"; + + Map result = StringUtil.extractMap(input, majorDelim, minorDelim); + + // add additional test code here + assertNotNull(result); + assertEquals(3, result.size()); + } + + /** + * Run the boolean filterString(String,String,boolean) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testFilterString_1() + throws Exception { + String sourceString = "This is java program"; + String filterString = "Java"; + boolean caseSensitive = true; + + boolean result = StringUtil.filterString(sourceString, filterString, caseSensitive); + + assertEquals(false, result); + } + + /** + * Run the boolean filterString(String,String,boolean) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testFilterString_2() + throws Exception { + String sourceString = "This is java program"; + String filterString = "Java"; + boolean caseSensitive = false; + + boolean result = StringUtil.filterString(sourceString, filterString, caseSensitive); + + assertEquals(true, result); + } + + /** + * Run the String removeSpaces(String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testRemoveSpaces_1() + throws Exception { + String str = "this is test string"; + + String result = StringUtil.removeSpaces(str); + + // add additional test code here + assertEquals("thisisteststring", result); + } + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Before + public void setUp() + throws Exception { + // add additional set up code here + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @After + public void tearDown() + throws Exception { + // Add additional tear down code here + } + + /** + * Launch the test. + * + * @param args the command line arguments + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + public static void main(String[] args) { + new org.junit.runner.JUnitCore().run(StringUtilTest.class); + } +} \ No newline at end of file diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java index cdf71dcc..02f44bc6 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/StringUtil.java @@ -102,14 +102,6 @@ public class StringUtil { return output; } - public static String formatNumber(Double number, int dec) { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMaximumFractionDigits(dec); - nf.setGroupingUsed(false); - // Setting this to true will give you xx,xxx,xxx type of formatting. - String formattedvalue = nf.format(number); - return formattedvalue; - } public static void main(String args[]) { -- cgit