Source Code Cross Referenced for BooleanUtilsTest.java in  » Library » Apache-common-lang » org » apache » commons » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common lang » org.apache.commons.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.lang;
018:
019:        import java.lang.reflect.Constructor;
020:        import java.lang.reflect.Modifier;
021:
022:        import junit.framework.Test;
023:        import junit.framework.TestCase;
024:        import junit.framework.TestSuite;
025:        import junit.textui.TestRunner;
026:
027:        /**
028:         * Unit tests {@link org.apache.commons.lang.BooleanUtils}.
029:         *
030:         * @author Stephen Colebourne
031:         * @author Matthew Hawthorne
032:         * @version $Id: BooleanUtilsTest.java 492361 2007-01-04 00:10:13Z scolebourne $
033:         */
034:        public class BooleanUtilsTest extends TestCase {
035:
036:            public BooleanUtilsTest(String name) {
037:                super (name);
038:            }
039:
040:            public static void main(String[] args) {
041:                TestRunner.run(suite());
042:            }
043:
044:            public static Test suite() {
045:                TestSuite suite = new TestSuite(BooleanUtilsTest.class);
046:                suite.setName("BooleanUtils Tests");
047:                return suite;
048:            }
049:
050:            protected void setUp() throws Exception {
051:                super .setUp();
052:            }
053:
054:            protected void tearDown() throws Exception {
055:                super .tearDown();
056:            }
057:
058:            //-----------------------------------------------------------------------
059:            public void testConstructor() {
060:                assertNotNull(new BooleanUtils());
061:                Constructor[] cons = BooleanUtils.class
062:                        .getDeclaredConstructors();
063:                assertEquals(1, cons.length);
064:                assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
065:                assertEquals(true, Modifier.isPublic(BooleanUtils.class
066:                        .getModifiers()));
067:                assertEquals(false, Modifier.isFinal(BooleanUtils.class
068:                        .getModifiers()));
069:            }
070:
071:            //-----------------------------------------------------------------------
072:            public void test_negate_Boolean() {
073:                assertSame(null, BooleanUtils.negate(null));
074:                assertSame(Boolean.TRUE, BooleanUtils.negate(Boolean.FALSE));
075:                assertSame(Boolean.FALSE, BooleanUtils.negate(Boolean.TRUE));
076:            }
077:
078:            //-----------------------------------------------------------------------
079:            public void test_isTrue_Boolean() {
080:                assertEquals(true, BooleanUtils.isTrue(Boolean.TRUE));
081:                assertEquals(false, BooleanUtils.isTrue(Boolean.FALSE));
082:                assertEquals(false, BooleanUtils.isTrue((Boolean) null));
083:            }
084:
085:            public void test_isNotTrue_Boolean() {
086:                assertEquals(false, BooleanUtils.isNotTrue(Boolean.TRUE));
087:                assertEquals(true, BooleanUtils.isNotTrue(Boolean.FALSE));
088:                assertEquals(true, BooleanUtils.isNotTrue((Boolean) null));
089:            }
090:
091:            //-----------------------------------------------------------------------
092:            public void test_isFalse_Boolean() {
093:                assertEquals(false, BooleanUtils.isFalse(Boolean.TRUE));
094:                assertEquals(true, BooleanUtils.isFalse(Boolean.FALSE));
095:                assertEquals(false, BooleanUtils.isFalse((Boolean) null));
096:            }
097:
098:            public void test_isNotFalse_Boolean() {
099:                assertEquals(true, BooleanUtils.isNotFalse(Boolean.TRUE));
100:                assertEquals(false, BooleanUtils.isNotFalse(Boolean.FALSE));
101:                assertEquals(true, BooleanUtils.isNotFalse((Boolean) null));
102:            }
103:
104:            //-----------------------------------------------------------------------
105:            public void test_toBooleanObject_boolean() {
106:                assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject(true));
107:                assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject(false));
108:            }
109:
110:            public void test_toBoolean_Boolean() {
111:                assertEquals(true, BooleanUtils.toBoolean(Boolean.TRUE));
112:                assertEquals(false, BooleanUtils.toBoolean(Boolean.FALSE));
113:                assertEquals(false, BooleanUtils.toBoolean((Boolean) null));
114:            }
115:
116:            public void test_toBooleanDefaultIfNull_Boolean_boolean() {
117:                assertEquals(true, BooleanUtils.toBooleanDefaultIfNull(
118:                        Boolean.TRUE, true));
119:                assertEquals(true, BooleanUtils.toBooleanDefaultIfNull(
120:                        Boolean.TRUE, false));
121:                assertEquals(false, BooleanUtils.toBooleanDefaultIfNull(
122:                        Boolean.FALSE, true));
123:                assertEquals(false, BooleanUtils.toBooleanDefaultIfNull(
124:                        Boolean.FALSE, false));
125:                assertEquals(true, BooleanUtils.toBooleanDefaultIfNull(
126:                        (Boolean) null, true));
127:                assertEquals(false, BooleanUtils.toBooleanDefaultIfNull(
128:                        (Boolean) null, false));
129:            }
130:
131:            //-----------------------------------------------------------------------
132:            //-----------------------------------------------------------------------
133:            public void test_toBoolean_int() {
134:                assertEquals(true, BooleanUtils.toBoolean(1));
135:                assertEquals(true, BooleanUtils.toBoolean(-1));
136:                assertEquals(false, BooleanUtils.toBoolean(0));
137:            }
138:
139:            public void test_toBooleanObject_int() {
140:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(1));
141:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(-1));
142:                assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(0));
143:            }
144:
145:            public void test_toBooleanObject_Integer() {
146:                assertEquals(Boolean.TRUE, BooleanUtils
147:                        .toBooleanObject(new Integer(1)));
148:                assertEquals(Boolean.TRUE, BooleanUtils
149:                        .toBooleanObject(new Integer(-1)));
150:                assertEquals(Boolean.FALSE, BooleanUtils
151:                        .toBooleanObject(new Integer(0)));
152:                assertEquals(null, BooleanUtils.toBooleanObject((Integer) null));
153:            }
154:
155:            //-----------------------------------------------------------------------
156:            public void test_toBoolean_int_int_int() {
157:                assertEquals(true, BooleanUtils.toBoolean(6, 6, 7));
158:                assertEquals(false, BooleanUtils.toBoolean(7, 6, 7));
159:                try {
160:                    BooleanUtils.toBoolean(8, 6, 7);
161:                    fail();
162:                } catch (IllegalArgumentException ex) {
163:                }
164:            }
165:
166:            public void test_toBoolean_Integer_Integer_Integer() {
167:                Integer six = new Integer(6);
168:                Integer seven = new Integer(7);
169:
170:                assertEquals(true, BooleanUtils.toBoolean((Integer) null, null,
171:                        seven));
172:                assertEquals(false, BooleanUtils.toBoolean((Integer) null, six,
173:                        null));
174:                try {
175:                    BooleanUtils.toBoolean(null, six, seven);
176:                    fail();
177:                } catch (IllegalArgumentException ex) {
178:                }
179:
180:                assertEquals(true, BooleanUtils.toBoolean(new Integer(6), six,
181:                        seven));
182:                assertEquals(false, BooleanUtils.toBoolean(new Integer(7), six,
183:                        seven));
184:                try {
185:                    BooleanUtils.toBoolean(new Integer(8), six, seven);
186:                    fail();
187:                } catch (IllegalArgumentException ex) {
188:                }
189:            }
190:
191:            //-----------------------------------------------------------------------
192:            public void test_toBooleanObject_int_int_int() {
193:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(6, 6,
194:                        7, 8));
195:                assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(7, 6,
196:                        7, 8));
197:                assertEquals(null, BooleanUtils.toBooleanObject(8, 6, 7, 8));
198:                try {
199:                    BooleanUtils.toBooleanObject(9, 6, 7, 8);
200:                    fail();
201:                } catch (IllegalArgumentException ex) {
202:                }
203:            }
204:
205:            public void test_toBooleanObject_Integer_Integer_Integer_Integer() {
206:                Integer six = new Integer(6);
207:                Integer seven = new Integer(7);
208:                Integer eight = new Integer(8);
209:
210:                assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject(
211:                        (Integer) null, null, seven, eight));
212:                assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject(
213:                        (Integer) null, six, null, eight));
214:                assertSame(null, BooleanUtils.toBooleanObject((Integer) null,
215:                        six, seven, null));
216:                try {
217:                    BooleanUtils.toBooleanObject(null, six, seven, eight);
218:                    fail();
219:                } catch (IllegalArgumentException ex) {
220:                }
221:
222:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject(
223:                        new Integer(6), six, seven, eight));
224:                assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject(
225:                        new Integer(7), six, seven, eight));
226:                assertEquals(null, BooleanUtils.toBooleanObject(new Integer(8),
227:                        six, seven, eight));
228:                try {
229:                    BooleanUtils.toBooleanObject(new Integer(9), six, seven,
230:                            eight);
231:                    fail();
232:                } catch (IllegalArgumentException ex) {
233:                }
234:            }
235:
236:            //-----------------------------------------------------------------------
237:            public void test_toInteger_boolean() {
238:                assertEquals(1, BooleanUtils.toInteger(true));
239:                assertEquals(0, BooleanUtils.toInteger(false));
240:            }
241:
242:            public void test_toIntegerObject_boolean() {
243:                assertEquals(new Integer(1), BooleanUtils.toIntegerObject(true));
244:                assertEquals(new Integer(0), BooleanUtils
245:                        .toIntegerObject(false));
246:            }
247:
248:            public void test_toIntegerObject_Boolean() {
249:                assertEquals(new Integer(1), BooleanUtils
250:                        .toIntegerObject(Boolean.TRUE));
251:                assertEquals(new Integer(0), BooleanUtils
252:                        .toIntegerObject(Boolean.FALSE));
253:                assertEquals(null, BooleanUtils.toIntegerObject((Boolean) null));
254:            }
255:
256:            //-----------------------------------------------------------------------
257:            public void test_toInteger_boolean_int_int() {
258:                assertEquals(6, BooleanUtils.toInteger(true, 6, 7));
259:                assertEquals(7, BooleanUtils.toInteger(false, 6, 7));
260:            }
261:
262:            public void test_toInteger_Boolean_int_int_int() {
263:                assertEquals(6, BooleanUtils.toInteger(Boolean.TRUE, 6, 7, 8));
264:                assertEquals(7, BooleanUtils.toInteger(Boolean.FALSE, 6, 7, 8));
265:                assertEquals(8, BooleanUtils.toInteger(null, 6, 7, 8));
266:            }
267:
268:            public void test_toIntegerObject_boolean_Integer_Integer() {
269:                Integer six = new Integer(6);
270:                Integer seven = new Integer(7);
271:                assertEquals(six, BooleanUtils
272:                        .toIntegerObject(true, six, seven));
273:                assertEquals(seven, BooleanUtils.toIntegerObject(false, six,
274:                        seven));
275:            }
276:
277:            public void test_toIntegerObject_Boolean_Integer_Integer_Integer() {
278:                Integer six = new Integer(6);
279:                Integer seven = new Integer(7);
280:                Integer eight = new Integer(8);
281:                assertEquals(six, BooleanUtils.toIntegerObject(Boolean.TRUE,
282:                        six, seven, eight));
283:                assertEquals(seven, BooleanUtils.toIntegerObject(Boolean.FALSE,
284:                        six, seven, eight));
285:                assertEquals(eight, BooleanUtils.toIntegerObject(
286:                        (Boolean) null, six, seven, eight));
287:                assertEquals(null, BooleanUtils.toIntegerObject((Boolean) null,
288:                        six, seven, null));
289:            }
290:
291:            //-----------------------------------------------------------------------
292:            //-----------------------------------------------------------------------
293:            public void test_toBooleanObject_String() {
294:                assertEquals(null, BooleanUtils.toBooleanObject((String) null));
295:                assertEquals(null, BooleanUtils.toBooleanObject(""));
296:                assertEquals(Boolean.FALSE, BooleanUtils
297:                        .toBooleanObject("false"));
298:                assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("no"));
299:                assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("off"));
300:                assertEquals(Boolean.FALSE, BooleanUtils
301:                        .toBooleanObject("FALSE"));
302:                assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("NO"));
303:                assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("OFF"));
304:                assertEquals(null, BooleanUtils.toBooleanObject("oof"));
305:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("true"));
306:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("yes"));
307:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("on"));
308:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TRUE"));
309:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("ON"));
310:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("YES"));
311:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("TruE"));
312:            }
313:
314:            public void test_toBooleanObject_String_String_String_String() {
315:                assertSame(Boolean.TRUE, BooleanUtils.toBooleanObject(
316:                        (String) null, null, "N", "U"));
317:                assertSame(Boolean.FALSE, BooleanUtils.toBooleanObject(
318:                        (String) null, "Y", null, "U"));
319:                assertSame(null, BooleanUtils.toBooleanObject((String) null,
320:                        "Y", "N", null));
321:                try {
322:                    BooleanUtils.toBooleanObject((String) null, "Y", "N", "U");
323:                    fail();
324:                } catch (IllegalArgumentException ex) {
325:                }
326:
327:                assertEquals(Boolean.TRUE, BooleanUtils.toBooleanObject("Y",
328:                        "Y", "N", "U"));
329:                assertEquals(Boolean.FALSE, BooleanUtils.toBooleanObject("N",
330:                        "Y", "N", "U"));
331:                assertEquals(null, BooleanUtils.toBooleanObject("U", "Y", "N",
332:                        "U"));
333:                try {
334:                    BooleanUtils.toBooleanObject(null, "Y", "N", "U");
335:                    fail();
336:                } catch (IllegalArgumentException ex) {
337:                }
338:                try {
339:                    BooleanUtils.toBooleanObject("X", "Y", "N", "U");
340:                    fail();
341:                } catch (IllegalArgumentException ex) {
342:                }
343:            }
344:
345:            //-----------------------------------------------------------------------
346:            public void test_toBoolean_String() {
347:                assertEquals(false, BooleanUtils.toBoolean((String) null));
348:                assertEquals(false, BooleanUtils.toBoolean(""));
349:                assertEquals(false, BooleanUtils.toBoolean("off"));
350:                assertEquals(false, BooleanUtils.toBoolean("oof"));
351:                assertEquals(false, BooleanUtils.toBoolean("yep"));
352:                assertEquals(false, BooleanUtils.toBoolean("trux"));
353:                assertEquals(false, BooleanUtils.toBoolean("false"));
354:                assertEquals(false, BooleanUtils.toBoolean("a"));
355:                assertEquals(true, BooleanUtils.toBoolean("true")); // interned handled differently
356:                assertEquals(true, BooleanUtils
357:                        .toBoolean(new StringBuffer("tr").append("ue")
358:                                .toString()));
359:                assertEquals(true, BooleanUtils.toBoolean("truE"));
360:                assertEquals(true, BooleanUtils.toBoolean("trUe"));
361:                assertEquals(true, BooleanUtils.toBoolean("trUE"));
362:                assertEquals(true, BooleanUtils.toBoolean("tRue"));
363:                assertEquals(true, BooleanUtils.toBoolean("tRuE"));
364:                assertEquals(true, BooleanUtils.toBoolean("tRUe"));
365:                assertEquals(true, BooleanUtils.toBoolean("tRUE"));
366:                assertEquals(true, BooleanUtils.toBoolean("TRUE"));
367:                assertEquals(true, BooleanUtils.toBoolean("TRUe"));
368:                assertEquals(true, BooleanUtils.toBoolean("TRuE"));
369:                assertEquals(true, BooleanUtils.toBoolean("TRue"));
370:                assertEquals(true, BooleanUtils.toBoolean("TrUE"));
371:                assertEquals(true, BooleanUtils.toBoolean("TrUe"));
372:                assertEquals(true, BooleanUtils.toBoolean("TruE"));
373:                assertEquals(true, BooleanUtils.toBoolean("True"));
374:                assertEquals(true, BooleanUtils.toBoolean("on"));
375:                assertEquals(true, BooleanUtils.toBoolean("oN"));
376:                assertEquals(true, BooleanUtils.toBoolean("On"));
377:                assertEquals(true, BooleanUtils.toBoolean("ON"));
378:                assertEquals(true, BooleanUtils.toBoolean("yes"));
379:                assertEquals(true, BooleanUtils.toBoolean("yeS"));
380:                assertEquals(true, BooleanUtils.toBoolean("yEs"));
381:                assertEquals(true, BooleanUtils.toBoolean("yES"));
382:                assertEquals(true, BooleanUtils.toBoolean("Yes"));
383:                assertEquals(true, BooleanUtils.toBoolean("YeS"));
384:                assertEquals(true, BooleanUtils.toBoolean("YEs"));
385:                assertEquals(true, BooleanUtils.toBoolean("YES"));
386:            }
387:
388:            public void test_toBoolean_String_String_String() {
389:                assertEquals(true, BooleanUtils.toBoolean((String) null, null,
390:                        "N"));
391:                assertEquals(false, BooleanUtils.toBoolean((String) null, "Y",
392:                        null));
393:                try {
394:                    BooleanUtils.toBooleanObject((String) null, "Y", "N", "U");
395:                    fail();
396:                } catch (IllegalArgumentException ex) {
397:                }
398:
399:                assertEquals(true, BooleanUtils.toBoolean("Y", "Y", "N"));
400:                assertEquals(false, BooleanUtils.toBoolean("N", "Y", "N"));
401:                try {
402:                    BooleanUtils.toBoolean(null, "Y", "N");
403:                    fail();
404:                } catch (IllegalArgumentException ex) {
405:                }
406:                try {
407:                    BooleanUtils.toBoolean("X", "Y", "N");
408:                    fail();
409:                } catch (IllegalArgumentException ex) {
410:                }
411:            }
412:
413:            //-----------------------------------------------------------------------
414:            public void test_toStringTrueFalse_Boolean() {
415:                assertEquals(null, BooleanUtils
416:                        .toStringTrueFalse((Boolean) null));
417:                assertEquals("true", BooleanUtils
418:                        .toStringTrueFalse(Boolean.TRUE));
419:                assertEquals("false", BooleanUtils
420:                        .toStringTrueFalse(Boolean.FALSE));
421:            }
422:
423:            public void test_toStringOnOff_Boolean() {
424:                assertEquals(null, BooleanUtils.toStringOnOff((Boolean) null));
425:                assertEquals("on", BooleanUtils.toStringOnOff(Boolean.TRUE));
426:                assertEquals("off", BooleanUtils.toStringOnOff(Boolean.FALSE));
427:            }
428:
429:            public void test_toStringYesNo_Boolean() {
430:                assertEquals(null, BooleanUtils.toStringYesNo((Boolean) null));
431:                assertEquals("yes", BooleanUtils.toStringYesNo(Boolean.TRUE));
432:                assertEquals("no", BooleanUtils.toStringYesNo(Boolean.FALSE));
433:            }
434:
435:            public void test_toString_Boolean_String_String_String() {
436:                assertEquals("U", BooleanUtils.toString((Boolean) null, "Y",
437:                        "N", "U"));
438:                assertEquals("Y", BooleanUtils.toString(Boolean.TRUE, "Y", "N",
439:                        "U"));
440:                assertEquals("N", BooleanUtils.toString(Boolean.FALSE, "Y",
441:                        "N", "U"));
442:            }
443:
444:            //-----------------------------------------------------------------------
445:            public void test_toStringTrueFalse_boolean() {
446:                assertEquals("true", BooleanUtils.toStringTrueFalse(true));
447:                assertEquals("false", BooleanUtils.toStringTrueFalse(false));
448:            }
449:
450:            public void test_toStringOnOff_boolean() {
451:                assertEquals("on", BooleanUtils.toStringOnOff(true));
452:                assertEquals("off", BooleanUtils.toStringOnOff(false));
453:            }
454:
455:            public void test_toStringYesNo_boolean() {
456:                assertEquals("yes", BooleanUtils.toStringYesNo(true));
457:                assertEquals("no", BooleanUtils.toStringYesNo(false));
458:            }
459:
460:            public void test_toString_boolean_String_String_String() {
461:                assertEquals("Y", BooleanUtils.toString(true, "Y", "N"));
462:                assertEquals("N", BooleanUtils.toString(false, "Y", "N"));
463:            }
464:
465:            //  testXor
466:            //  -----------------------------------------------------------------------
467:            public void testXor_primitive_nullInput() {
468:                final boolean[] b = null;
469:                try {
470:                    BooleanUtils.xor(b);
471:                    fail("Exception was not thrown for null input.");
472:                } catch (IllegalArgumentException ex) {
473:                }
474:            }
475:
476:            public void testXor_primitive_emptyInput() {
477:                try {
478:                    BooleanUtils.xor(new boolean[] {});
479:                    fail("Exception was not thrown for empty input.");
480:                } catch (IllegalArgumentException ex) {
481:                }
482:            }
483:
484:            public void testXor_primitive_validInput_2items() {
485:                assertTrue("True result for (true, true)", !BooleanUtils
486:                        .xor(new boolean[] { true, true }));
487:
488:                assertTrue("True result for (false, false)", !BooleanUtils
489:                        .xor(new boolean[] { false, false }));
490:
491:                assertTrue("False result for (true, false)", BooleanUtils
492:                        .xor(new boolean[] { true, false }));
493:
494:                assertTrue("False result for (false, true)", BooleanUtils
495:                        .xor(new boolean[] { false, true }));
496:            }
497:
498:            public void testXor_primitive_validInput_3items() {
499:                assertTrue("False result for (false, false, true)",
500:                        BooleanUtils.xor(new boolean[] { false, false, true }));
501:
502:                assertTrue("False result for (false, true, false)",
503:                        BooleanUtils.xor(new boolean[] { false, true, false }));
504:
505:                assertTrue("False result for (true, false, false)",
506:                        BooleanUtils.xor(new boolean[] { true, false, false }));
507:
508:                assertTrue("True result for (true, true, true)", !BooleanUtils
509:                        .xor(new boolean[] { true, true, true }));
510:
511:                assertTrue("True result for (false, false)", !BooleanUtils
512:                        .xor(new boolean[] { false, false, false }));
513:
514:                assertTrue("True result for (true, true, false)", !BooleanUtils
515:                        .xor(new boolean[] { true, true, false }));
516:
517:                assertTrue("True result for (true, false, true)", !BooleanUtils
518:                        .xor(new boolean[] { true, false, true }));
519:
520:                assertTrue("False result for (false, true, true)",
521:                        !BooleanUtils.xor(new boolean[] { false, true, true }));
522:            }
523:
524:            public void testXor_object_nullInput() {
525:                final Boolean[] b = null;
526:                try {
527:                    BooleanUtils.xor(b);
528:                    fail("Exception was not thrown for null input.");
529:                } catch (IllegalArgumentException ex) {
530:                }
531:            }
532:
533:            public void testXor_object_emptyInput() {
534:                try {
535:                    BooleanUtils.xor(new Boolean[] {});
536:                    fail("Exception was not thrown for empty input.");
537:                } catch (IllegalArgumentException ex) {
538:                }
539:            }
540:
541:            public void testXor_object_nullElementInput() {
542:                try {
543:                    BooleanUtils.xor(new Boolean[] { null });
544:                    fail("Exception was not thrown for null element input.");
545:                } catch (IllegalArgumentException ex) {
546:                }
547:            }
548:
549:            public void testXor_object_validInput_2items() {
550:                assertTrue("True result for (true, true)", !BooleanUtils.xor(
551:                        new Boolean[] { Boolean.TRUE, Boolean.TRUE })
552:                        .booleanValue());
553:
554:                assertTrue("True result for (false, false)", !BooleanUtils.xor(
555:                        new Boolean[] { Boolean.FALSE, Boolean.FALSE })
556:                        .booleanValue());
557:
558:                assertTrue("False result for (true, false)", BooleanUtils.xor(
559:                        new Boolean[] { Boolean.TRUE, Boolean.FALSE })
560:                        .booleanValue());
561:
562:                assertTrue("False result for (false, true)", BooleanUtils.xor(
563:                        new Boolean[] { Boolean.FALSE, Boolean.TRUE })
564:                        .booleanValue());
565:            }
566:
567:            public void testXor_object_validInput_3items() {
568:                assertTrue("False result for (false, false, true)",
569:                        BooleanUtils.xor(
570:                                new Boolean[] { Boolean.FALSE, Boolean.FALSE,
571:                                        Boolean.TRUE }).booleanValue());
572:
573:                assertTrue("False result for (false, true, false)",
574:                        BooleanUtils.xor(
575:                                new Boolean[] { Boolean.FALSE, Boolean.TRUE,
576:                                        Boolean.FALSE }).booleanValue());
577:
578:                assertTrue("False result for (true, false, false)",
579:                        BooleanUtils.xor(
580:                                new Boolean[] { Boolean.TRUE, Boolean.FALSE,
581:                                        Boolean.FALSE }).booleanValue());
582:
583:                assertTrue("True result for (true, true, true)", !BooleanUtils
584:                        .xor(
585:                                new Boolean[] { Boolean.TRUE, Boolean.TRUE,
586:                                        Boolean.TRUE }).booleanValue());
587:
588:                assertTrue("True result for (false, false)", !BooleanUtils.xor(
589:                        new Boolean[] { Boolean.FALSE, Boolean.FALSE,
590:                                Boolean.FALSE }).booleanValue());
591:
592:                assertTrue("True result for (true, true, false)", !BooleanUtils
593:                        .xor(
594:                                new Boolean[] { Boolean.TRUE, Boolean.TRUE,
595:                                        Boolean.FALSE }).booleanValue());
596:
597:                assertTrue("True result for (true, false, true)", !BooleanUtils
598:                        .xor(
599:                                new Boolean[] { Boolean.TRUE, Boolean.FALSE,
600:                                        Boolean.TRUE }).booleanValue());
601:
602:                assertTrue("False result for (false, true, true)",
603:                        !BooleanUtils.xor(
604:                                new Boolean[] { Boolean.FALSE, Boolean.TRUE,
605:                                        Boolean.TRUE }).booleanValue());
606:
607:            }
608:
609:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.