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