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