diff options
author | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-09-23 04:57:31 -0700 |
---|---|---|
committer | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-09-23 04:57:31 -0700 |
commit | f3b959a9ece36c64a5a5fea19b91304105fa1023 (patch) | |
tree | 1fd026ac5e2ad6065dd6789cbf0d0ba962cf9098 | |
parent | b6b83d20cbd1701cf9ad82a1cae00dcfb077738a (diff) | |
parent | 2d67428457466d8b41191aa4b102a436d1b6965e (diff) |
Merge pull request #281 from Dhandapani/master
JUnit test cases for StringUtil
3 files changed, 315 insertions, 24 deletions
diff --git a/src/com.gluster.storage.management.core/.project b/src/com.gluster.storage.management.core/.project index 6c8fbb5c..c016cd3c 100644 --- a/src/com.gluster.storage.management.core/.project +++ b/src/com.gluster.storage.management.core/.project @@ -20,9 +20,15 @@ <arguments> </arguments> </buildCommand> + <buildCommand> + <name>com.instantiations.assist.eclipse.coverage.instrumentationBuilder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.jdt.core.javanature</nature> + <nature>com.instantiations.assist.eclipse.coverage.codeCoverageNature</nature> </natures> </projectDescription> 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..dc8c6c80 --- /dev/null +++ b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/StringUtilTest.java @@ -0,0 +1,309 @@ +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 <code>StringUtilTest</code> contains tests for the class <code>{@link StringUtil}</code>. + * + * @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<? extends Object>,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_1() + throws Exception { + List<String> string = new ArrayList<String>(); + string.add("test string"); + String delimiter = ""; + + String result = StringUtil.collectionToString(string, delimiter); + assertEquals("test string", result); + } + + /** + * Run the String collectionToString(Collection<? extends Object>,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_2() + throws Exception { + List<String> string = new ArrayList<String>(); + 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<? extends Object>,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_3() + throws Exception { + List<String> string = new ArrayList<String>(); + string.add("test ## string"); + string.add("java world"); + String delimiter = "##"; + + String result = StringUtil.collectionToString(string, delimiter); + assertEquals("test ## string##java world", result); + } + + /** + * Run the String collectionToString(Collection<? extends Object>,String) method test. + * + * @throws Exception + * + * @generatedBy CodePro at 21/9/11 4:53 PM + */ + @Test + public void testCollectionToString_4() + throws Exception { + List<String> string = new ArrayList<String>(); + String delimiter = ""; + + String result = StringUtil.collectionToString(string, delimiter); + assertEquals("", result); + } + + /** + * Run the List<String> 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<String> result = StringUtil.enumToArray(Season.values()); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List<String> 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<String> result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List<String> 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<String> result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(4, result.size()); + } + + /** + * Run the List<String> 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<String> result = StringUtil.extractList(input, delim); + + assertNotNull(result); + assertEquals(2, result.size()); + } + + /** + * Run the Map<String, String> 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<String, String> result = StringUtil.extractMap(input, majorDelim, minorDelim); + + // add additional test code here + assertNotNull(result); + assertEquals(3, result.size()); + } + + /** + * Run the Map<String, String> 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<String, String> 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..7d9ec340 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 @@ -18,7 +18,6 @@ *******************************************************************************/ package com.gluster.storage.management.core.utils; -import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; @@ -101,27 +100,4 @@ 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[]) { - - //Test case for "ListToString" - List<String> string = new ArrayList<String>(); - // Empty list - System.out.println(StringUtil.collectionToString(string, ", ")); - // Only one - string.add("test"); - System.out.println(StringUtil.collectionToString(string, ",:")); - // Multiple - string.add("welcome to java"); - System.out.println(StringUtil.collectionToString(string, "")); - } } |