1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package ch.powerunit.test.core;
21
22 import ch.powerunit.Ignore;
23 import ch.powerunit.Test;
24 import ch.powerunit.TestContext;
25 import ch.powerunit.TestResultListener;
26 import ch.powerunit.TestSuite;
27 import ch.powerunit.impl.DefaultPowerUnitRunnerImpl;
28
29 public class TestResultListenerTests {
30 public static void main(String[] args) {
31 AllTests.testNoException(
32 "testResultListenerOK",
33 () -> {
34 DefaultPowerUnitRunnerImpl<TestClass> runner = new DefaultPowerUnitRunnerImpl<>(
35 TestClass.class);
36 runner.addListener(new Listener());
37 runner.run();
38 TestSuite.DSL.assertThat(counter).is(
39 1000l + 10000 + 100000 + 100000 + 1000000
40 + 10000000 + 100000 + 100000000
41 + 1000000000 + 100000 + 100000 + 100000000);
42 });
43 }
44
45 private static class Listener implements TestResultListener<TestClass> {
46
47 @Override
48 public void notifySetStart(String setName, String parameters) {
49 counter += 1000;
50 }
51
52 @Override
53 public void notifySetEnd(String setName, String parameters) {
54 counter += 10000;
55 }
56
57 @Override
58 public void notifyStart(TestContext<TestClass> context) {
59 counter += 100000;
60 }
61
62 @Override
63 public void notifySuccess(TestContext<TestClass> context) {
64 counter += 1000000;
65 TestSuite.DSL.assertThat(context.getLocalTestName()).is("success");
66 }
67
68 @Override
69 public void notifyFailure(TestContext<TestClass> context,
70 Throwable cause) {
71 counter += 10000000;
72 TestSuite.DSL.assertThat(context.getLocalTestName()).is("failure");
73 }
74
75 @Override
76 public void notifySkipped(TestContext<TestClass> context) {
77 counter += 100000000;
78 TestSuite.DSL.assertThat(context.getLocalTestName()).is(
79 TestSuite.DSL.either(TestSuite.DSL.is("skip")).or(
80 TestSuite.DSL.is("skipOnAssume")));
81 }
82
83 @Override
84 public void notifyError(TestContext<TestClass> context, Throwable cause) {
85 counter += 1000000000;
86 TestSuite.DSL.assertThat(context.getLocalTestName()).is("error");
87 }
88
89 @Override
90 public void notifyParameterStart(String setName, String parameterName) {
91 counter += 10000000000l;
92 }
93
94 @Override
95 public void notifyParameterEnd(String setName, String parameterName) {
96 counter += 100000000000l;
97 }
98
99 }
100
101 private static long counter = 0;
102
103 public static class TestClass implements TestSuite {
104 @Test
105 public void success() {
106 }
107
108 @Test
109 public void failure() {
110 fail();
111 }
112
113 @Test
114 public void error() {
115 throw new IllegalArgumentException("xxx");
116 }
117
118 @Override
119 @Test
120 @Ignore
121 public void skip() {
122
123 }
124
125 @Test
126 public void skipOnAssume() {
127 assumeThat(true).is(false);
128 }
129 }
130 }