-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.html
139 lines (122 loc) · 4.91 KB
/
examples.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<meta name="Description" content="Behavior driven development (BDD) framework for Java" />
<meta name="Keywords" content="bdd, behaviour driven development, behavior driven development, tdd, test driven design" />
<meta name="Copyright" content="Christina Chun" />
<meta name="Designed By" content="ChristinaChun.com" />
<meta name="Language" content="English" />
<title>JDave</title>
<style type="text/css" title="layout" media="screen"> @import url("gg.css"); </style>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">
_uacct = "UA-832056-1";
_udn="none";
_ulink=1;
urchinTracker();
</script>
</head>
<body>
<div id="container">
<div id="header"><div class="headerText">JDave</div>
<div class="center"><b class="menu"><a href="index.html">About</a> |
<a href="examples.html">Examples</a> | <a href="usage.html">Usage</a> |
<a href="documentation.html">Documentation</a> |
<a href="modules.html">Modules</a> |
<a href="screenshots.html">Screenshots</a> |
<a href="resources.html">Resources</a></b></div>
</div>
<div id="content">
<div id="bodytext">
<h1 class="title">Examples</h1>
<div></div>
<pre>
import jdave.Block;
import jdave.Specification;
import jdave.junit4.JDaveRunner;
@RunWith(JDaveRunner.class)
public class StackSpec extends Specification<Stack<?>> {
public class EmptyStack {
private Stack<String> stack;
public Stack<String> create() {
stack = new Stack<String>();
return stack;
}
public void isEmpty() {
specify(stack, must.be.empty());
}
public void isNoLongerEmptyAfterPush() {
stack.push("anything");
specify(stack, must.not().be.empty());
}
}
public class FullStack {
private Stack<Integer> stack;
public Stack<Integer> create() {
stack = new Stack<Integer>(10);
for (int i = 0; i < 10; i++) {
stack.push(i);
}
return stack;
}
public void isFull() {
specify(stack, must.be.full());
}
public void complainsOnPush() {
specify(new Block() {
public void run() throws Throwable {
stack.push(100);
}
}, should.raise(StackOverflowException.class));
}
public void containsAllItems() {
for (int i = 0; i < 10; i++) {
specify(stack, contains(i));
}
}
public void doesNotContainRemovedItem() {
stack.remove(3);
specify(stack, does.not().contain(3));
}
public void containsAllButRemovedItem() {
stack.remove(3);
specify(stack, containsExactly(0, 1, 2, 4, 5, 6, 7, 8, 9));
}
}
public class StackWhichIsNeitherEmptyNorFull {
private Stack<Integer> stack;
public Stack<Integer> create() {
stack = new Stack<Integer>();
for (int i = 0; i < 10; i++) {
stack.push(i);
}
return stack;
}
public void addsToTheTopWhenSentPush() {
stack.push(100);
specify(stack.peek(), must.equal(100));
}
}
}
</pre>
<p/>
More examples:
<ul>
<li><a href="https://github.com/jdave/JDave/blob/master/jdave-examples/src/test/jdave/examples/ObservableSpec.java">Using mocks</a></li>
<li><a href="https://github.com/jdave/JDave/blob/master/jdave-examples/src/test/jdave/examples/ContainmentSampleSpec.java">Using collection containment expectations</a></li>
<li><a href="https://github.com/jdave/JDave/blob/master/jdave-examples/src/test/jdave/examples/ContractEnforcementSampleSpec.java">Using contract enforcements</a></li>
<li><a href="https://github.com/jdave/JDave/blob/master/jdave-examples/src/test/jdave/examples/HamcrestSampleSpec.java">Using Hamcrest matchers</a></li>
<li><a href="https://github.com/jdave/JDave/blob/master/jdave-core/src/java/jdave/injection/InjectionSupport.java">Injection example (see javadoc)</a></li>
<li><a href="https://github.com/jdave/JDave/blob/master/jdave-examples/src/test/jdave/examples/swing/AlbumPanelSpec.java">Jemmy example</a></li>
<li><a href="https://github.com/jdave/JDave/blob/master/jdave-examples/src/test/jdave/examples/wicket/DictionarySpec.java">Wicket example</a></li>
</ul>
</div>
</div>
</div>
<div class="footer">
<div>Copyright © 2007 JDave developers</div>
<div>Designed By <a href="http://www.christinachun.com" title="Christina Chun - Digital Artist & Web Developer">Christina Chun</a> © 2006 </div>
</div>
</body>
</html>