Skip to content

Commit b9c4126

Browse files
varomorfpivovarit
authored andcommitted
Fix on the test and compression to match article (eugenp#520)
* Add new module for mocks comparison. * Add sources for testing. * Changes on testCase. * Enter some tests for mockito. * More tests for Mockito. * Even more tests. * Add the rest of the mocking libraries. * Javadoc on test. * Test bare bones for EasyMock. * Fist kind of test and setup. * Add tests using EasyMock with a change on LoginService. * Create LoginControllerTest.java * Test setup * [JMockit] No method called test. * [JMockit] Two methods called test. * [JMockit] One method called test. * [JMockit] Exception mock test * [JMockit] Mocked object to pass around test. * [JMockit] Custom matcher test. * [JMockit] Partial mocking test. * [JMockit] Fix with IDE. * Not stubs. Mocks. MOCKS!!! * Remove unnecesary import. * Use correct encoding. Was having problems with buildings. * Remove failing module. * Create new module mocks and move mock-comparisons there. * Add jmockit module. * Add model class. * Add collaborator class. * Add performer class. * Add performer test. * Fix * Add interface for tests. * Test for any. * Test for with. * Test for null. * Test for times. * Test for arg that. * Test for result and returns. * Test for delegate. * Add verifications to any tests. * Add verifications to with test. * Add verification examples to methods using null. * Add verifications to methods using times. * Formatting. * Compress tests and fix one test.
1 parent 11241ea commit b9c4126

1 file changed

Lines changed: 7 additions & 21 deletions

File tree

‎mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@ public void testWithNulls(@Mocked ExpectationsCollaborator mock) {
8282
public void testWithTimes(@Mocked ExpectationsCollaborator mock) {
8383
new Expectations() {
8484
{
85-
// exactly 2 invocations are expected
86-
mock.methodForTimes1();
87-
times = 2;
88-
mock.methodForTimes2(); // "minTimes = 1" is implied
85+
mock.methodForTimes1(); times = 2;
86+
mock.methodForTimes2();
8987
}
9088
};
9189

@@ -98,10 +96,7 @@ public void testWithTimes(@Mocked ExpectationsCollaborator mock) {
9896

9997
new Verifications() {
10098
{
101-
// we expect from 1 to 3 invocations
102-
mock.methodForTimes3();
103-
minTimes = 1;
104-
maxTimes = 3;
99+
mock.methodForTimes3(); minTimes = 1; maxTimes = 3;
105100
}
106101
};
107102
}
@@ -117,9 +112,7 @@ public boolean matches(Object item) {
117112
}
118113

119114
@Override
120-
public void describeTo(Description description) {
121-
// NOOP
122-
}
115+
public void describeTo(Description description) { }
123116
}));
124117
}
125118
};
@@ -130,18 +123,14 @@ public void describeTo(Description description) {
130123
public void testResultAndReturns(@Mocked ExpectationsCollaborator mock) {
131124
new StrictExpectations() {
132125
{
133-
// return "foo", an exception and lastly "bar"
134126
mock.methodReturnsString();
135127
result = "foo";
136128
result = new Exception();
137129
result = "bar";
138-
// return 1, 2, 3
139130
mock.methodReturnsInt();
140131
result = new int[] { 1, 2, 3 };
141-
// return "foo" and "bar"
142132
mock.methodReturnsString();
143133
returns("foo", "bar");
144-
// return only 1
145134
mock.methodReturnsInt();
146135
result = 1;
147136
}
@@ -164,11 +153,9 @@ public void testResultAndReturns(@Mocked ExpectationsCollaborator mock) {
164153

165154
@Test
166155
public void testDelegate(@Mocked ExpectationsCollaborator mock) {
167-
new StrictExpectations() {
156+
new Expectations() {
168157
{
169-
// return "foo", an exception and lastly "bar"
170158
mock.methodForDelegate(anyInt);
171-
times = 2;
172159
result = new Delegate() {
173160
public int delegate(int i) throws Exception {
174161
if (i < 3) {
@@ -180,11 +167,10 @@ public int delegate(int i) throws Exception {
180167
};
181168
}
182169
};
170+
183171
assertEquals("Should return 5", 5, mock.methodForDelegate(1));
184172
try {
185173
mock.methodForDelegate(3);
186-
} catch (Exception e) {
187-
// NOOP
188-
}
174+
} catch (Exception e) { }
189175
}
190176
}

0 commit comments

Comments
 (0)