1 package otherTests.testng;
2
3 import static org.testng.Assert.assertThrows;
4
5 import java.util.IllegalFormatCodePointException;
6
7 import mockit.Expectations;
8 import mockit.Mocked;
9 import mockit.integration.Collaborator;
10
11 import org.testng.annotations.Test;
12
13
14 @Test(enabled = false)
15 public final class TestNGViolatedExpectationsTest {
16 @Test
17 public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_1(@Mocked final Collaborator mock) {
18 new Expectations() {
19 {
20 mock.doSomething();
21 }
22 };
23 }
24
25 @Test
26 public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_2(@Mocked final Collaborator mock) {
27 new Expectations() {
28 {
29 mock.doSomething();
30 result = new IllegalFormatCodePointException('x');
31 }
32 };
33
34 mock.doSomething();
35 }
36
37 @Test
38 public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_3(@Mocked Collaborator mock) {
39 new Expectations() {
40 {
41 new Collaborator();
42 maxTimes = 1;
43 }
44 };
45
46 new Collaborator();
47 new Collaborator();
48 }
49
50 @Test
51 public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_4(@Mocked final Collaborator mock) {
52 new Expectations() {
53 {
54 mock.doSomething();
55 result = new IllegalFormatCodePointException('x');
56 minTimes = 2;
57 }
58 };
59
60
61 assertThrows(IllegalFormatCodePointException.class, () -> {
62 mock.doSomething();
63 });
64 }
65
66 @Test
67 public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_5(@Mocked final Collaborator mock) {
68 new Expectations() {
69 {
70 mock.doSomething();
71 result = new IllegalFormatCodePointException('x');
72 }
73 };
74
75
76 assertThrows(AssertionError.class, () -> {
77 mock.doSomething();
78 });
79 }
80
81 @Test
82 public void expectInvocationWhichDoesNotOccurInTestedCodeThatThrowsAnException_6(@Mocked final Collaborator mock) {
83 new Expectations() {
84 {
85
86 assertThrows(AssertionError.class, () -> {
87 mock.doSomething();
88 });
89 result = new IllegalFormatCodePointException('x');
90 }
91 };
92 }
93 }