Source Code Cross Referenced for LenientMocksControlTest.java in  » Testing » unitils » org » unitils » easymock » util » 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 » unitils » org.unitils.easymock.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007,  Unitils.org
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.unitils.easymock.util;
017:
018:        import junit.framework.TestCase;
019:        import static org.easymock.classextension.EasyMock.*;
020:        import static org.easymock.internal.MocksControl.MockType.DEFAULT;
021:        import static org.unitils.easymock.EasyMockUnitils.refEq;
022:        import static org.unitils.reflectionassert.ReflectionComparatorMode.IGNORE_DEFAULTS;
023:
024:        import java.util.ArrayList;
025:        import java.util.Arrays;
026:        import java.util.List;
027:
028:        /**
029:         * A test for {@link LenientMocksControl}.
030:         *
031:         * @author Tim Ducheyne
032:         * @author Filip Neven
033:         */
034:        public class LenientMocksControlTest extends TestCase {
035:
036:            /* Class under test, with mock type LENIENT and ignore defaults */
037:            private LenientMocksControl lenientMocksControl;
038:
039:            /**
040:             * Initializes the test fixture.
041:             */
042:            protected void setUp() throws Exception {
043:                super .setUp();
044:
045:                lenientMocksControl = new LenientMocksControl(DEFAULT,
046:                        IGNORE_DEFAULTS);
047:            }
048:
049:            /**
050:             * Test for a mocked method call that is invoked with the expected arguments.
051:             */
052:            public void testLenientMocksControl_equals() {
053:
054:                MockedClass mock = lenientMocksControl
055:                        .createMock(MockedClass.class);
056:                expect(
057:                        mock.someBehavior(true, 999, "Test",
058:                                new ArrayList<Object>())).andReturn("Result");
059:                replay(mock);
060:
061:                String result = mock.someBehavior(true, 999, "Test",
062:                        new ArrayList<Object>());
063:
064:                assertEquals("Result", result);
065:                verify(mock);
066:            }
067:
068:            /**
069:             * Test for a mocked method call that has no arguments.
070:             */
071:            public void testLenientMocksControl_equalsNoArguments() {
072:
073:                MockedClass mock = lenientMocksControl
074:                        .createMock(MockedClass.class);
075:                mock.someBehavior();
076:                replay(mock);
077:
078:                mock.someBehavior();
079:
080:                verify(mock);
081:            }
082:
083:            /**
084:             * Test for a invoking a mocked method call more than once.
085:             */
086:            public void testLenientMocksControl_equalsDoubleInvocation() {
087:
088:                MockedClass mock = lenientMocksControl
089:                        .createMock(MockedClass.class);
090:                expect(
091:                        mock.someBehavior(true, 111, "Test1", Arrays
092:                                .asList("1"))).andReturn("Result1");
093:                expect(
094:                        mock.someBehavior(false, 222, "Test2", Arrays
095:                                .asList("2"))).andReturn("Result2");
096:                replay(mock);
097:
098:                String result1 = mock.someBehavior(true, 111, "Test1", Arrays
099:                        .asList("1"));
100:                String result2 = mock.someBehavior(false, 222, "Test2", Arrays
101:                        .asList("2"));
102:
103:                verify(mock);
104:                assertEquals("Result1", result1);
105:                assertEquals("Result2", result2);
106:            }
107:
108:            /**
109:             * Test for ignoring a default value for an argument.
110:             */
111:            public void testLenientMocksControl_equalsIgnoreDefaults() {
112:
113:                MockedClass mock = lenientMocksControl
114:                        .createMock(MockedClass.class);
115:                expect(mock.someBehavior(false, 0, null, null)).andReturn(
116:                        "Result");
117:                replay(mock);
118:
119:                String result = mock.someBehavior(true, 999, "Test",
120:                        new ArrayList<Object>());
121:
122:                assertEquals("Result", result);
123:                verify(mock);
124:            }
125:
126:            /**
127:             * Test for a mocked method that is expected but was never called.
128:             */
129:            public void testLenientMocksControl_notEqualsNotCalled() {
130:
131:                MockedClass mock = lenientMocksControl
132:                        .createMock(MockedClass.class);
133:                expect(
134:                        mock.someBehavior(true, 999, "XXXX",
135:                                new ArrayList<Object>())).andReturn("Result");
136:                replay(mock);
137:
138:                try {
139:                    verify(mock);
140:                    fail();
141:                } catch (AssertionError e) {
142:                    //expected
143:                }
144:            }
145:
146:            /**
147:             * Test for a mocked method call that is invoked with the different arguments.
148:             */
149:            public void testLenientMocksControl_notEqualsDifferentArguments() {
150:
151:                MockedClass mock = lenientMocksControl
152:                        .createMock(MockedClass.class);
153:                expect(
154:                        mock.someBehavior(true, 999, "XXXX",
155:                                new ArrayList<Object>())).andReturn("Result");
156:                replay(mock);
157:
158:                try {
159:                    mock.someBehavior(true, 999, "Test",
160:                            new ArrayList<Object>());
161:                    fail();
162:                } catch (AssertionError e) {
163:                    //expected
164:                }
165:            }
166:
167:            /**
168:             * Test for using argument matchers (refEq and EasyMocks eq).
169:             */
170:            public void testLenientMocksControl_mixingArgumentMatchers() {
171:
172:                MockedClass mock = lenientMocksControl
173:                        .createMock(MockedClass.class);
174:                expect(
175:                        mock.someBehavior(eq(true), refEq(999), eq("Test"),
176:                                refEq(new ArrayList<Object>()))).andReturn(
177:                        "Result");
178:                replay(mock);
179:
180:                String result = mock.someBehavior(true, 999, "Test",
181:                        new ArrayList<Object>());
182:
183:                assertEquals("Result", result);
184:                verify(mock);
185:            }
186:
187:            /**
188:             * Test for a invoking a mocked method call with a enum argument.
189:             */
190:            public void testLenientMocksControl_equalsEnumArgument() {
191:
192:                MockedClass mock = lenientMocksControl
193:                        .createMock(MockedClass.class);
194:                expect(mock.someBehavior(MockedClass.TestEnum.TEST1))
195:                        .andStubReturn("Result1");
196:                expect(mock.someBehavior(MockedClass.TestEnum.TEST2))
197:                        .andStubReturn("Result2");
198:                replay(mock);
199:
200:                String result1 = mock.someBehavior(MockedClass.TestEnum.TEST1);
201:                String result2 = mock.someBehavior(MockedClass.TestEnum.TEST2);
202:
203:                verify(mock);
204:                assertEquals("Result1", result1);
205:                assertEquals("Result2", result2);
206:            }
207:
208:            /**
209:             * The test class that is going to be mocked.
210:             */
211:            private static class MockedClass {
212:
213:                public enum TestEnum {
214:                    TEST1, TEST2
215:                }
216:
217:                public void someBehavior() {
218:                }
219:
220:                public String someBehavior(boolean b, int i, Object object,
221:                        List<?> list) {
222:                    return null;
223:                }
224:
225:                public String someBehavior(TestEnum testEnum) {
226:                    return null;
227:                }
228:            }
229:
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.