Move test class to tests folder (#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.
This commit is contained in:
parent
944525a524
commit
463f5256c0
|
@ -0,0 +1,57 @@
|
|||
package org.baeldung.mocks.jmockit;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import mockit.Expectations;
|
||||
import mockit.Injectable;
|
||||
import mockit.Mocked;
|
||||
import mockit.Tested;
|
||||
import mockit.Verifications;
|
||||
import mockit.integration.junit4.JMockit;
|
||||
|
||||
@RunWith(JMockit.class)
|
||||
public class ReusingTest {
|
||||
|
||||
@Injectable
|
||||
private Collaborator collaborator;
|
||||
|
||||
@Mocked
|
||||
private Model model;
|
||||
|
||||
@Tested
|
||||
private Performer performer;
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
new Expectations(){{
|
||||
model.getInfo(); result = "foo"; minTimes = 0;
|
||||
collaborator.collaborate("foo"); result = true; minTimes = 0;
|
||||
}};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSetup() {
|
||||
performer.perform(model);
|
||||
verifyTrueCalls(1);
|
||||
}
|
||||
|
||||
protected void verifyTrueCalls(int calls){
|
||||
new Verifications(){{
|
||||
collaborator.receive(true); times = calls;
|
||||
}};
|
||||
}
|
||||
|
||||
final class TrueCallsVerification extends Verifications{
|
||||
public TrueCallsVerification(int calls){
|
||||
collaborator.receive(true); times = calls;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithFinalClass() {
|
||||
performer.perform(model);
|
||||
new TrueCallsVerification(1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue