View Javadoc
1   package mockit.integration.junit4;
2   
3   import java.util.IllegalFormatCodePointException;
4   
5   import mockit.Expectations;
6   import mockit.Mocked;
7   import mockit.integration.Collaborator;
8   
9   import org.junit.Ignore;
10  import org.junit.Test;
11  
12  // These tests are expected to fail, so they are kept inactive.
13  @Ignore
14  public final class JUnit4ViolatedExpectationsTest {
15      @Test // fails with a "missing invocation" error
16      public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_1(@Mocked final Collaborator mock) {
17          new Expectations() {
18              {
19                  mock.doSomething();
20              }
21          };
22      }
23  
24      @Test // fails with a "missing invocation" error
25      public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_2(@Mocked final Collaborator mock) {
26          new Expectations() {
27              {
28                  mock.doSomething();
29                  result = new IllegalFormatCodePointException('x');
30              }
31          };
32  
33          mock.doSomething();
34      }
35  
36      // fails with a "missing invocation" error after the exception thrown by tested code
37      @Test(expected = IllegalFormatCodePointException.class)
38      public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_4(@Mocked final Collaborator mock) {
39          new Expectations() {
40              {
41                  mock.doSomething();
42                  result = new IllegalFormatCodePointException('x');
43                  minTimes = 2;
44              }
45          };
46  
47          mock.doSomething();
48      }
49  
50      @Test(expected = AssertionError.class) // fails with a different exception than expected
51      public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_5(@Mocked final Collaborator mock) {
52          new Expectations() {
53              {
54                  mock.doSomething();
55                  result = new IllegalFormatCodePointException('x');
56              }
57          };
58  
59          mock.doSomething();
60      }
61  
62      @Test(expected = AssertionError.class) // fails without the expected exception being thrown
63      public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_6(@Mocked final Collaborator mock) {
64          new Expectations() {
65              {
66                  mock.doSomething();
67                  result = new IllegalFormatCodePointException('x');
68              }
69          };
70      }
71  }