Skip to content

Commit 463f525

Browse files
varomorfpivovarit
authored andcommitted
Move test class to tests folder (eugenp#558)
* 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. * Adding new article to readme. * [BAEL-178] Add collaborator for advanced article. * [BAEL-178] Add link to readme. * [BAEL-178] Add test for mockUp. * [BAEL-178] Add test for invoke method. * [BAEL-178] Add constructors and tests for mockup for constructors. * [BAEL-178] Add private fields and more test for deencapsulation. * [BAEL-178] Add inner class and test for instantiating inner classes. * [BAEL-178] Multimocks. * [BAEL-178] Add test for expectation reusing. * [BAEL-178] Move test class to tests folders.
1 parent 944525a commit 463f525

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.baeldung.mocks.jmockit;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
7+
import mockit.Expectations;
8+
import mockit.Injectable;
9+
import mockit.Mocked;
10+
import mockit.Tested;
11+
import mockit.Verifications;
12+
import mockit.integration.junit4.JMockit;
13+
14+
@RunWith(JMockit.class)
15+
public class ReusingTest {
16+
17+
@Injectable
18+
private Collaborator collaborator;
19+
20+
@Mocked
21+
private Model model;
22+
23+
@Tested
24+
private Performer performer;
25+
26+
@Before
27+
public void setup(){
28+
new Expectations(){{
29+
model.getInfo(); result = "foo"; minTimes = 0;
30+
collaborator.collaborate("foo"); result = true; minTimes = 0;
31+
}};
32+
}
33+
34+
@Test
35+
public void testWithSetup() {
36+
performer.perform(model);
37+
verifyTrueCalls(1);
38+
}
39+
40+
protected void verifyTrueCalls(int calls){
41+
new Verifications(){{
42+
collaborator.receive(true); times = calls;
43+
}};
44+
}
45+
46+
final class TrueCallsVerification extends Verifications{
47+
public TrueCallsVerification(int calls){
48+
collaborator.receive(true); times = calls;
49+
}
50+
}
51+
52+
@Test
53+
public void testWithFinalClass() {
54+
performer.perform(model);
55+
new TrueCallsVerification(1);
56+
}
57+
}

0 commit comments

Comments
 (0)