Fix on the test and compression to match article (#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.
This commit is contained in:
parent
11241eabc0
commit
b9c412689d
@ -82,10 +82,8 @@ public class ExpectationsTest {
|
||||
public void testWithTimes(@Mocked ExpectationsCollaborator mock) {
|
||||
new Expectations() {
|
||||
{
|
||||
// exactly 2 invocations are expected
|
||||
mock.methodForTimes1();
|
||||
times = 2;
|
||||
mock.methodForTimes2(); // "minTimes = 1" is implied
|
||||
mock.methodForTimes1(); times = 2;
|
||||
mock.methodForTimes2();
|
||||
}
|
||||
};
|
||||
|
||||
@ -98,10 +96,7 @@ public class ExpectationsTest {
|
||||
|
||||
new Verifications() {
|
||||
{
|
||||
// we expect from 1 to 3 invocations
|
||||
mock.methodForTimes3();
|
||||
minTimes = 1;
|
||||
maxTimes = 3;
|
||||
mock.methodForTimes3(); minTimes = 1; maxTimes = 3;
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -117,9 +112,7 @@ public class ExpectationsTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
// NOOP
|
||||
}
|
||||
public void describeTo(Description description) { }
|
||||
}));
|
||||
}
|
||||
};
|
||||
@ -130,18 +123,14 @@ public class ExpectationsTest {
|
||||
public void testResultAndReturns(@Mocked ExpectationsCollaborator mock) {
|
||||
new StrictExpectations() {
|
||||
{
|
||||
// return "foo", an exception and lastly "bar"
|
||||
mock.methodReturnsString();
|
||||
result = "foo";
|
||||
result = new Exception();
|
||||
result = "bar";
|
||||
// return 1, 2, 3
|
||||
mock.methodReturnsInt();
|
||||
result = new int[] { 1, 2, 3 };
|
||||
// return "foo" and "bar"
|
||||
mock.methodReturnsString();
|
||||
returns("foo", "bar");
|
||||
// return only 1
|
||||
mock.methodReturnsInt();
|
||||
result = 1;
|
||||
}
|
||||
@ -164,11 +153,9 @@ public class ExpectationsTest {
|
||||
|
||||
@Test
|
||||
public void testDelegate(@Mocked ExpectationsCollaborator mock) {
|
||||
new StrictExpectations() {
|
||||
new Expectations() {
|
||||
{
|
||||
// return "foo", an exception and lastly "bar"
|
||||
mock.methodForDelegate(anyInt);
|
||||
times = 2;
|
||||
result = new Delegate() {
|
||||
public int delegate(int i) throws Exception {
|
||||
if (i < 3) {
|
||||
@ -180,11 +167,10 @@ public class ExpectationsTest {
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
assertEquals("Should return 5", 5, mock.methodForDelegate(1));
|
||||
try {
|
||||
mock.methodForDelegate(3);
|
||||
} catch (Exception e) {
|
||||
// NOOP
|
||||
}
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user