1   ////////////////////////////////////////////////////////////////////////////////
2   //
3   //                  ObjectLab is sponsoring QALab
4   // 
5   // Based in London, we are world leaders in the design and development 
6   // of bespoke applications for the Securities Financing markets.
7   // 
8   // <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
9   //           ___  _     _           _   _          _
10  //          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
11  //         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
12  //         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
13  //          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
14  //                   |__/
15  //
16  //                   http://www.ObjectLab.co.uk
17  // ---------------------------------------------------------------------------
18  //
19  //QALab is released under the GNU General Public License.
20  //
21  //QALab: Collects QA Statistics from your build over time.
22  //2005+, ObjectLab Ltd
23  //
24  //This library is free software; you can redistribute it and/or
25  //modify it under the terms of the GNU General Public
26  //License as published by the Free Software Foundation; either
27  //version 2.1 of the License, or (at your option) any later version.
28  //
29  //This library is distributed in the hope that it will be useful,
30  //but WITHOUT ANY WARRANTY; without even the implied warranty of
31  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
32  //General Public License for more details.
33  //
34  //You should have received a copy of the GNU General Public
35  //License along with this library; if not, write to the Free Software
36  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
37  //
38  ////////////////////////////////////////////////////////////////////////////////
39  package net.objectlab.qalab.util;
40  
41  import junit.framework.Test;
42  import junit.framework.TestSuite;
43  
44  import net.objectlab.qalab.AbstractTestCase;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.List;
49  
50  public class UtilTest extends AbstractTestCase {
51      /**
52       * Create the test case
53       *
54       * @param testName name of the test case
55       */
56      public UtilTest(String testName) {
57          super(testName);
58      }
59  
60      /**
61       * @return the suite of tests being tested
62       */
63      public static Test suite() {
64          return new TestSuite(UtilTest.class);
65      }
66  
67      /**
68       * Test Util.listify
69       */
70      public void testListify() {
71          List list1 = Util.listify("a,b,c", ",");
72  
73          checkList(list1);
74  
75          List list2 = Util.listify("a:b:c", ":");
76  
77          checkList(list2);
78      }
79  
80      private void checkList(List list) {
81          assertEquals("List1 size", 3, list.size());
82          assertEquals("List 1, element", "a", list.get(0));
83          assertEquals("List 1, element", "b", list.get(1));
84          assertEquals("List 1, element", "c", list.get(2));
85      }
86  
87      /**
88       * Test Util.listify empty string
89       */
90      public void testListifyEmptyString() {
91          List list1 = Util.listify("", ",");
92  
93          assertTrue("List1 should be empty", list1.isEmpty());
94  
95          List list2 = Util.listify("", ":");
96  
97          assertTrue("List2 should be empty", list2.isEmpty());
98      }
99  
100     /**
101      * Test Util.listify string but wrong delim
102      */
103     public void testListifyStringWrongDelim() {
104         List list1 = Util.listify("a,b,c", ";");
105 
106         assertEquals("List1 should have 1 element", 1, list1.size());
107         assertEquals("List1 element", "a,b,c", list1.get(0));
108     }
109 
110     /**
111      * Test Util.listify null string
112      */
113     public void testListifyNullString() {
114         List list1 = Util.listify(null, ",");
115 
116         assertTrue("List1 should be empty", list1.isEmpty());
117 
118         List list2 = Util.listify(null, ":");
119 
120         assertTrue("List2 should be empty", list2.isEmpty());
121     }
122 
123     /**
124      * Test Util.listToCSVString
125      */
126     public void testListToCSVString() {
127         List list1 = new ArrayList();
128 
129         list1.add("a");
130         list1.add("b");
131         list1.add("c");
132 
133         final String str = Util.listToCSVString(list1);
134 
135         assertEquals("Util.listToCSVString", "a,b,c", str);
136     }
137 
138     /**
139      * Test Util.listToCSVString with empty list
140      */
141     public void testEmptyListToCSVString() {
142         final String str = Util.listToCSVString(Collections.EMPTY_LIST);
143 
144         assertEquals("Util.listToCSVString", "", str);
145     }
146 
147     /**
148      * Test Util.listToCSVString with null list
149      */
150     public void testNullListToCSVString() {
151         final String str = Util.listToCSVString(null);
152 
153         assertEquals("Util.listToCSVString", "", str);
154     }
155 }
156 /*
157  *                   ObjectLab is sponsoring QALab
158  * 
159  * Based in London, we are world leaders in the design and development 
160  * of bespoke applications for the securities financing markets.
161  * 
162  * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
163  *           ___  _     _           _   _          _
164  *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
165  *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
166  *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
167  *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
168  *                   |__/
169  *
170  *                     www.ObjectLab.co.uk
171  */