Source Code Cross Referenced for NormalBehaviorSet.java in  » Testing » mocquer » org » jingle » mocquer » internal » 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 » Testing » mocquer » org.jingle.mocquer.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jingle.mocquer.internal;
002:
003:        import java.util.ArrayList;
004:        import java.util.List;
005:
006:        import org.jingle.mocquer.ArgumentsMatcher;
007:        import org.jingle.mocquer.AssertionFailedError;
008:        import org.jingle.mocquer.MockControl;
009:        import org.jingle.mocquer.Range;
010:
011:        /**
012:         * This class is a normal implementation of BehaviorSet interface
013:         * 
014:         * 
015:         * @author JianLu
016:         * @version 1.0 2004-10-27
017:         * @since 1.0
018:         */
019:        public class NormalBehaviorSet implements  BehaviorSet {
020:            /**
021:             * The list contains all the behavior
022:             */
023:            protected List behaviorList = new ArrayList();
024:
025:            /**
026:             * Default argument matcher object
027:             */
028:            ArgumentsMatcher defaultMatcher = MockControl.ARRAY_MATCHER;
029:
030:            /**
031:             * (non-Javadoc)
032:             * 
033:             * @see org.jingle.mocquer.internal.BehaviorSet#addBehavior(org.jingle.mocquer.internal.MockBehavior)
034:             */
035:            public void addBehavior(MockBehavior behavior) {
036:                behaviorList.add(behavior);
037:            }
038:
039:            /**
040:             * (non-Javadoc)
041:             * 
042:             * @see org.jingle.mocquer.internal.BehaviorSet#visitBehavior(org.jingle.mocquer.internal.MockBehavior)
043:             */
044:            public void visitBehavior(MockBehavior behavior) {
045:                MockBehavior mb = findBehavior(behavior);
046:                if (mb != null) {
047:                    mb.useOnce();
048:                    mb.copyto(behavior);
049:                } else
050:                    throw new AssertionFailedError("No behavior defined");
051:            }
052:
053:            /**
054:             * Find a behavior from the behavio set according to the given incomplete behavior
055:             * @param behavior The given behavior
056:             * @return The behavior in the behavior set
057:             */
058:            protected MockBehavior findBehavior(MockBehavior behavior) {
059:                MockBehavior ret = null;
060:                for (int i = 1; i <= behaviorList.size(); i++) {
061:                    MockBehavior item = (MockBehavior) behaviorList.get(i - 1);
062:                    if (item.getMethod().equals(behavior.getMethod())
063:                            && !item.isUsed()
064:                            && item.getMatcher().matches(item.getArguments(),
065:                                    behavior.getArguments())) {
066:                        ret = item;
067:                        break;
068:                    }
069:                }
070:                return ret;
071:            }
072:
073:            /**
074:             * Find last behavior in the behavior set
075:             * @return The last behavior in the behavior set
076:             */
077:            protected MockBehavior findBehavior() {
078:                int length = behaviorList.size();
079:                if (length > 0) {
080:                    MockBehavior behavior = (MockBehavior) behaviorList
081:                            .get(length - 1);
082:                    return behavior;
083:                } else
084:                    throw new AssertionFailedError("No behavior found");
085:            }
086:
087:            /** 
088:             * (non-Javadoc)
089:             * @see org.jingle.mocquer.internal.BehaviorSet#setReturnValue(java.lang.Object, org.jingle.mocquer.Range)
090:             */
091:            public void setReturnValue(Object retValue, Range range) {
092:                MockBehavior behavior = findBehavior();
093:                behavior.setRetValue(retValue);
094:                if (range != null)
095:                    behavior.setRange(range);
096:                if (behavior.getMatcher() == null)
097:                    behavior.setMatcher(defaultMatcher);
098:            }
099:
100:            /** 
101:             * (non-Javadoc)
102:             * @see org.jingle.mocquer.internal.BehaviorSet#setDefaultReturnValue(java.lang.Object)
103:             */
104:            public void setDefaultReturnValue(Object retValue) {
105:                MockBehavior behavior = findBehavior();
106:                behavior.setRetValue(retValue);
107:                behavior.setArguments(null);
108:                if (behavior.getMatcher() == null)
109:                    behavior.setMatcher(defaultMatcher);
110:            }
111:
112:            /** 
113:             * (non-Javadoc)
114:             * @see org.jingle.mocquer.internal.BehaviorSet#setThrowable(java.lang.Throwable, org.jingle.mocquer.Range)
115:             */
116:            public void setThrowable(Throwable throwable, Range range) {
117:                MockBehavior behavior = findBehavior();
118:                behavior.setThrowable(throwable);
119:                if (range != null)
120:                    behavior.setRange(range);
121:                if (behavior.getMatcher() == null)
122:                    behavior.setMatcher(defaultMatcher);
123:            }
124:
125:            /** 
126:             * (non-Javadoc)
127:             * @see org.jingle.mocquer.internal.BehaviorSet#setDefaultThrowable(java.lang.Throwable)
128:             */
129:            public void setDefaultThrowable(Throwable throwable) {
130:                MockBehavior behavior = findBehavior();
131:                behavior.setThrowable(throwable);
132:                behavior.setArguments(null);
133:                if (behavior.getMatcher() == null)
134:                    behavior.setMatcher(defaultMatcher);
135:            }
136:
137:            /**
138:             * (non-Javadoc)
139:             * 
140:             * @see org.jingle.mocquer.internal.BehaviorSet#verify()
141:             */
142:            public void verify() {
143:                for (int i = 1; i <= behaviorList.size(); i++) {
144:                    MockBehavior item = (MockBehavior) behaviorList.get(i - 1);
145:                    Range range = item.getRange();
146:                    int actualTimes = item.getActualTimes();
147:                    if (!range.inRange(actualTimes))
148:                        throw new AssertionFailedError("Method ["
149:                                + item.getMethod()
150:                                + "] is expected to be called " + range
151:                                + " times, but is called " + actualTimes
152:                                + " times actually.");
153:                }
154:            }
155:
156:            /**
157:             * (non-Javadoc)
158:             * 
159:             * @see org.jingle.mocquer.internal.BehaviorSet#reset()
160:             */
161:            public void reset() {
162:                behaviorList.clear();
163:            }
164:
165:            /**
166:             * (non-Javadoc)
167:             * 
168:             * @see org.jingle.mocquer.internal.BehaviorSet#replay()
169:             */
170:            public void replay() {
171:                for (int i = 1; i <= behaviorList.size(); i++) {
172:                    MockBehavior bahavior = (MockBehavior) behaviorList
173:                            .get(i - 1);
174:                    bahavior.reset();
175:                }
176:            }
177:
178:            /** 
179:             * (non-Javadoc)
180:             * @see org.jingle.mocquer.internal.BehaviorSet#setMatcher(org.jingle.mocquer.ArgumentsMatcher)
181:             */
182:            public void setMatcher(ArgumentsMatcher matcher) {
183:                MockBehavior behavior = findBehavior();
184:                behavior.setMatcher(matcher);
185:            }
186:
187:            /** 
188:             * (non-Javadoc)
189:             * @see org.jingle.mocquer.internal.BehaviorSet#isEmpty()
190:             */
191:            public boolean isEmpty() {
192:                return behaviorList.isEmpty();
193:            }
194:
195:            /** 
196:             * (non-Javadoc)
197:             * @see org.jingle.mocquer.internal.BehaviorSet#setDefaultMatcher(org.jingle.mocquer.ArgumentsMatcher)
198:             */
199:            public void setDefaultMatcher(ArgumentsMatcher matcher) {
200:                this .defaultMatcher = matcher;
201:            }
202:
203:            /** 
204:             * (non-Javadoc)
205:             * @see org.jingle.mocquer.internal.BehaviorSet#setVoidCallable(org.jingle.mocquer.Range)
206:             */
207:            public void setVoidCallable(Range range) {
208:                MockBehavior behavior = findBehavior();
209:                behavior.setVoidCallable();
210:                if (range != null)
211:                    behavior.setRange(range);
212:                if (behavior.getMatcher() == null)
213:                    behavior.setMatcher(defaultMatcher);
214:            }
215:
216:            /** 
217:             * (non-Javadoc)
218:             * @see org.jingle.mocquer.internal.BehaviorSet#setDefaultVoidCallable()
219:             */
220:            public void setDefaultVoidCallable() {
221:                MockBehavior behavior = findBehavior();
222:                behavior.setVoidCallable();
223:                behavior.setArguments(null);
224:                if (behavior.getMatcher() == null)
225:                    behavior.setMatcher(defaultMatcher);
226:            }
227:
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.