Source Code Cross Referenced for TheoriesTest.java in  » Testing » junit » org » junit » experimental » test » theories » 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 » junit » org.junit.experimental.test.theories 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.junit.experimental.test.theories;
002:
003:        import static org.hamcrest.CoreMatchers.is;
004:        import static org.hamcrest.CoreMatchers.not;
005:        import static org.hamcrest.CoreMatchers.notNullValue;
006:        import static org.junit.Assert.assertThat;
007:        import static org.junit.Assume.assumeThat;
008:        import static org.junit.experimental.results.PrintableResult.testResult;
009:        import static org.junit.experimental.results.ResultMatchers.failureCountIs;
010:        import static org.junit.experimental.results.ResultMatchers.hasSingleFailureContaining;
011:        import static org.junit.experimental.results.ResultMatchers.isSuccessful;
012:        import static org.junit.matchers.StringContains.containsString;
013:        import org.hamcrest.Matcher;
014:        import org.junit.Test;
015:        import org.junit.experimental.results.ResultMatchers;
016:        import org.junit.experimental.theories.DataPoint;
017:        import org.junit.experimental.theories.Theories;
018:        import org.junit.experimental.theories.Theory;
019:        import org.junit.experimental.theories.suppliers.TestedOn;
020:        import org.junit.internal.runners.TestClass;
021:        import org.junit.runner.RunWith;
022:
023:        @SuppressWarnings("restriction")
024:        @RunWith(Theories.class)
025:        public class TheoriesTest {
026:            public static String SPACE = " ";
027:
028:            public static String J = "J";
029:
030:            public static String NULL_STRING = null;
031:
032:            public static int ZERO = 0;
033:
034:            public static int ONE = 1;
035:
036:            public static int THREE = 3;
037:
038:            public static int FIVE = 5;
039:
040:            public static int INDEPENDENCE = 1776;
041:
042:            public static Matcher<Integer> NOT_ZERO = not(0);
043:
044:            public static Matcher<Integer> IS_ONE = is(1);
045:
046:            @RunWith(Theories.class)
047:            public static class HasATheory {
048:                public static int ONE = 1;
049:
050:                @Theory
051:                public void everythingIsZero(int x) {
052:                    assertThat(x, is(0));
053:                }
054:            }
055:
056:            @Test
057:            public void theoryClassMethodsShowUp() throws Exception {
058:                assertThat(new Theories(HasATheory.class).getDescription()
059:                        .getChildren().size(), is(1));
060:            }
061:
062:            @Test
063:            public void theoryAnnotationsAreRetained() throws Exception {
064:                assertThat(new TestClass(HasATheory.class).getAnnotatedMethods(
065:                        Theory.class).size(), is(1));
066:            }
067:
068:            @Test
069:            public void canRunTheories() throws Exception {
070:                assertThat(testResult(HasATheory.class),
071:                        hasSingleFailureContaining("Expected"));
072:            }
073:
074:            @RunWith(Theories.class)
075:            public static class HasATwoParameterTheory {
076:                public static int ONE = 1;
077:
078:                @Theory
079:                public void everythingIsZero(int x, int y) {
080:                    assertThat(x, is(y));
081:                }
082:            }
083:
084:            @Test
085:            public void canRunTwoParameterTheories() throws Exception {
086:                assertThat(testResult(HasATwoParameterTheory.class),
087:                        ResultMatchers.isSuccessful());
088:            }
089:
090:            @RunWith(Theories.class)
091:            public static class DoesntUseParams {
092:                public static int ONE = 1;
093:
094:                @Theory
095:                public void everythingIsZero(int x, int y) {
096:                    assertThat(2, is(3));
097:                }
098:            }
099:
100:            @Test
101:            public void reportBadParams() throws Exception {
102:                assertThat(testResult(DoesntUseParams.class),
103:                        hasSingleFailureContaining("everythingIsZero(1, 1)"));
104:            }
105:
106:            @RunWith(Theories.class)
107:            public static class NullsOK {
108:                public static String NULL = null;
109:
110:                public static String A = "A";
111:
112:                @Theory
113:                public void everythingIsA(String a) {
114:                    assertThat(a, is("A"));
115:                }
116:            }
117:
118:            @Test
119:            public void nullsUsedUnlessProhibited() throws Exception {
120:                assertThat(testResult(NullsOK.class),
121:                        hasSingleFailureContaining("null"));
122:            }
123:
124:            @RunWith(Theories.class)
125:            public static class ParameterAnnotations {
126:                @Theory
127:                public void everythingIsOne(@TestedOn(ints={1})
128:                int number) {
129:                    assertThat(number, is(1));
130:                }
131:            }
132:
133:            @Test
134:            public void testedOnLimitsParameters() throws Exception {
135:                assertThat(testResult(ParameterAnnotations.class),
136:                        ResultMatchers.isSuccessful());
137:            }
138:
139:            @RunWith(Theories.class)
140:            public static class HonorExpectedException {
141:                @Test(expected=NullPointerException.class)
142:                public void shouldThrow() {
143:
144:                }
145:            }
146:
147:            @Test
148:            public void honorExpected() throws Exception {
149:                assertThat(testResult(HonorExpectedException.class)
150:                        .getFailures().size(), is(1));
151:            }
152:
153:            @RunWith(Theories.class)
154:            public static class HonorTimeout {
155:                @Test(timeout=5)
156:                public void shouldStop() {
157:                    while (true) {
158:                        try {
159:                            Thread.sleep(1000);
160:                        } catch (InterruptedException e) {
161:
162:                        }
163:                    }
164:                }
165:            }
166:
167:            @Test
168:            public void honorTimeout() throws Exception {
169:                assertThat(testResult(HonorTimeout.class), failureCountIs(1));
170:            }
171:
172:            @RunWith(Theories.class)
173:            public static class AssumptionsFail {
174:                public static int DATA = 0;
175:
176:                public static Matcher<Integer> MATCHER = null;
177:
178:                @Theory
179:                public void nonZeroIntsAreFun(int x) {
180:                    assumeThat(x, MATCHER);
181:                }
182:            }
183:
184:            @Theory
185:            public void showFailedAssumptionsWhenNoParametersFound(int data,
186:                    Matcher<Integer> matcher) throws Exception {
187:                assumeThat(data, not(matcher));
188:                AssumptionsFail.DATA = data;
189:                AssumptionsFail.MATCHER = matcher;
190:
191:                String result = testResult(AssumptionsFail.class).toString();
192:                assertThat(result, containsString(matcher.toString()));
193:                assertThat(result, containsString("" + data));
194:            }
195:
196:            @RunWith(Theories.class)
197:            public static class ShouldFilterNull {
198:                @DataPoint
199:                public static String NULL = null;
200:
201:                @DataPoint
202:                public static String A = "a";
203:
204:                @Theory(nullsAccepted=false)
205:                public void allStringsAreNonNull(String s) {
206:                    assertThat(s, notNullValue());
207:                }
208:            }
209:
210:            @Test
211:            public void shouldFilterNull() {
212:                assertThat(testResult(ShouldFilterNull.class), isSuccessful());
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.