Source Code Cross Referenced for TestMoveMethodRefactoring.java in  » UML » jrefactory » org » acm » seguin » refactor » method » 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 » UML » jrefactory » org.acm.seguin.refactor.method 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.acm.seguin.refactor.method;
002:
003:        import java.io.File;
004:        import java.util.Iterator;
005:        import org.acm.seguin.io.FileCopy;
006:        import org.acm.seguin.junit.DirSourceTestCase;
007:        import org.acm.seguin.junit.FileCompare;
008:        import org.acm.seguin.refactor.RefactoringException;
009:        import org.acm.seguin.summary.*;
010:        import org.acm.seguin.summary.query.GetTypeSummary;
011:        import org.acm.seguin.summary.query.GetMethodSummary;
012:
013:        /**
014:         *  Unit tests for moving a method from one class to another
015:         *
016:         *@author    Chris Seguin
017:         */
018:        public class TestMoveMethodRefactoring extends DirSourceTestCase {
019:            /**
020:             *  Constructor for the TestMoveMethodRefactoring object
021:             *
022:             *@param  name  Description of Parameter
023:             */
024:            public TestMoveMethodRefactoring(String name) {
025:                super (name);
026:            }
027:
028:            /**
029:             *  A unit test for JUnit
030:             *
031:             *@exception  RefactoringException  Description of Exception
032:             */
033:            public void test01() throws RefactoringException {
034:                System.out.println("Test 01");
035:                test("methodOne", 1);
036:            }
037:
038:            /**
039:             *  A unit test for JUnit
040:             *
041:             *@exception  RefactoringException  Description of Exception
042:             */
043:            public void test02() throws RefactoringException {
044:                System.out.println("Test 02");
045:                test("methodTwo", 2);
046:            }
047:
048:            /**
049:             *  A unit test for JUnit
050:             *
051:             *@exception  RefactoringException  Description of Exception
052:             */
053:            public void test03() throws RefactoringException {
054:                System.out.println("Test 03");
055:                test("methodThree", 3);
056:            }
057:
058:            /**
059:             *  A unit test for JUnit
060:             *
061:             *@exception  RefactoringException  Description of Exception
062:             */
063:            public void test04() throws RefactoringException {
064:                System.out.println("Test 04");
065:                test(
066:                        "methodFour",
067:                        "Unable to find the appropriate method (getIncr2) for private field access in MoveMethodSource");
068:            }
069:
070:            /**
071:             *  A unit test for JUnit
072:             *
073:             *@exception  RefactoringException  Description of Exception
074:             */
075:            public void test05() throws RefactoringException {
076:                System.out.println("Test 05");
077:                test("methodFive", 5);
078:            }
079:
080:            /**
081:             *  A unit test for JUnit
082:             *
083:             *@exception  RefactoringException  Description of Exception
084:             */
085:            public void test06() throws RefactoringException {
086:                System.out.println("Test 06");
087:                test("methodSix", 6);
088:            }
089:
090:            /**
091:             *  A unit test for JUnit
092:             *
093:             *@exception  RefactoringException  Description of Exception
094:             */
095:            public void test07() throws RefactoringException {
096:                System.out.println("Test 07");
097:                test("methodSeven", 7);
098:            }
099:
100:            /**
101:             *  A unit test for JUnit
102:             *
103:             *@exception  RefactoringException  Description of Exception
104:             */
105:            public void test08() throws RefactoringException {
106:                System.out.println("Test 08");
107:                test(
108:                        "methodEight",
109:                        "Moving a method (packageMethod) from MoveMethodSource to a different package that requires package access is illegal.");
110:            }
111:
112:            /**
113:             *  A unit test for JUnit
114:             *
115:             *@exception  RefactoringException  Description of Exception
116:             */
117:            public void test09() throws RefactoringException {
118:                System.out.println("Test 09");
119:                test(
120:                        "methodNine",
121:                        "Moving a method (privateMethod) from MoveMethodSource that requires private access is illegal");
122:            }
123:
124:            /**
125:             *  A unit test for JUnit
126:             *
127:             *@exception  RefactoringException  Description of Exception
128:             */
129:            public void test10() throws RefactoringException {
130:                System.out.println("Test 10");
131:                testFile2("method1", "step35");
132:            }
133:
134:            /**
135:             *  A unit test for JUnit
136:             *
137:             *@exception  RefactoringException  Description of Exception
138:             */
139:            public void test11() throws RefactoringException {
140:                System.out.println("Test 11");
141:                testFile2("method2", "step36");
142:            }
143:
144:            /**
145:             *  A unit test for JUnit
146:             */
147:            public void test12() {
148:                System.out.println("Test 12");
149:                TypeSummary type = GetTypeSummary.query("method",
150:                        "MoveMethodSource2");
151:                MethodSummary method = GetMethodSummary.query(type, "method3");
152:                Iterator iter = method.getParameters();
153:                ParameterSummary param = (ParameterSummary) iter.next();
154:
155:                MoveMethodRefactoring mmr = new MoveMethodRefactoring();
156:                mmr.setMethod(method);
157:                mmr.setDestination(param);
158:
159:                boolean exceptionThrown = false;
160:                try {
161:                    mmr.run();
162:                } catch (RefactoringException re) {
163:                    assertEquals("Incorrect message",
164:                            "The source code for String is not modifiable", re
165:                                    .getMessage());
166:                    exceptionThrown = true;
167:                }
168:                assertTrue("No exception", exceptionThrown);
169:            }
170:
171:            /**
172:             *  A unit test for JUnit
173:             */
174:            public void test13() {
175:                System.out.println("Test 13");
176:                TypeSummary type = GetTypeSummary.query("method",
177:                        "MoveMethodSource2");
178:                MethodSummary method = GetMethodSummary.query(type, "method4");
179:                Iterator iter = method.getParameters();
180:                ParameterSummary param = (ParameterSummary) iter.next();
181:
182:                MoveMethodRefactoring mmr = new MoveMethodRefactoring();
183:                mmr.setMethod(method);
184:                mmr.setDestination(param);
185:
186:                boolean exceptionThrown = false;
187:                try {
188:                    mmr.run();
189:                } catch (RefactoringException re) {
190:                    assertEquals("Incorrect message",
191:                            "The parameter total is a primitive", re
192:                                    .getMessage());
193:                    exceptionThrown = true;
194:                }
195:                assertTrue("No exception", exceptionThrown);
196:            }
197:
198:            /**
199:             *  The JUnit setup method
200:             */
201:            protected void setUp() {
202:                (new FileCopy(new File(clean + File.separator
203:                        + "method_MoveMethodSource.java"), new File(root
204:                        + File.separator + "method\\MoveMethodSource.java"),
205:                        false)).run();
206:                (new FileCopy(new File(clean + File.separator
207:                        + "method_MoveMethodDest.java"), new File(root
208:                        + File.separator + "method\\MoveMethodDest.java"),
209:                        false)).run();
210:                (new FileCopy(new File(clean + File.separator
211:                        + "other_OtherMethodDest.java"), new File(root
212:                        + File.separator + "other\\OtherMethodDest.java"),
213:                        false)).run();
214:                (new FileCopy(new File(clean + File.separator
215:                        + "method_MoveMethodSource2.java"), new File(root
216:                        + File.separator + "method\\MoveMethodSource2.java"),
217:                        false)).run();
218:                (new FileCopy(new File(clean + File.separator
219:                        + "method_MoveMethodDest2.java"), new File(root
220:                        + File.separator + "method\\MoveMethodDest2.java"),
221:                        false)).run();
222:
223:                (new SummaryTraversal(root)).run();
224:            }
225:
226:            /**
227:             *  The teardown method for JUnit
228:             */
229:            protected void tearDown() {
230:                (new File(root + "method\\MoveMethodSource.java")).delete();
231:                (new File(root + "method\\MoveMethodDest.java")).delete();
232:                (new File(root + "other\\OtherMethodDest.java")).delete();
233:                (new File(root + "method\\MoveMethodSource2.java")).delete();
234:                (new File(root + "method\\MoveMethodDest2.java")).delete();
235:            }
236:
237:            /**
238:             *  A unit test for JUnit
239:             *
240:             *@param  methodName                Description of Parameter
241:             *@param  testID                    Description of Parameter
242:             *@exception  RefactoringException  Description of Exception
243:             */
244:            private void testFile2(String methodName, String testID)
245:                    throws RefactoringException {
246:                TypeSummary type = GetTypeSummary.query("method",
247:                        "MoveMethodSource2");
248:                MethodSummary method = GetMethodSummary.query(type, methodName);
249:                Iterator iter = method.getParameters();
250:                ParameterSummary param = (ParameterSummary) iter.next();
251:
252:                MoveMethodRefactoring mmr = new MoveMethodRefactoring();
253:                mmr.setMethod(method);
254:                mmr.setDestination(param);
255:
256:                mmr.run();
257:
258:                //  Check things out
259:                File checkDir = new File(check + "\\ut3\\" + testID);
260:                File destDir = new File(root + "\\method");
261:
262:                FileCompare.assertEquals("MoveMethodSource2 is incorrect",
263:                        new File(checkDir, "MoveMethodSource2.java"), new File(
264:                                destDir, "MoveMethodSource2.java"));
265:                FileCompare.assertEquals("MoveMethodDest2 is incorrect",
266:                        new File(checkDir, "MoveMethodDest2.java"), new File(
267:                                destDir, "MoveMethodDest2.java"));
268:            }
269:
270:            /**
271:             *  A unit test for JUnit
272:             *
273:             *@param  methodName                Description of Parameter
274:             *@param  testCase                  Description of Parameter
275:             *@exception  RefactoringException  Description of Exception
276:             */
277:            private void test(String methodName, int testCase)
278:                    throws RefactoringException {
279:                TypeSummary type = GetTypeSummary.query("method",
280:                        "MoveMethodSource");
281:                MethodSummary method = GetMethodSummary.query(type, methodName);
282:                Iterator iter = method.getParameters();
283:                ParameterSummary param = (ParameterSummary) iter.next();
284:
285:                MoveMethodRefactoring mmr = new MoveMethodRefactoring();
286:                mmr.setMethod(method);
287:                mmr.setDestination(param);
288:
289:                mmr.run();
290:
291:                //  Check things out
292:                File checkDir = new File(check + "\\ut3\\step" + (9 + testCase));
293:                File destDir = new File(root + "\\method");
294:
295:                FileCompare.assertEquals("MoveMethodSource is incorrect",
296:                        new File(checkDir, "MoveMethodSource.java"), new File(
297:                                destDir, "MoveMethodSource.java"));
298:                FileCompare.assertEquals("MoveMethodDest is incorrect",
299:                        new File(checkDir, "MoveMethodDest.java"), new File(
300:                                destDir, "MoveMethodDest.java"));
301:            }
302:
303:            /**
304:             *  A unit test for JUnit
305:             *
306:             *@param  methodName                Description of Parameter
307:             *@param  message                   Description of Parameter
308:             *@exception  RefactoringException  Description of Exception
309:             */
310:            private void test(String methodName, String message)
311:                    throws RefactoringException {
312:                TypeSummary type = GetTypeSummary.query("method",
313:                        "MoveMethodSource");
314:                MethodSummary method = GetMethodSummary.query(type, methodName);
315:                Iterator iter = method.getParameters();
316:                ParameterSummary param = (ParameterSummary) iter.next();
317:
318:                MoveMethodRefactoring mmr = new MoveMethodRefactoring();
319:                mmr.setMethod(method);
320:                mmr.setDestination(param);
321:
322:                try {
323:                    mmr.run();
324:                } catch (RefactoringException re) {
325:                    assertEquals("Incorrect message", message, re.getMessage());
326:                    return;
327:                }
328:                fail("Expected a refactoring exception with a message of "
329:                        + message);
330:            }
331:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.