Source Code Cross Referenced for AssertTestFactoryUTest.java in  » Test-Coverage » GroboUtils » net » sourceforge » groboutils » junit » v1 » 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 » Test Coverage » GroboUtils » net.sourceforge.groboutils.junit.v1 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)AssertTestFactoryUTest.java
003:         *
004:         * Copyright (C) 2002-2004 Matt Albrecht
005:         * groboclown@users.sourceforge.net
006:         * http://groboutils.sourceforge.net
007:         *
008:         *  Permission is hereby granted, free of charge, to any person obtaining a
009:         *  copy of this software and associated documentation files (the "Software"),
010:         *  to deal in the Software without restriction, including without limitation
011:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
012:         *  and/or sell copies of the Software, and to permit persons to whom the
013:         *  Software is furnished to do so, subject to the following conditions:
014:         *
015:         *  The above copyright notice and this permission notice shall be included in
016:         *  all copies or substantial portions of the Software.
017:         *
018:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019:         *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020:         *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
021:         *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022:         *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023:         *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024:         *  DEALINGS IN THE SOFTWARE.
025:         */
026:
027:        package net.sourceforge.groboutils.junit.v1;
028:
029:        import java.util.Enumeration;
030:        import junit.framework.Test;
031:        import junit.framework.TestCase;
032:        import junit.framework.TestSuite;
033:        import junit.framework.TestResult;
034:        import junit.framework.TestFailure;
035:        import junit.framework.AssertionFailedError;
036:        import junit.framework.Assert;
037:
038:        /**
039:         * Tests the AssertTestFactory class.
040:         *
041:         * @author    Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042:         * @since     July 26, 2002
043:         * @version   $Date: 2004/01/09 20:32:26 $
044:         */
045:        public class AssertTestFactoryUTest extends TestCase {
046:            //-------------------------------------------------------------------------
047:            // Standard JUnit Class-specific declarations
048:
049:            private static final Class THIS_CLASS = AssertTestFactoryUTest.class;
050:
051:            //    private static final IJUnitDocumentor LOG = (new JUnitLog(THIS_CLASS)).getDocumentor();
052:
053:            public AssertTestFactoryUTest(String name) {
054:                super (name);
055:            }
056:
057:            //-------------------------------------------------------------------------
058:            // Tests
059:
060:            public void testConstructor1() {
061:                new AssertTestFactory(null);
062:            }
063:
064:            public void testConstructor2() {
065:                new AssertTestFactory("help");
066:            }
067:
068:            public void testSetName1() {
069:                AssertTestFactory atf = new AssertTestFactory();
070:                assertNull("Factory did not return a null name.", atf.getName());
071:
072:                AssertTestFactory.InnerTest it = atf.createAssertTrue(true);
073:                assertNull("InnerTest did not have name be set to null.", it
074:                        .getName());
075:            }
076:
077:            public void testSetName2() {
078:                AssertTestFactory atf = new AssertTestFactory("a");
079:                assertEquals("Factory did not return correct name.", "a", atf
080:                        .getName());
081:
082:                AssertTestFactory.InnerTest it = atf.createAssertTrue(true);
083:                assertEquals("InnerTest did not have name be set correctly.",
084:                        "a", it.getName());
085:            }
086:
087:            public void testSetName3() {
088:                AssertTestFactory atf = new AssertTestFactory();
089:                atf.setName("b");
090:                assertEquals("Factory did not return correct name.", "b", atf
091:                        .getName());
092:
093:                AssertTestFactory.InnerTest it = atf.createAssertTrue(true);
094:                assertEquals("InnerTest did not have name be set correctly.",
095:                        "b", it.getName());
096:            }
097:
098:            public void testSetName4() {
099:                AssertTestFactory atf = new AssertTestFactory("0");
100:
101:                AssertTestFactory.InnerTest it = atf.createAssertTrue(true);
102:                assertEquals("InnerTest did not have name be set correctly.",
103:                        "0", it.getName());
104:
105:                atf.setName("c");
106:                assertEquals("Factory did not return correct name.", "c", atf
107:                        .getName());
108:
109:                it = atf.createAssertTrue(true);
110:                assertEquals("InnerTest did not have name be set correctly.",
111:                        "c", it.getName());
112:            }
113:
114:            // ----------
115:
116:            public void testNameIndex1() {
117:                AssertTestFactory atf = new AssertTestFactory("aa", false);
118:                assertEquals("Factory did not return correct name.", "aa", atf
119:                        .getName());
120:
121:                AssertTestFactory.InnerTest it = atf.createAssertTrue(true);
122:                assertEquals("InnerTest did not have name be set correctly.",
123:                        "aa", it.getName());
124:            }
125:
126:            public void testNameIndex2() {
127:                AssertTestFactory atf = new AssertTestFactory("bb", true);
128:                assertEquals("Factory did not return correct name.", "bb", atf
129:                        .getName());
130:
131:                AssertTestFactory.InnerTest it = atf.createAssertTrue(true);
132:                assertEquals("InnerTest did not have name be set correctly.",
133:                        "bb1", it.getName());
134:
135:                it = atf.createAssertTrue(true);
136:                assertEquals("InnerTest did not have name be set correctly.",
137:                        "bb2", it.getName());
138:
139:                atf.setName("cc");
140:                assertEquals("Factory did not return correct name.", "cc", atf
141:                        .getName());
142:
143:                it = atf.createAssertTrue(true);
144:                assertEquals("InnerTest did not have name be set correctly.",
145:                        "cc3", it.getName());
146:            }
147:
148:            public void testNameIndex3() {
149:                AssertTestFactory atf = new AssertTestFactory("ca", false);
150:                assertFalse("Did not set the use-index value to false.", atf
151:                        .getUseIndexWithName());
152:
153:                AssertTestFactory.InnerTest it = atf.createAssertTrue(true);
154:                assertEquals("InnerTest did not have name set correctly.",
155:                        "ca", it.getName());
156:
157:                atf.setUseIndexWithName(true);
158:                assertTrue("Did not set the use-index value to true.", atf
159:                        .getUseIndexWithName());
160:
161:                it = atf.createAssertTrue(true);
162:                assertEquals("InnerTest did not have name be set correctly.",
163:                        "ca1", it.getName());
164:
165:                atf.setUseIndexWithName(false);
166:                assertFalse("Did not set the use-index value to false.", atf
167:                        .getUseIndexWithName());
168:
169:                it = atf.createAssertTrue(true);
170:                assertEquals("InnerTest did not have name be set correctly.",
171:                        "ca", it.getName());
172:
173:                atf.setUseIndexWithName(true);
174:                assertTrue("Did not set the use-index value to true.", atf
175:                        .getUseIndexWithName());
176:
177:                it = atf.createAssertTrue(true);
178:                assertEquals("InnerTest did not have name be set correctly.",
179:                        "ca2", it.getName());
180:            }
181:
182:            // ----------
183:
184:            public void testCreateAssertTrue1() {
185:                AssertTestFactory atf = createAssertTestFactory();
186:                assertCleanResult(atf.createAssertTrue("message", true));
187:            }
188:
189:            public void testCreateAssertTrue2() {
190:                AssertTestFactory atf = createAssertTestFactory();
191:                AssertionFailedError assertError = null;
192:                try {
193:                    Assert.assertTrue("message", false);
194:                } catch (AssertionFailedError e) {
195:                    assertError = e;
196:                }
197:
198:                assertIsFailure(atf.createAssertTrue("message", false),
199:                        assertError);
200:            }
201:
202:            public void testCreateAssertTrue3() {
203:                AssertTestFactory atf = createAssertTestFactory();
204:
205:                assertCleanResult(atf.createAssertTrue(true));
206:            }
207:
208:            public void testCreateAssertTrue4() {
209:                AssertTestFactory atf = createAssertTestFactory();
210:                AssertionFailedError assertError = null;
211:                try {
212:                    Assert.assertTrue(false);
213:                } catch (AssertionFailedError e) {
214:                    assertError = e;
215:                }
216:
217:                assertIsFailure(atf.createAssertTrue(false), assertError);
218:            }
219:
220:            // ----------
221:
222:            public void testSoftFail1() {
223:                AssertTestFactory atf = createAssertTestFactory();
224:                AssertionFailedError assertError = null;
225:                try {
226:                    Assert.fail("message");
227:                } catch (AssertionFailedError e) {
228:                    assertError = e;
229:                }
230:
231:                assertIsFailure(atf.createFail("message"), assertError);
232:            }
233:
234:            public void testSoftFail2() {
235:                AssertTestFactory atf = createAssertTestFactory();
236:                AssertionFailedError assertError = null;
237:                try {
238:                    Assert.fail();
239:                } catch (AssertionFailedError e) {
240:                    assertError = e;
241:                }
242:
243:                assertIsFailure(atf.createFail(), assertError);
244:            }
245:
246:            // ----------
247:
248:            public void testCreateAssertEquals1() {
249:                AssertTestFactory atf = createAssertTestFactory();
250:
251:                assertCleanResult(atf.createAssertEquals("message", "a", "a"));
252:            }
253:
254:            public void testCreateAssertEquals2() {
255:                AssertTestFactory atf = createAssertTestFactory();
256:                AssertionFailedError assertError = null;
257:                try {
258:                    Assert.assertEquals("message", "a", "b");
259:                } catch (AssertionFailedError e) {
260:                    assertError = e;
261:                }
262:
263:                assertIsFailure(atf.createAssertEquals("message", "a", "b"),
264:                        assertError);
265:            }
266:
267:            public void testCreateAssertEquals3() {
268:                AssertTestFactory atf = createAssertTestFactory();
269:
270:                assertCleanResult(atf.createAssertEquals("a", "a"));
271:            }
272:
273:            public void testCreateAssertEquals4() {
274:                AssertTestFactory atf = createAssertTestFactory();
275:                AssertionFailedError assertError = null;
276:                try {
277:                    Assert.assertEquals("a", "b");
278:                } catch (AssertionFailedError e) {
279:                    assertError = e;
280:                }
281:
282:                assertIsFailure(atf.createAssertEquals("a", "b"), assertError);
283:            }
284:
285:            // ----------
286:
287:            public void testCreateAssertEquals5() {
288:                AssertTestFactory atf = createAssertTestFactory();
289:
290:                assertCleanResult(atf.createAssertEquals("message", 0.0, 0.1,
291:                        0.2));
292:            }
293:
294:            public void testCreateAssertEquals6() {
295:                AssertTestFactory atf = createAssertTestFactory();
296:                AssertionFailedError assertError = null;
297:                try {
298:                    Assert.assertEquals("message", 0.0, 0.2, 0.1);
299:                } catch (AssertionFailedError e) {
300:                    assertError = e;
301:                }
302:
303:                assertIsFailure(atf
304:                        .createAssertEquals("message", 0.0, 0.2, 0.1),
305:                        assertError);
306:            }
307:
308:            public void testCreateAssertEquals7() {
309:                AssertTestFactory atf = createAssertTestFactory();
310:
311:                assertCleanResult(atf.createAssertEquals(0.0, 0.1, 0.2));
312:            }
313:
314:            public void testCreateAssertEquals8() {
315:                AssertTestFactory atf = createAssertTestFactory();
316:                AssertionFailedError assertError = null;
317:                try {
318:                    Assert.assertEquals(0.0, 0.2, 0.1);
319:                } catch (AssertionFailedError e) {
320:                    assertError = e;
321:                }
322:
323:                assertIsFailure(atf.createAssertEquals(0.0, 0.2, 0.1),
324:                        assertError);
325:            }
326:
327:            // ----------
328:
329:            public void testCreateAssertEquals9() {
330:                AssertTestFactory atf = createAssertTestFactory();
331:
332:                assertCleanResult(atf.createAssertEquals("message", 0.0f, 0.1f,
333:                        0.2f));
334:            }
335:
336:            public void testCreateAssertEquals10() {
337:                AssertTestFactory atf = createAssertTestFactory();
338:                AssertionFailedError assertError = null;
339:                try {
340:                    Assert.assertEquals("message", 0.0f, 0.2f, 0.1f);
341:                } catch (AssertionFailedError e) {
342:                    assertError = e;
343:                }
344:
345:                assertIsFailure(atf.createAssertEquals("message", 0.0f, 0.2f,
346:                        0.1f), assertError);
347:            }
348:
349:            public void testCreateAssertEquals11() {
350:                AssertTestFactory atf = createAssertTestFactory();
351:
352:                assertCleanResult(atf.createAssertEquals(0.0f, 0.1f, 0.2f));
353:            }
354:
355:            public void testCreateAssertEquals12() {
356:                AssertTestFactory atf = createAssertTestFactory();
357:                AssertionFailedError assertError = null;
358:                try {
359:                    Assert.assertEquals(0.0f, 0.2f, 0.1f);
360:                } catch (AssertionFailedError e) {
361:                    assertError = e;
362:                }
363:
364:                assertIsFailure(atf.createAssertEquals(0.0f, 0.2f, 0.1f),
365:                        assertError);
366:            }
367:
368:            // ----------
369:
370:            public void testCreateAssertEquals13() {
371:                AssertTestFactory atf = createAssertTestFactory();
372:
373:                assertCleanResult(atf.createAssertEquals("message", 0L, 0L));
374:            }
375:
376:            public void testCreateAssertEquals14() {
377:                AssertTestFactory atf = createAssertTestFactory();
378:                AssertionFailedError assertError = null;
379:                try {
380:                    Assert.assertEquals("message", 0L, 1L);
381:                } catch (AssertionFailedError e) {
382:                    assertError = e;
383:                }
384:
385:                assertIsFailure(atf.createAssertEquals("message", 0L, 1L),
386:                        assertError);
387:            }
388:
389:            public void testCreateAssertEquals15() {
390:                AssertTestFactory atf = createAssertTestFactory();
391:
392:                assertCleanResult(atf.createAssertEquals(0L, 0L));
393:            }
394:
395:            public void testCreateAssertEquals16() {
396:                AssertTestFactory atf = createAssertTestFactory();
397:                AssertionFailedError assertError = null;
398:                try {
399:                    Assert.assertEquals(0L, 1L);
400:                } catch (AssertionFailedError e) {
401:                    assertError = e;
402:                }
403:
404:                assertIsFailure(atf.createAssertEquals(0L, 1L), assertError);
405:            }
406:
407:            // ----------
408:
409:            public void testCreateAssertEquals17() {
410:                AssertTestFactory atf = createAssertTestFactory();
411:
412:                assertCleanResult(atf.createAssertEquals("message", true, true));
413:            }
414:
415:            public void testCreateAssertEquals18() {
416:                AssertTestFactory atf = createAssertTestFactory();
417:                AssertionFailedError assertError = null;
418:                try {
419:                    Assert.assertEquals("message", true, false);
420:                } catch (AssertionFailedError e) {
421:                    assertError = e;
422:                }
423:
424:                assertIsFailure(atf.createAssertEquals("message", true, false),
425:                        assertError);
426:            }
427:
428:            public void testCreateAssertEquals19() {
429:                AssertTestFactory atf = createAssertTestFactory();
430:
431:                assertCleanResult(atf.createAssertEquals(false, false));
432:            }
433:
434:            public void testCreateAssertEquals20() {
435:                AssertTestFactory atf = createAssertTestFactory();
436:                AssertionFailedError assertError = null;
437:                try {
438:                    Assert.assertEquals(false, true);
439:                } catch (AssertionFailedError e) {
440:                    assertError = e;
441:                }
442:
443:                assertIsFailure(atf.createAssertEquals(false, true),
444:                        assertError);
445:            }
446:
447:            // ----------
448:
449:            public void testCreateAssertEquals21() {
450:                AssertTestFactory atf = createAssertTestFactory();
451:
452:                assertCleanResult(atf.createAssertEquals("message", (byte) 0,
453:                        (byte) 0));
454:            }
455:
456:            public void testCreateAssertEquals22() {
457:                AssertTestFactory atf = createAssertTestFactory();
458:                AssertionFailedError assertError = null;
459:                try {
460:                    Assert.assertEquals("message", (byte) 0, (byte) 1);
461:                } catch (AssertionFailedError e) {
462:                    assertError = e;
463:                }
464:
465:                ;
466:
467:                assertIsFailure(atf.createAssertEquals("message", (byte) 0,
468:                        (byte) 1), assertError);
469:            }
470:
471:            public void testCreateAssertEquals23() {
472:                AssertTestFactory atf = createAssertTestFactory();
473:
474:                assertCleanResult(atf.createAssertEquals((byte) 0, (byte) 0));
475:            }
476:
477:            public void testCreateAssertEquals24() {
478:                AssertTestFactory atf = createAssertTestFactory();
479:                AssertionFailedError assertError = null;
480:                try {
481:                    Assert.assertEquals((byte) 0, (byte) 1);
482:                } catch (AssertionFailedError e) {
483:                    assertError = e;
484:                }
485:
486:                assertIsFailure(atf.createAssertEquals((byte) 0, (byte) 1),
487:                        assertError);
488:            }
489:
490:            // ----------
491:
492:            public void testCreateAssertEquals25() {
493:                AssertTestFactory atf = createAssertTestFactory();
494:
495:                assertCleanResult(atf.createAssertEquals("message", 'a', 'a'));
496:            }
497:
498:            public void testCreateAssertEquals26() {
499:                AssertTestFactory atf = createAssertTestFactory();
500:                AssertionFailedError assertError = null;
501:                try {
502:                    Assert.assertEquals("message", 'a', 'b');
503:                } catch (AssertionFailedError e) {
504:                    assertError = e;
505:                }
506:
507:                assertIsFailure(atf.createAssertEquals("message", 'a', 'b'),
508:                        assertError);
509:            }
510:
511:            public void testCreateAssertEquals27() {
512:                AssertTestFactory atf = createAssertTestFactory();
513:
514:                assertCleanResult(atf.createAssertEquals('a', 'a'));
515:            }
516:
517:            public void testCreateAssertEquals28() {
518:                AssertTestFactory atf = createAssertTestFactory();
519:                AssertionFailedError assertError = null;
520:                try {
521:                    Assert.assertEquals('a', 'b');
522:                } catch (AssertionFailedError e) {
523:                    assertError = e;
524:                }
525:
526:                assertIsFailure(atf.createAssertEquals('a', 'b'), assertError);
527:            }
528:
529:            // ----------
530:
531:            public void testCreateAssertEquals29() {
532:                AssertTestFactory atf = createAssertTestFactory();
533:
534:                assertCleanResult(atf.createAssertEquals("message", (short) 0,
535:                        (short) 0));
536:            }
537:
538:            public void testCreateAssertEquals30() {
539:                AssertTestFactory atf = createAssertTestFactory();
540:                AssertionFailedError assertError = null;
541:                try {
542:                    Assert.assertEquals("message", (short) 0, (short) 1);
543:                } catch (AssertionFailedError e) {
544:                    assertError = e;
545:                }
546:
547:                assertIsFailure(atf.createAssertEquals("message", (short) 0,
548:                        (short) 1), assertError);
549:            }
550:
551:            public void testCreateAssertEquals31() {
552:                AssertTestFactory atf = createAssertTestFactory();
553:
554:                assertCleanResult(atf.createAssertEquals((short) 0, (short) 0));
555:            }
556:
557:            public void testCreateAssertEquals32() {
558:                AssertTestFactory atf = createAssertTestFactory();
559:                AssertionFailedError assertError = null;
560:                try {
561:                    Assert.assertEquals((short) 0, (short) 1);
562:                } catch (AssertionFailedError e) {
563:                    assertError = e;
564:                }
565:
566:                assertIsFailure(atf.createAssertEquals((short) 0, (short) 1),
567:                        assertError);
568:            }
569:
570:            // ----------
571:
572:            public void testCreateAssertEquals33() {
573:                AssertTestFactory atf = createAssertTestFactory();
574:
575:                assertCleanResult(atf.createAssertEquals("message", 0, 0));
576:            }
577:
578:            public void testCreateAssertEquals34() {
579:                AssertTestFactory atf = createAssertTestFactory();
580:                AssertionFailedError assertError = null;
581:                try {
582:                    Assert.assertEquals("message", 0, 1);
583:                } catch (AssertionFailedError e) {
584:                    assertError = e;
585:                }
586:
587:                assertIsFailure(atf.createAssertEquals("message", 0, 1),
588:                        assertError);
589:            }
590:
591:            public void testCreateAssertEquals35() {
592:                AssertTestFactory atf = createAssertTestFactory();
593:
594:                assertCleanResult(atf.createAssertEquals(0, 0));
595:            }
596:
597:            public void testCreateAssertEquals36() {
598:                AssertTestFactory atf = createAssertTestFactory();
599:                AssertionFailedError assertError = null;
600:                try {
601:                    Assert.assertEquals(0, 1);
602:                } catch (AssertionFailedError e) {
603:                    assertError = e;
604:                }
605:
606:                assertIsFailure(atf.createAssertEquals(0, 1), assertError);
607:            }
608:
609:            // ----------
610:
611:            public void testCreateAssertNotNull1() {
612:                AssertTestFactory atf = createAssertTestFactory();
613:
614:                assertCleanResult(atf.createAssertNotNull("message", "a"));
615:            }
616:
617:            public void testCreateAssertNotNull2() {
618:                AssertTestFactory atf = createAssertTestFactory();
619:                AssertionFailedError assertError = null;
620:                try {
621:                    Assert.assertNotNull("message", null);
622:                } catch (AssertionFailedError e) {
623:                    assertError = e;
624:                }
625:
626:                assertIsFailure(atf.createAssertNotNull("message", null),
627:                        assertError);
628:            }
629:
630:            public void testCreateAssertNotNull3() {
631:                AssertTestFactory atf = createAssertTestFactory();
632:
633:                assertCleanResult(atf.createAssertNotNull("a"));
634:            }
635:
636:            public void testCreateAssertNotNull4() {
637:                AssertTestFactory atf = createAssertTestFactory();
638:                AssertionFailedError assertError = null;
639:                try {
640:                    Assert.assertNotNull(null);
641:                } catch (AssertionFailedError e) {
642:                    assertError = e;
643:                }
644:
645:                assertIsFailure(atf.createAssertNotNull(null), assertError);
646:            }
647:
648:            // ----------
649:
650:            public void testCreateAssertNull1() {
651:                AssertTestFactory atf = createAssertTestFactory();
652:
653:                assertCleanResult(atf.createAssertNull("message", null));
654:            }
655:
656:            public void testCreateAssertNull2() {
657:                AssertTestFactory atf = createAssertTestFactory();
658:                AssertionFailedError assertError = null;
659:                try {
660:                    Assert.assertNull("message", "a");
661:                } catch (AssertionFailedError e) {
662:                    assertError = e;
663:                }
664:
665:                assertIsFailure(atf.createAssertNull("message", "a"),
666:                        assertError);
667:            }
668:
669:            public void testCreateAssertNull3() {
670:                AssertTestFactory atf = createAssertTestFactory();
671:
672:                assertCleanResult(atf.createAssertNull(null));
673:            }
674:
675:            public void testCreateAssertNull4() {
676:                AssertTestFactory atf = createAssertTestFactory();
677:                AssertionFailedError assertError = null;
678:                try {
679:                    Assert.assertNull("a");
680:                } catch (AssertionFailedError e) {
681:                    assertError = e;
682:                }
683:
684:                assertIsFailure(atf.createAssertNull("a"), assertError);
685:            }
686:
687:            // ----------
688:
689:            public void testCreateAssertSame1() {
690:                AssertTestFactory atf = createAssertTestFactory();
691:
692:                Object a1 = new Object();
693:                Object a2 = new Object();
694:
695:                assertCleanResult(atf.createAssertSame("message", a1, a1));
696:            }
697:
698:            public void testCreateAssertSame2() {
699:                AssertTestFactory atf = createAssertTestFactory();
700:                AssertionFailedError assertError = null;
701:                Object a1 = new Object();
702:                Object a2 = new Object();
703:
704:                try {
705:                    Assert.assertSame("message", a1, a2);
706:                } catch (AssertionFailedError e) {
707:                    assertError = e;
708:                }
709:
710:                assertIsFailure(atf.createAssertSame("message", a1, a2),
711:                        assertError);
712:            }
713:
714:            public void testCreateAssertSame3() {
715:                AssertTestFactory atf = createAssertTestFactory();
716:                Object a1 = new Object();
717:                Object a2 = new Object();
718:
719:                assertCleanResult(atf.createAssertSame(a1, a1));
720:            }
721:
722:            public void testCreateAssertSame4() {
723:                AssertTestFactory atf = createAssertTestFactory();
724:                AssertionFailedError assertError = null;
725:                Object a1 = new Object();
726:                Object a2 = new Object();
727:
728:                try {
729:                    Assert.assertSame(a1, a2);
730:                } catch (AssertionFailedError e) {
731:                    assertError = e;
732:                }
733:
734:                assertIsFailure(atf.createAssertSame(a1, a2), assertError);
735:            }
736:
737:            // ----------
738:
739:            public void testCreateAssertNotSame1() {
740:                AssertTestFactory atf = createAssertTestFactory();
741:
742:                Object a1 = new Object();
743:                Object a2 = new Object();
744:
745:                assertCleanResult(atf.createAssertNotSame("message", a1, a2));
746:            }
747:
748:            public void testCreateAssertNotSame2() {
749:                AssertTestFactory atf = createAssertTestFactory();
750:                AssertionFailedError assertError = null;
751:                Object a1 = new Object();
752:                Object a2 = new Object();
753:
754:                try {
755:                    Assert.assertNotSame("message", a1, a1);
756:                } catch (AssertionFailedError e) {
757:                    assertError = e;
758:                }
759:
760:                assertIsFailure(atf.createAssertNotSame("message", a1, a1),
761:                        assertError);
762:            }
763:
764:            public void testCreateAssertNotSame3() {
765:                AssertTestFactory atf = createAssertTestFactory();
766:                Object a1 = new Object();
767:                Object a2 = new Object();
768:
769:                assertCleanResult(atf.createAssertNotSame(a1, a2));
770:            }
771:
772:            public void testCreateAssertNotSame4() {
773:                AssertTestFactory atf = createAssertTestFactory();
774:                AssertionFailedError assertError = null;
775:                Object a1 = new Object();
776:                Object a2 = new Object();
777:
778:                try {
779:                    Assert.assertNotSame(a1, a1);
780:                } catch (AssertionFailedError e) {
781:                    assertError = e;
782:                }
783:
784:                assertIsFailure(atf.createAssertNotSame(a1, a1), assertError);
785:            }
786:
787:            //-------------------------------------------------------------------------
788:            // Helpers
789:
790:            protected TestResult createTestResult(Test t) {
791:                TestResult tr = new TestResult();
792:                t.run(tr);
793:                return tr;
794:            }
795:
796:            protected AssertTestFactory createAssertTestFactory() {
797:                return new AssertTestFactory("name");
798:            }
799:
800:            protected void assertIsFailure(Test t, AssertionFailedError orig) {
801:                TestResult tr = createTestResult(t);
802:                AssertionFailedError softError = getFailure(tr);
803:                String origMsg = orig.getMessage();
804:                String newMsg = softError.getMessage();
805:                if (origMsg == null) {
806:                    assertTrue("From null message to named message ('" + newMsg
807:                            + "') didn't work right.", newMsg != null
808:                            && (newMsg.equals("name: null") || newMsg
809:                                    .equals("name: <null>")));
810:                    return;
811:                }
812:                if (origMsg.equals(newMsg)) {
813:                    return;
814:                }
815:                if (origMsg.startsWith("<")) {
816:                    origMsg = origMsg.substring(1);
817:                }
818:                if (newMsg.endsWith(origMsg)) {
819:                    return;
820:                }
821:
822:                fail("Assert message ('" + orig.getMessage()
823:                        + "') doesn't look like soft message ('"
824:                        + softError.getMessage() + "').");
825:            }
826:
827:            protected AssertionFailedError getFailure( TestResult tr )
828:    {
829:        Enumeration enum = tr.failures();
830:        assertNotNull(
831:            "Failure list is null",
832:            enum );
833:        assertTrue(
834:            "Does not contain failures.",
835:            enum.hasMoreElements() );
836:        TestFailure tf = (TestFailure)enum.nextElement();
837:        AssertionFailedError afe = (AssertionFailedError)tf.thrownException();
838:        assertTrue(
839:            "Has more than one failure.",
840:            !enum.hasMoreElements() );
841:        assertNotNull(
842:            "Has null failure.",
843:            afe );
844:        return afe;
845:    }
846:
847:            protected void assertCleanResult(Test t) {
848:                TestResult tr = createTestResult(t);
849:                assertEquals("Has errors.", 0, tr.errorCount());
850:
851:                assertEquals("Has failures.", 0, tr.failureCount());
852:            }
853:
854:            //-------------------------------------------------------------------------
855:            // Standard JUnit declarations
856:
857:            public static Test suite() {
858:                TestSuite suite = new TestSuite(THIS_CLASS);
859:
860:                return suite;
861:            }
862:
863:            public static void main(String[] args) {
864:                String[] name = { THIS_CLASS.getName() };
865:
866:                // junit.textui.TestRunner.main( name );
867:                // junit.swingui.TestRunner.main( name );
868:
869:                junit.textui.TestRunner.main(name);
870:            }
871:
872:            /**
873:             * 
874:             * @exception Exception thrown under any exceptional condition.
875:             */
876:            protected void setUp() throws Exception {
877:                super .setUp();
878:
879:                // set ourself up
880:            }
881:
882:            /**
883:             * 
884:             * @exception Exception thrown under any exceptional condition.
885:             */
886:            protected void tearDown() throws Exception {
887:                // tear ourself down
888:
889:                super.tearDown();
890:            }
891:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.