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