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


001:        /*
002:         * @(#)ClassRecordUTest.java
003:         *
004:         * Copyright (C) 2003 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.codecoverage.v2.datastore;
028:
029:        import junit.framework.Test;
030:        import junit.framework.TestCase;
031:        import junit.framework.TestSuite;
032:        import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
033:        import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
034:        import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData;
035:        import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
036:
037:        /**
038:         * Tests the ClassRecord class.
039:         *
040:         * @author    Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
041:         * @version   $Date: 2004/04/15 05:48:28 $
042:         * @since     January 22, 2003
043:         */
044:        public class ClassRecordUTest extends TestCase {
045:            //-------------------------------------------------------------------------
046:            // Standard JUnit Class-specific declarations
047:
048:            private static final Class THIS_CLASS = ClassRecordUTest.class;
049:            private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
050:
051:            public ClassRecordUTest(String name) {
052:                super (name);
053:            }
054:
055:            //-------------------------------------------------------------------------
056:            // Tests
057:
058:            public void testConstructor1() {
059:                try {
060:                    new ClassRecord(null, 0L, null, null, null);
061:                } catch (IllegalArgumentException ex) {
062:                    // test exception
063:                }
064:            }
065:
066:            public void testConstructor2() {
067:                try {
068:                    new ClassRecord("A", 0L, null, null, null);
069:                } catch (IllegalArgumentException ex) {
070:                    // test exception
071:                }
072:            }
073:
074:            public void testConstructor3() {
075:                try {
076:                    new ClassRecord(null, 0L, null, new String[0], null);
077:                } catch (IllegalArgumentException ex) {
078:                    // test exception
079:                }
080:            }
081:
082:            public void testConstructor4() {
083:                try {
084:                    new ClassRecord(null, 0L, null, null,
085:                            createAnalysisModuleSet(4));
086:                } catch (IllegalArgumentException ex) {
087:                    // test exception
088:                }
089:            }
090:
091:            public void testConstructor5() {
092:                try {
093:                    new ClassRecord("A", 0L, null, null,
094:                            createAnalysisModuleSet(4));
095:                } catch (IllegalArgumentException ex) {
096:                    // test exception
097:                }
098:            }
099:
100:            public void testConstructor6() {
101:                try {
102:                    new ClassRecord(null, 0L, "a", new String[0],
103:                            createAnalysisModuleSet(4));
104:                } catch (IllegalArgumentException ex) {
105:                    // test exception
106:                }
107:            }
108:
109:            public void testConstructor7() {
110:                try {
111:                    new ClassRecord("A", 0L, "a", new String[1],
112:                            createAnalysisModuleSet(4));
113:                } catch (IllegalArgumentException ex) {
114:                    // test exception
115:                }
116:            }
117:
118:            public void testConstructor8() {
119:                new ClassRecord("A", 0L, "a", new String[0],
120:                        createAnalysisModuleSet(4));
121:            }
122:
123:            public void testConstructor9() {
124:                new ClassRecord("A", 0L, "a", new String[] { "m()V" },
125:                        createAnalysisModuleSet(4));
126:            }
127:
128:            public void testConstructor10() {
129:                try {
130:                    new ClassRecord("A", 0L, "a",
131:                            new String[Short.MAX_VALUE + 1],
132:                            createAnalysisModuleSet(4));
133:                    fail("Did not throw IllegalStateException.");
134:                } catch (IllegalStateException ex) {
135:                    assertTrue(
136:                            "Did not raise exception for the correct reason.",
137:                            ex.getMessage().toLowerCase().indexOf(
138:                                    "too many methods") >= 0);
139:                }
140:
141:            }
142:
143:            public void testGetClassName1() {
144:                ClassRecord cr = new ClassRecord("A", 0L, "a",
145:                        new String[] { "m()V" }, createAnalysisModuleSet(4));
146:                assertEquals("Did not return correct class name.", "A", cr
147:                        .getClassName());
148:            }
149:
150:            public void testGetClassCRC1() {
151:                ClassRecord cr = new ClassRecord("A", 100L, "a",
152:                        new String[] { "m()V" }, createAnalysisModuleSet(4));
153:                assertEquals("Did not return correct class crc.", 100L, cr
154:                        .getClassCRC());
155:            }
156:
157:            public void testGetClassSignature1() {
158:                ClassRecord cr = new ClassRecord("A", -10L, "a",
159:                        new String[] { "m()V" }, createAnalysisModuleSet(4));
160:                assertEquals("Did not return correct class name.", "A--10", cr
161:                        .getClassSignature());
162:            }
163:
164:            public void testGetAnalysisModuleSet1() {
165:                ClassRecord cr = new ClassRecord("A", -10L, "a",
166:                        new String[] { "m()V" }, createAnalysisModuleSet(4));
167:                AnalysisModuleSet ams = cr.getAnalysisModuleSet();
168:                assertEquals("Did not return the correct number of modules.",
169:                        4, ams.getAnalysisModuleCount());
170:            }
171:
172:            public void testGetMethods1() {
173:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[0],
174:                        createAnalysisModuleSet(4));
175:                String m[] = cr.getMethods();
176:                assertEquals("Did not return correct method set.", 0, m.length);
177:            }
178:
179:            public void testGetMethods2() {
180:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
181:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
182:                String m[] = cr.getMethods();
183:                assertEquals("Did not return correct method set length.", 3,
184:                        m.length);
185:                assertEquals(
186:                        "Did not return correct method [0], or resorted the list.",
187:                        "m1()V", m[0]);
188:                assertEquals(
189:                        "Did not return correct method [1], or resorted the list.",
190:                        "m2()V", m[1]);
191:                assertEquals(
192:                        "Did not return correct method [2], or resorted the list.",
193:                        "m3()V", m[2]);
194:            }
195:
196:            public void testGetMethodIndex1() {
197:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
198:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
199:                try {
200:                    cr.getMethodIndex(null);
201:                    fail("Did not throw IllegalArgumentException.");
202:                } catch (IllegalArgumentException ex) {
203:                    // test exception
204:                }
205:            }
206:
207:            public void testGetMethodIndex2() {
208:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
209:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
210:                assertEquals("Did not identify unknown method as not found.",
211:                        (short) -1, cr.getMethodIndex("m0()V"));
212:            }
213:
214:            public void testGetMethodIndex3() {
215:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
216:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
217:                assertEquals(
218:                        "Did not keep the original order, or couldn't find the index [0].",
219:                        (short) 0, cr.getMethodIndex("m1()V"));
220:                assertEquals(
221:                        "Did not keep the original order, or couldn't find the index [1].",
222:                        (short) 1, cr.getMethodIndex("m2()V"));
223:                assertEquals(
224:                        "Did not keep the original order, or couldn't find the index [2].",
225:                        (short) 2, cr.getMethodIndex("m3()V"));
226:            }
227:
228:            public void testGetMethodCount1() {
229:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
230:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
231:                assertEquals("Did not return correct count.", 3, cr
232:                        .getMethodCount());
233:            }
234:
235:            public void testGetMethodCount2() {
236:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[0],
237:                        createAnalysisModuleSet(4));
238:                assertEquals("Did not return correct count.", 0, cr
239:                        .getMethodCount());
240:            }
241:
242:            public void testGetMethodAt1() {
243:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[0],
244:                        createAnalysisModuleSet(4));
245:                try {
246:                    cr.getMethodAt((short) 0);
247:                    fail("Did not throw IllegalArgumentException.");
248:                } catch (IllegalArgumentException ex) {
249:                    // test exception
250:                }
251:            }
252:
253:            public void testGetMethodAt2a() {
254:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
255:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
256:                try {
257:                    cr.getMethodAt((short) 3);
258:                    fail("Did not throw IllegalArgumentException.");
259:                } catch (IllegalArgumentException ex) {
260:                    // test exception
261:                }
262:            }
263:
264:            public void testGetMethodAt2b() {
265:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
266:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
267:                try {
268:                    cr.getMethodAt((short) -1);
269:                    fail("Did not throw IllegalArgumentException.");
270:                } catch (IllegalArgumentException ex) {
271:                    // test exception
272:                }
273:            }
274:
275:            public void testGetMethodAt2c() {
276:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
277:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
278:                try {
279:                    cr.getMethodAt((short) 4);
280:                    fail("Did not throw IllegalArgumentException.");
281:                } catch (IllegalArgumentException ex) {
282:                    // test exception
283:                }
284:            }
285:
286:            public void testGetMethodAt3() {
287:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
288:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
289:                assertEquals("Did not return correct method name [0].",
290:                        "m1()V", cr.getMethodAt((short) 0));
291:                assertEquals("Did not return correct method name [1].",
292:                        "m2()V", cr.getMethodAt((short) 1));
293:                assertEquals("Did not return correct method name [2].",
294:                        "m3()V", cr.getMethodAt((short) 2));
295:            }
296:
297:            public void testAddMark1() {
298:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
299:                        "m1()V", "m2()V", "m3()V" }, createAnalysisModuleSet(4));
300:                try {
301:                    cr.addMark(null);
302:                } catch (IllegalArgumentException ex) {
303:                    // test exception
304:                }
305:            }
306:
307:            public void testMarks1a() {
308:                AnalysisModuleSet ams = createAnalysisModuleSet(4);
309:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
310:                        "m1()V", "m2()V", "m3()V" }, ams);
311:                String moduleN = ams.getAnalysisModuleAt((short) 0)
312:                        .getMeasureName();
313:                cr.addMark(createMarkRecord(0, moduleN, "m0()V", 1));
314:                MarkRecord mr[] = cr.getMarksForAnalysisModule(moduleN);
315:                assertEquals("Mark record length is wrong.", 1, mr.length);
316:                try {
317:                    mr[0].getMethodIndex();
318:                    fail("Did not throw IllegalStateException.");
319:                } catch (IllegalStateException ex) {
320:                    // test exception
321:                }
322:            }
323:
324:            public void testMarks1b() {
325:                AnalysisModuleSet ams = createAnalysisModuleSet(4);
326:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
327:                        "m1()V", "m2()V", "m3()V" }, ams);
328:                IAnalysisModule am = ams.getAnalysisModuleAt((short) 0);
329:                String moduleN = am.getMeasureName();
330:                cr.addMark(createMarkRecord(0, moduleN, "m0()V", 1));
331:                MarkRecord mr[] = cr.getMarksForAnalysisModule(am);
332:                assertEquals("Mark record length is wrong.", 1, mr.length);
333:                try {
334:                    mr[0].getMethodIndex();
335:                    fail("Did not throw IllegalStateException.");
336:                } catch (IllegalStateException ex) {
337:                    // test exception
338:                }
339:            }
340:
341:            public void testMarks2a() {
342:                AnalysisModuleSet ams = createAnalysisModuleSet(4);
343:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
344:                        "m1()V", "m2()V", "m3()V" }, ams);
345:                String moduleN1 = ams.getAnalysisModuleAt((short) 0)
346:                        .getMeasureName();
347:                String moduleN2 = ams.getAnalysisModuleAt((short) 1)
348:                        .getMeasureName();
349:                cr.addMark(createMarkRecord(0, moduleN1, "m1()V", 1));
350:                cr.addMark(createMarkRecord(0, moduleN2, "m1()V", 2));
351:                MarkRecord mr[] = cr.getMarksForAnalysisModule(moduleN1);
352:                assertEquals("Mark record length is wrong.", 1, mr.length);
353:                assertEquals("Wrong method index.", (short) 0, mr[0]
354:                        .getMethodIndex());
355:                assertEquals("Wrong mark index.", (short) 1, mr[0]
356:                        .getMarkIndex());
357:
358:                mr = cr.getMarksForAnalysisModule(moduleN2);
359:                assertEquals("Mark record length is wrong.", 1, mr.length);
360:                assertEquals("Wrong method index.", (short) 0, mr[0]
361:                        .getMethodIndex());
362:                assertEquals("Wrong mark index.", (short) 2, mr[0]
363:                        .getMarkIndex());
364:            }
365:
366:            public void testMarks2b() {
367:                AnalysisModuleSet ams = createAnalysisModuleSet(4);
368:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
369:                        "m1()V", "m2()V", "m3()V" }, ams);
370:                IAnalysisModule am1 = ams.getAnalysisModuleAt((short) 0);
371:                IAnalysisModule am2 = ams.getAnalysisModuleAt((short) 1);
372:                String moduleN1 = am1.getMeasureName();
373:                String moduleN2 = am2.getMeasureName();
374:                cr.addMark(createMarkRecord(0, moduleN1, "m1()V", 1));
375:                cr.addMark(createMarkRecord(0, moduleN2, "m1()V", 2));
376:                MarkRecord mr[] = cr.getMarksForAnalysisModule(am1);
377:                assertEquals("Mark record length is wrong.", 1, mr.length);
378:                assertEquals("Wrong method index.", (short) 0, mr[0]
379:                        .getMethodIndex());
380:                assertEquals("Wrong mark index.", (short) 1, mr[0]
381:                        .getMarkIndex());
382:
383:                mr = cr.getMarksForAnalysisModule(am2);
384:                assertEquals("Mark record length is wrong.", 1, mr.length);
385:                assertEquals("Wrong method index.", (short) 0, mr[0]
386:                        .getMethodIndex());
387:                assertEquals("Wrong mark index.", (short) 2, mr[0]
388:                        .getMarkIndex());
389:            }
390:
391:            public void testMarks3a() {
392:                AnalysisModuleSet ams = createAnalysisModuleSet(4);
393:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
394:                        "m1()V", "m2()V", "m3()V" }, ams);
395:                String moduleN = ams.getAnalysisModuleAt((short) 0)
396:                        .getMeasureName();
397:                cr.addMark(createMarkRecord(0, moduleN, "m1()V", 1));
398:                cr.addMark(createMarkRecord(1, moduleN, "m1()V", 1));
399:                MarkRecord mr[] = cr.getMarksForAnalysisModule(moduleN);
400:                assertEquals("Mark record length is wrong.", 1, mr.length);
401:            }
402:
403:            public void testMarks3b() {
404:                AnalysisModuleSet ams = createAnalysisModuleSet(4);
405:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
406:                        "m1()V", "m2()V", "m3()V" }, ams);
407:                IAnalysisModule am = ams.getAnalysisModuleAt((short) 0);
408:                String moduleN = am.getMeasureName();
409:                cr.addMark(createMarkRecord(0, moduleN, "m1()V", 1));
410:                cr.addMark(createMarkRecord(1, moduleN, "m1()V", 1));
411:                MarkRecord mr[] = cr.getMarksForAnalysisModule(am);
412:                assertEquals("Mark record length is wrong.", 1, mr.length);
413:            }
414:
415:            public void testMarks4() {
416:                AnalysisModuleSet ams = createAnalysisModuleSet(4);
417:                ClassRecord cr = new ClassRecord("A", -10L, "a", new String[] {
418:                        "m1()V", "m2()V", "m3()V" }, ams);
419:                IAnalysisModule am = ams.getAnalysisModuleAt((short) 0);
420:                String moduleN = am.getMeasureName();
421:                cr.addMark(createMarkRecord(0, moduleN, "m1()V", 1));
422:                MarkRecord mr1[] = cr.getMarksForAnalysisModule(moduleN);
423:                MarkRecord mr2[] = cr.getMarksForAnalysisModule(am);
424:                assertSame("Marks are wrong.", mr1[0], mr2[0]);
425:            }
426:
427:            //-------------------------------------------------------------------------
428:            // Helpers
429:
430:            protected IAnalysisMetaData createAnalysisMetaData(int weight) {
431:                return CCCreatorUtil.createIAnalysisMetaData("a", "b",
432:                        (byte) weight);
433:            }
434:
435:            protected AnalysisModuleSet createAnalysisModuleSet(int count) {
436:                return CCCreatorUtil.createAnalysisModuleSet(count);
437:            }
438:
439:            protected MarkRecord createMarkRecord(int metaDataWeight,
440:                    String am, String methSig, int markId) {
441:                return new MarkRecord(createAnalysisMetaData(metaDataWeight),
442:                        am, methSig, (short) markId, 1);
443:            }
444:
445:            //-------------------------------------------------------------------------
446:            // Standard JUnit declarations
447:
448:            public static Test suite() {
449:                TestSuite suite = new TestSuite(THIS_CLASS);
450:
451:                return suite;
452:            }
453:
454:            public static void main(String[] args) {
455:                String[] name = { THIS_CLASS.getName() };
456:
457:                // junit.textui.TestRunner.main( name );
458:                // junit.swingui.TestRunner.main( name );
459:
460:                junit.textui.TestRunner.main(name);
461:            }
462:
463:            /**
464:             * 
465:             * @exception Exception thrown under any exceptional condition.
466:             */
467:            protected void setUp() throws Exception {
468:                super .setUp();
469:
470:                // set ourself up
471:            }
472:
473:            /**
474:             * 
475:             * @exception Exception thrown under any exceptional condition.
476:             */
477:            protected void tearDown() throws Exception {
478:                // tear ourself down
479:
480:                super.tearDown();
481:            }
482:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.